diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/gfx/font.rs | 4 | ||||
-rw-r--r-- | components/gfx/platform/freetype/font.rs | 12 | ||||
-rw-r--r-- | components/gfx/platform/macos/font.rs | 12 | ||||
-rw-r--r-- | components/gfx/platform/windows/font.rs | 11 | ||||
-rw-r--r-- | components/layout_thread_2020/lib.rs | 36 |
5 files changed, 64 insertions, 11 deletions
diff --git a/components/gfx/font.rs b/components/gfx/font.rs index 65c984ed3cb..1921edc1d12 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -131,6 +131,8 @@ pub struct FontMetrics { pub max_advance: Au, pub average_advance: Au, pub line_gap: Au, + pub zero_horizontal_advance: Option<Au>, + pub ic_horizontal_advance: Option<Au>, } impl FontMetrics { @@ -150,6 +152,8 @@ impl FontMetrics { max_advance: Au(0), average_advance: Au(0), line_gap: Au(0), + zero_horizontal_advance: None, + ic_horizontal_advance: None, } } } diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index 33bd7be0aa0..f437dbed8c0 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -261,10 +261,16 @@ impl PlatformFontMethods for PlatformFont { x_height = self.font_units_to_au(os2.sx_height as f64); } - let average_advance = self + let zero_horizontal_advance = self .glyph_index('0') .and_then(|idx| self.glyph_h_advance(idx)) - .map_or(max_advance, |advance| self.font_units_to_au(advance)); + .map(Au::from_f64_px); + let ic_horizontal_advance = self + .glyph_index('\u{6C34}') + .and_then(|idx| self.glyph_h_advance(idx)) + .map(Au::from_f64_px); + + let average_advance = zero_horizontal_advance.unwrap_or(max_advance); let metrics = FontMetrics { underline_size, @@ -279,6 +285,8 @@ impl PlatformFontMethods for PlatformFont { max_advance, average_advance, line_gap: height, + zero_horizontal_advance, + ic_horizontal_advance, }; debug!("Font metrics (@{}px): {:?}", em_size.to_f32_px(), metrics); diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index 7844ecb9089..c6e009ffae8 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -259,11 +259,15 @@ impl PlatformFontMethods for PlatformFont { let line_gap = (ascent + descent + leading + 0.5).floor(); let max_advance = Au::from_f64_px(self.ctfont.bounding_box().size.width); - let average_advance = self + let zero_horizontal_advance = self .glyph_index('0') .and_then(|idx| self.glyph_h_advance(idx)) - .map(Au::from_f64_px) - .unwrap_or(max_advance); + .map(Au::from_f64_px); + let ic_horizontal_advance = self + .glyph_index('\u{6C34}') + .and_then(|idx| self.glyph_h_advance(idx)) + .map(Au::from_f64_px); + let average_advance = zero_horizontal_advance.unwrap_or(max_advance); let metrics = FontMetrics { underline_size: Au::from_f64_au(underline_thickness), @@ -286,6 +290,8 @@ impl PlatformFontMethods for PlatformFont { max_advance, average_advance, line_gap: Au::from_f64_px(line_gap), + zero_horizontal_advance, + ic_horizontal_advance, }; debug!( "Font metrics (@{} pt): {:?}", diff --git a/components/gfx/platform/windows/font.rs b/components/gfx/platform/windows/font.rs index ce28d0f378b..5debd0c64fa 100644 --- a/components/gfx/platform/windows/font.rs +++ b/components/gfx/platform/windows/font.rs @@ -232,6 +232,15 @@ impl PlatformFontMethods for PlatformFont { // is pulled out here for clarity let leading = dm.ascent - dm.capHeight; + let zero_horizontal_advance = self + .glyph_index('0') + .and_then(|idx| self.glyph_h_advance(idx)) + .map(Au::from_f64_px); + let ic_horizontal_advance = self + .glyph_index('\u{6C34}') + .and_then(|idx| self.glyph_h_advance(idx)) + .map(Au::from_f64_px); + let metrics = FontMetrics { underline_size: au_from_du(dm.underlineThickness as i32), underline_offset: au_from_du_s(dm.underlinePosition as i32), @@ -245,6 +254,8 @@ impl PlatformFontMethods for PlatformFont { max_advance: au_from_pt(0.0), // FIXME average_advance: au_from_pt(0.0), // FIXME line_gap: au_from_du_s((dm.ascent + dm.descent + dm.lineGap as u16) as i32), + zero_horizontal_advance, + ic_horizontal_advance, }; debug!("Font metrics (@{} pt): {:?}", self.em_size * 12., metrics); metrics diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs index e9bf481f8c6..d0a9eccfef9 100644 --- a/components/layout_thread_2020/lib.rs +++ b/components/layout_thread_2020/lib.rs @@ -1247,8 +1247,9 @@ impl FontMetricsProvider for LayoutFontMetricsProvider { _retrieve_math_scales: bool, ) -> FontMetrics { layout::context::with_thread_local_font_context(&self.0, move |font_context| { - let Some(servo_metrics) = font_context - .font_group_with_size(ServoArc::new(font.clone()), base_size.into()) + let font_group = + font_context.font_group_with_size(ServoArc::new(font.clone()), base_size.into()); + let Some(first_font_metrics) = font_group .borrow_mut() .first(font_context) .map(|font| font.borrow().metrics.clone()) @@ -1258,16 +1259,39 @@ impl FontMetricsProvider for LayoutFontMetricsProvider { // Only use the x-height of this font if it is non-zero. Some fonts return // inaccurate metrics, which shouldn't be used. - let x_height = Some(servo_metrics.x_height) + let x_height = Some(first_font_metrics.x_height) .filter(|x_height| !x_height.is_zero()) .map(CSSPixelLength::from); + let zero_advance_measure = first_font_metrics + .zero_horizontal_advance + .or_else(|| { + font_group + .borrow_mut() + .find_by_codepoint(font_context, '0')? + .borrow() + .metrics + .zero_horizontal_advance + }) + .map(CSSPixelLength::from); + let ic_width = first_font_metrics + .ic_horizontal_advance + .or_else(|| { + font_group + .borrow_mut() + .find_by_codepoint(font_context, '\u{6C34}')? + .borrow() + .metrics + .ic_horizontal_advance + }) + .map(CSSPixelLength::from); + FontMetrics { x_height, - zero_advance_measure: None, + zero_advance_measure, cap_height: None, - ic_width: None, - ascent: servo_metrics.ascent.into(), + ic_width, + ascent: first_font_metrics.ascent.into(), script_percent_scale_down: None, script_script_percent_scale_down: None, } |