Skip to content

Commit

Permalink
[skrifa] empty glyphs have phantom points too (#1283)
Browse files Browse the repository at this point in the history
Fixes a small oversight: we explicitly didn't account for phantom point memory for empty glyphs. Just removes the explicit check and adds a test to ensure it works.
  • Loading branch information
dfrg authored Dec 10, 2024
1 parent f82e95f commit 67ef9ea
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions skrifa/src/outline/glyf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,10 @@ impl<'a> Outlines<'a> {
..Default::default()
};
let glyph = self.loca.get_glyf(glyph_id, &self.glyf)?;
if glyph.is_none() {
return Ok(outline);
}
self.outline_rec(glyph.as_ref().unwrap(), &mut outline, 0, 0)?;
if outline.points != 0 {
outline.points += PHANTOM_POINT_COUNT;
if let Some(glyph) = glyph.as_ref() {
self.outline_rec(glyph, &mut outline, 0, 0)?;
}
outline.points += PHANTOM_POINT_COUNT;
outline.max_stack = self.max_stack_elements as usize;
outline.cvt_count = self.cvt_len as usize;
outline.storage_count = self.max_storage as usize;
Expand Down Expand Up @@ -1320,17 +1317,30 @@ mod tests {
let gid = font.charmap().map(' ').unwrap();
let outline = outlines.outline(gid).unwrap();
// Make sure this is an empty outline since that's what we're testing
assert_eq!(outline.points, 0);
let scaler = FreeTypeScaler::unhinted(&outlines, &outline, &mut [], ppem, &coords).unwrap();
assert!(outline.glyph.is_none());
let mut buf = [0u8; 128];
let scaler =
FreeTypeScaler::unhinted(&outlines, &outline, &mut buf, ppem, &coords).unwrap();
let scaled = scaler.scale(&outline.glyph, gid).unwrap();
let advance_hvar = scaled.adjusted_advance_width();
// Set HVAR table to None to force loading metrics from gvar
outlines.common.hvar = None;
let scaler = FreeTypeScaler::unhinted(&outlines, &outline, &mut [], ppem, &coords).unwrap();
let scaler =
FreeTypeScaler::unhinted(&outlines, &outline, &mut buf, ppem, &coords).unwrap();
let scaled = scaler.scale(&outline.glyph, gid).unwrap();
let advance_gvar = scaled.adjusted_advance_width();
// Make sure we have an advance and that the two are the same
assert!(advance_hvar != F26Dot6::ZERO);
assert_eq!(advance_hvar, advance_gvar);
}

#[test]
fn empty_glyphs_have_phantom_points_too() {
let font = FontRef::new(font_test_data::HVAR_WITH_TRUNCATED_ADVANCE_INDEX_MAP).unwrap();
let outlines = Outlines::new(&OutlinesCommon::new(&font).unwrap()).unwrap();
let gid = font.charmap().map(' ').unwrap();
let outline = outlines.outline(gid).unwrap();
assert!(outline.glyph.is_none());
assert_eq!(outline.points, PHANTOM_POINT_COUNT);
}
}

0 comments on commit 67ef9ea

Please sign in to comment.