Skip to content

Commit

Permalink
Merge pull request #1099 from Hoolean/include-empties-for-max
Browse files Browse the repository at this point in the history
Include empty glyphs when calculating max width, to match fonttools
  • Loading branch information
cmyr authored Nov 6, 2024
2 parents b55d418 + 8395d61 commit 39b7a88
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion fontbe/src/metrics_and_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ impl GlyphLimits {

impl FontLimits {
fn update(&mut self, id: GlyphId16, advance: u16, glyph: &Glyph) {
// max advance width should consider every glyph that has an hmtx entry
self.advance_width_max = max(self.advance_width_max, advance);

// min side bearings are only for non-empty glyphs
// we will presume only simple glyphs with no contours are empty
if let Some(bbox) = glyph.data.bbox() {
Expand All @@ -103,7 +106,6 @@ impl FontLimits {
.x_max_extent
.map(|v| max(v, bbox.x_max))
.or(Some(bbox.x_max));
self.advance_width_max = max(self.advance_width_max, advance);
self.bbox = self.bbox.map(|b| b.union(bbox)).or(Some(bbox));
}

Expand Down Expand Up @@ -385,4 +387,19 @@ mod tests {
)
);
}

#[test]
fn empty_glyph_contributes_to_max() {
let width = 123u16;

// confirm that empty glyphs still contribute to the advance_width_max
// field, as they will still originate an hmtx entry
let mut glyph_limits = FontLimits::default();
glyph_limits.update(
GlyphId16::NOTDEF,
width,
&crate::orchestration::Glyph::new("empty".into(), RawGlyph::Empty),
);
assert_eq!(width, glyph_limits.advance_width_max);
}
}

0 comments on commit 39b7a88

Please sign in to comment.