Compare malformed glyph recovery against original pen

This commit is contained in:
Dylan M. Taylor
2026-11-15 16:28:57 +00:00
parent 09f02d70b5
commit 6fa5a6fb56
3 changed files with 35 additions and 2 deletions
Generated
+1 -1
View File
@@ -1008,7 +1008,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=6d620e971e820b517b11a9
[[package]]
name = "craft-font-catalog"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=14bccd4e09094820babc434d2681297be8873bd9#14bccd4e09094820babc434d2681297be8873bd9"
source = "git+https://github.com/storytold/craft-libs?rev=58e2a887e6fe346deff2708513b0c1cd7c2af8c3#58e2a887e6fe346deff2708513b0c1cd7c2af8c3"
dependencies = [
"kurbo 0.13.1",
"skrifa 0.47.0",
+1 -1
View File
@@ -10,7 +10,7 @@ workspace = true
[dependencies]
# Pending shared extraction; pin the immutable official PR head until it merges.
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "14bccd4e09094820babc434d2681297be8873bd9", default-features = false }
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "58e2a887e6fe346deff2708513b0c1cd7c2af8c3", default-features = false }
vectorcraft-geom = { workspace = true }
vectorcraft-doc = { workspace = true }
kurbo = { workspace = true }
+33
View File
@@ -657,4 +657,37 @@ mod shared_outline_tests {
assert_eq!(*db.outline(&face, glyph.to_u32()), old.0, "glyph {ch}");
}
}
#[test]
fn malformed_cff_prefix_matches_original_pen() {
use skrifa::raw::ps::cff::CffFontRef;
let Ok(dir) = std::env::var("CRAFT_FONTS_DIR") else { return };
let mut bytes = std::fs::read(std::path::Path::new(&dir).join("fonts/noto-sans-cjk-sc/NotoSansCJKsc-Regular.otf")).unwrap();
let (gid, start) = {
let f = skrifa::FontRef::new(&bytes).unwrap();
let table = f.table_data(skrifa::Tag::new(b"CFF ")).unwrap().as_bytes();
let cff = CffFontRef::new(table, 0, None).unwrap();
let (gid, cs) = (0..cff.num_glyphs())
.find_map(|gid| {
let cs = cff.charstrings().get(gid as usize)?;
(cs.len() >= 8).then_some((gid, cs))
})
.unwrap();
(gid, cs.as_ptr() as usize - bytes.as_ptr() as usize)
};
bytes[start..start + 8].copy_from_slice(&[139, 139, 21, 239, 139, 5, 10, 14]);
let f = skrifa::FontRef::new(&bytes).unwrap();
let mut old = FlipPen(BezPath::new());
let result = f
.outline_glyphs()
.get(GlyphId::new(gid))
.unwrap()
.draw(DrawSettings::unhinted(Size::unscaled(), skrifa::instance::LocationRef::default()), &mut old);
assert!(result.is_err());
assert!(!old.0.elements().is_empty());
let shared = craft_font_catalog::FontOutline::from_bytes(&bytes, 0, &[]).unwrap();
let (path, status) = shared.outline_recovering(gid).unwrap();
assert!(status.is_err());
assert_eq!(kurbo::Affine::scale_non_uniform(1.0, -1.0) * path, old.0);
}
}