From 79789a18de4afefcf7407cc24081f1cf4b27466b Mon Sep 17 00:00:00 2001 From: Daniel Hedlund Date: Sun, 8 Dec 2013 11:25:20 -0800 Subject: [PATCH] Implement font leading metric for linux platform Fixes #76. --- src/components/gfx/platform/android/font.rs | 11 ++++++++++- src/components/gfx/platform/linux/font.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/gfx/platform/android/font.rs b/src/components/gfx/platform/android/font.rs index c350f8b820c..745157f5354 100644 --- a/src/components/gfx/platform/android/font.rs +++ b/src/components/gfx/platform/android/font.rs @@ -231,6 +231,15 @@ impl FontHandleMethods for FontHandle { let descent = self.font_units_to_au(face.descender as float); let max_advance = self.font_units_to_au(face.max_advance_width as float); + // 'leading' is supposed to be the vertical distance between two baselines, + // reflected by the height attibute in freetype. On OS X (w/ CTFont), + // leading represents the distance between the bottom of a line descent to + // the top of the next line's ascent or: (line_height - ascent - descent), + // see http://stackoverflow.com/a/5635981 for CTFont implementation. + // Convert using a formular similar to what CTFont returns for consistency. + let height = self.font_units_to_au(face.height as float); + let leading = height - (ascent + descent); + let mut strikeout_size = geometry::from_pt(0.0); let mut strikeout_offset = geometry::from_pt(0.0); let mut x_height = geometry::from_pt(0.0); @@ -249,7 +258,7 @@ impl FontHandleMethods for FontHandle { underline_offset: underline_offset, strikeout_size: strikeout_size, strikeout_offset: strikeout_offset, - leading: geometry::from_pt(0.0), //FIXME + leading: leading, x_height: x_height, em_size: em_size, ascent: ascent, diff --git a/src/components/gfx/platform/linux/font.rs b/src/components/gfx/platform/linux/font.rs index ca01f2ee949..cb2573a9a13 100644 --- a/src/components/gfx/platform/linux/font.rs +++ b/src/components/gfx/platform/linux/font.rs @@ -230,6 +230,15 @@ impl FontHandleMethods for FontHandle { let descent = self.font_units_to_au(face.descender as f64); let max_advance = self.font_units_to_au(face.max_advance_width as f64); + // 'leading' is supposed to be the vertical distance between two baselines, + // reflected by the height attibute in freetype. On OS X (w/ CTFont), + // leading represents the distance between the bottom of a line descent to + // the top of the next line's ascent or: (line_height - ascent - descent), + // see http://stackoverflow.com/a/5635981 for CTFont implementation. + // Convert using a formular similar to what CTFont returns for consistency. + let height = self.font_units_to_au(face.height as f64); + let leading = height - (ascent + descent); + let mut strikeout_size = geometry::from_pt(0.0); let mut strikeout_offset = geometry::from_pt(0.0); let mut x_height = geometry::from_pt(0.0); @@ -248,7 +257,7 @@ impl FontHandleMethods for FontHandle { underline_offset: underline_offset, strikeout_size: strikeout_size, strikeout_offset: strikeout_offset, - leading: geometry::from_pt(0.0), //FIXME + leading: leading, x_height: x_height, em_size: em_size, ascent: ascent,