Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include empty glyphs when calculating max width, to match fonttools #1099

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading