diff options
author | Josh Matthews <josh@joshmatthews.net> | 2014-09-29 02:15:43 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2014-10-01 15:03:15 -0400 |
commit | 9b20d6e7d296a0eec6ba925fee740fa8a09018f3 (patch) | |
tree | b5ef6b3a5afd3e4a723e4ede1281f59608b5a149 /components/gfx/platform/macos | |
parent | 08cac68d5a481c3c612fff1e9a87612871f95f5f (diff) | |
download | servo-9b20d6e7d296a0eec6ba925fee740fa8a09018f3.tar.gz servo-9b20d6e7d296a0eec6ba925fee740fa8a09018f3.zip |
Add average advance width to the font metrics structure, using the X glyph as a best guess.
Diffstat (limited to 'components/gfx/platform/macos')
-rw-r--r-- | components/gfx/platform/macos/font.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index b025b70566c..ad3d5bd1b29 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -153,6 +153,12 @@ impl FontHandleMethods for FontHandle { let scale = px_to_pt(self.ctfont.pt_size() as f64) / (ascent + descent); let line_gap = (ascent + descent + leading + 0.5).floor(); + let max_advance_width = Au::from_pt(bounding_rect.size.width as f64); + let average_advance = self.glyph_index('x') + .and_then(|idx| self.glyph_h_advance(idx)) + .map(|advance| Au::from_frac_px(advance)) + .unwrap_or(max_advance_width); + let metrics = FontMetrics { underline_size: Au::from_pt(self.ctfont.underline_thickness() as f64), // TODO(Issue #201): underline metrics are not reliable. Have to pull out of font table @@ -168,7 +174,8 @@ impl FontHandleMethods for FontHandle { em_size: em_size, ascent: Au::from_pt(ascent * scale), descent: Au::from_pt(descent * scale), - max_advance: Au::from_pt(bounding_rect.size.width as f64), + max_advance: max_advance_width, + average_advance: average_advance, line_gap: Au::from_frac_px(line_gap), }; debug!("Font metrics (@{:f} pt): {:?}", self.ctfont.pt_size() as f64, metrics); |