mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Add average advance width to the font metrics structure, using the X glyph as a best guess.
This commit is contained in:
parent
08cac68d5a
commit
9b20d6e7d2
3 changed files with 15 additions and 1 deletions
|
@ -78,6 +78,7 @@ pub struct FontMetrics {
|
||||||
pub ascent: Au,
|
pub ascent: Au,
|
||||||
pub descent: Au,
|
pub descent: Au,
|
||||||
pub max_advance: Au,
|
pub max_advance: Au,
|
||||||
|
pub average_advance: Au,
|
||||||
pub line_gap: Au,
|
pub line_gap: Au,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
let metrics = FontMetrics {
|
||||||
underline_size: underline_size,
|
underline_size: underline_size,
|
||||||
underline_offset: underline_offset,
|
underline_offset: underline_offset,
|
||||||
|
@ -246,6 +251,7 @@ impl FontHandleMethods for FontHandle {
|
||||||
ascent: ascent,
|
ascent: ascent,
|
||||||
descent: -descent, // linux font's seem to use the opposite sign from mac
|
descent: -descent, // linux font's seem to use the opposite sign from mac
|
||||||
max_advance: max_advance,
|
max_advance: max_advance,
|
||||||
|
average_advance: average_advance,
|
||||||
line_gap: height,
|
line_gap: height,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,12 @@ impl FontHandleMethods for FontHandle {
|
||||||
let scale = px_to_pt(self.ctfont.pt_size() as f64) / (ascent + descent);
|
let scale = px_to_pt(self.ctfont.pt_size() as f64) / (ascent + descent);
|
||||||
let line_gap = (ascent + descent + leading + 0.5).floor();
|
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 {
|
let metrics = FontMetrics {
|
||||||
underline_size: Au::from_pt(self.ctfont.underline_thickness() as f64),
|
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
|
// 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,
|
em_size: em_size,
|
||||||
ascent: Au::from_pt(ascent * scale),
|
ascent: Au::from_pt(ascent * scale),
|
||||||
descent: Au::from_pt(descent * 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),
|
line_gap: Au::from_frac_px(line_gap),
|
||||||
};
|
};
|
||||||
debug!("Font metrics (@{:f} pt): {:?}", self.ctfont.pt_size() as f64, metrics);
|
debug!("Font metrics (@{:f} pt): {:?}", self.ctfont.pt_size() as f64, metrics);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue