aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'components/gfx')
-rw-r--r--components/gfx/font.rs1
-rw-r--r--components/gfx/platform/freetype/font.rs6
-rw-r--r--components/gfx/platform/macos/font.rs9
3 files changed, 15 insertions, 1 deletions
diff --git a/components/gfx/font.rs b/components/gfx/font.rs
index b3f85edf823..b3e30b100fd 100644
--- a/components/gfx/font.rs
+++ b/components/gfx/font.rs
@@ -78,6 +78,7 @@ pub struct FontMetrics {
pub ascent: Au,
pub descent: Au,
pub max_advance: Au,
+ pub average_advance: Au,
pub line_gap: Au,
}
diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs
index 5bc2ce0abe4..4d78afd8c46 100644
--- a/components/gfx/platform/freetype/font.rs
+++ b/components/gfx/platform/freetype/font.rs
@@ -235,6 +235,11 @@ impl FontHandleMethods for FontHandle {
}
}
+ let average_advance = self.glyph_index('x')
+ .and_then(|idx| self.glyph_h_advance(idx))
+ .map(|advance| self.font_units_to_au(advance))
+ .unwrap_or(max_advance_width);
+
let metrics = FontMetrics {
underline_size: underline_size,
underline_offset: underline_offset,
@@ -246,6 +251,7 @@ impl FontHandleMethods for FontHandle {
ascent: ascent,
descent: -descent, // linux font's seem to use the opposite sign from mac
max_advance: max_advance,
+ average_advance: average_advance,
line_gap: height,
};
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);