From 7275ecc282d29d1c67f700c01a399582ba052853 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Mon, 31 Dec 2018 17:01:06 +0000 Subject: Fix line metrics Since bitmap fonts do not provide their own underline metrics, the self-calculated metrics which have been used for rusttype are now also used for bitmap fonts with freetype. The rusttype and bitmap fallback metrics have incorrectly offset the underline by the underline height. Since the position is already defined as the center point, that is not necessary. All rounding and clamping has also been removed from the font library, so that the raw values are reported now. The clamping and rounding is now done in the line renderer. --- font/src/darwin/mod.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'font/src/darwin/mod.rs') diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index ca784ae6..0e694f16 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -430,21 +430,17 @@ impl Font { let leading = self.ct_font.leading() as f64; let line_height = (ascent + descent + leading + 0.5).floor(); - // Strikeout and underline metrics - // CoreText doesn't provide strikeout so we provide our own - let underline_position = - (self.ct_font.underline_position() - descent) - .round() as f32; - let underline_thickness = self.ct_font.underline_thickness() - .round() - .max(1.) as f32; - let strikeout_position = (line_height as f32 / 2. - descent as f32).round(); + // Strikeout and underline metrics. + // CoreText doesn't provide strikeout so we provide our own. + let underline_position = (self.ct_font.underline_position() - descent) as f32; + let underline_thickness = self.ct_font.underline_thickness() as f32; + let strikeout_position = (line_height / 2. - descent) as f32; let strikeout_thickness = underline_thickness; Metrics { average_advance, line_height, - descent: -(self.ct_font.descent() as f32), + descent: -(descent as f32), underline_position, underline_thickness, strikeout_position, -- cgit