diff --git a/fontc/src/lib.rs b/fontc/src/lib.rs index 99509a900..59735ccc8 100644 --- a/fontc/src/lib.rs +++ b/fontc/src/lib.rs @@ -786,7 +786,7 @@ mod tests { }; use fontdrasil::types::GlyphName; use fontir::{ - ir, + ir::{self, KernParticipant}, orchestration::{Context as FeContext, WorkId as FeWorkIdentifier}, }; use indexmap::IndexSet; @@ -1886,4 +1886,104 @@ mod tests { fn captures_created_from_designspace() { assert_created_set("wght_var.designspace"); } + + fn assert_simple_kerning(source: &str) { + let temp_dir = tempdir().unwrap(); + let build_dir = temp_dir.path(); + let result = compile(Args::for_test(build_dir, source)); + + let kerning = result.fe_context.get_kerning(); + + let mut groups: Vec<_> = kerning + .groups + .iter() + .map(|(name, entries)| { + let mut entries: Vec<_> = entries.iter().map(|e| e.as_str()).collect(); + entries.sort(); + (name.as_str(), entries) + }) + .collect(); + groups.sort(); + + let mut kerns: Vec<_> = kerning + .kerns + .iter() + .map(|((side1, side2), values)| { + ( + side1, + side2, + values + .iter() + .map(|(loc, val)| { + assert_eq!(loc.axis_names().count(), 1, "Should be only weight"); + let (axis, pos) = loc.iter().next().unwrap(); + (format!("{axis} {}", pos.to_f32()), val.0) + }) + .collect::>(), + ) + }) + .collect(); + kerns.sort_by_key(|(side1, side2, _)| (*side1, *side2)); + + assert_eq!( + (groups, kerns), + ( + vec![ + ("public.kern1.brackets", vec!["bracketleft", "bracketright"],), + ("public.kern2.brackets", vec!["bracketleft", "bracketright"],) + ], + vec![ + ( + &KernParticipant::Glyph("bracketleft".into()), + &KernParticipant::Glyph("bracketright".into()), + vec![ + ("Weight 0".to_string(), -300.0), + ("Weight 1".to_string(), -150.0) + ], + ), + ( + &KernParticipant::Glyph("exclam".into()), + &KernParticipant::Glyph("exclam".into()), + vec![ + ("Weight 0".to_string(), -360.0), + ("Weight 1".to_string(), -100.0) + ], + ), + ( + &KernParticipant::Glyph("exclam".into()), + &KernParticipant::Glyph("hyphen".into()), + vec![("Weight 0".to_string(), 20.0),], + ), + ( + &KernParticipant::Glyph("exclam".into()), + &KernParticipant::Group("public.kern2.brackets".into()), + vec![("Weight 0".to_string(), -160.0),], + ), + ( + &KernParticipant::Glyph("hyphen".into()), + &KernParticipant::Glyph("hyphen".into()), + vec![ + ("Weight 0".to_string(), -150.0), + ("Weight 1".to_string(), -50.0) + ], + ), + ( + &KernParticipant::Group("public.kern1.brackets".into()), + &KernParticipant::Glyph("exclam".into()), + vec![("Weight 0".to_string(), -165.0),], + ), + ], + ), + ); + } + + #[test] + fn kerning_from_glyphs() { + assert_simple_kerning("glyphs3/WghtVar.glyphs"); + } + + #[test] + fn kerning_from_ufo() { + assert_simple_kerning("designspace_from_glyphs/WghtVar.designspace"); + } } diff --git a/fontir/src/ir.rs b/fontir/src/ir.rs index f85bfba4a..002e21787 100644 --- a/fontir/src/ir.rs +++ b/fontir/src/ir.rs @@ -123,10 +123,10 @@ pub struct Kerning { /// Concretely, a glyph or a group of glyphs. /// /// -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum KernParticipant { Glyph(GlyphName), - GroupName(GroupName), + Group(GroupName), } impl StaticMetadata { diff --git a/glyphs2fontir/src/source.rs b/glyphs2fontir/src/source.rs index 98b457a9a..bb6893bfa 100644 --- a/glyphs2fontir/src/source.rs +++ b/glyphs2fontir/src/source.rs @@ -509,7 +509,7 @@ fn kern_participant( ); let group = GroupName::from(&group_name); if groups.contains_key(&group) { - Some(KernParticipant::GroupName(group)) + Some(KernParticipant::Group(group)) } else { warn!("Invalid kern side: {raw_side}, no group {group_name}"); None diff --git a/resources/testdata/designspace_from_glyphs/README.md b/resources/testdata/designspace_from_glyphs/README.md new file mode 100644 index 000000000..1a86d1028 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/README.md @@ -0,0 +1,6 @@ +Created by converting .glyphs files using fontmake, e.g.: + +```shell +$ fontmake -o=ufo resources/testdata/glyphs3/WghtVar.glyphs +$ mv master_ufo/* resources/testdata/designspace_from_glyphs/ +``` \ No newline at end of file diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/fontinfo.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/fontinfo.plist new file mode 100644 index 000000000..3ad1eda79 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/fontinfo.plist @@ -0,0 +1,53 @@ + + + + + ascender + 800 + capHeight + 700 + copyright + Copy! + descender + -200 + familyName + WghtVar + italicAngle + 0 + openTypeHeadCreated + 2022/12/01 04:52:20 + openTypeNameDescription + The greatest weight var + openTypeNameLicenseURL + https://example.com/my/font/license + openTypeNameVersion + New Value + openTypeOS2Selection + + 7 + 8 + + openTypeOS2Type + + 3 + + postscriptUnderlinePosition + -100 + postscriptUnderlineThickness + 50 + styleMapFamilyName + WghtVar + styleMapStyleName + bold + styleName + Bold + unitsPerEm + 1000 + versionMajor + 42 + versionMinor + 42 + xHeight + 500 + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/bracketleft.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/bracketleft.glif new file mode 100644 index 000000000..58d3becdd --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/bracketleft.glif @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/bracketright.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/bracketright.glif new file mode 100644 index 000000000..4bd39ccd6 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/bracketright.glif @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/contents.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/contents.plist new file mode 100644 index 000000000..47862ecda --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/contents.plist @@ -0,0 +1,18 @@ + + + + + bracketleft + bracketleft.glif + bracketright + bracketright.glif + exclam + exclam.glif + hyphen + hyphen.glif + manual-component + manual-component.glif + space + space.glif + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/exclam.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/exclam.glif new file mode 100644 index 000000000..c16771227 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/exclam.glif @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/hyphen.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/hyphen.glif new file mode 100644 index 000000000..4bc2c7341 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/hyphen.glif @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/manual-component.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/manual-component.glif new file mode 100644 index 000000000..cd1d614cb --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/manual-component.glif @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/space.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/space.glif new file mode 100644 index 000000000..983348125 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/glyphs/space.glif @@ -0,0 +1,7 @@ + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/groups.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/groups.plist new file mode 100644 index 000000000..15368f4da --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/groups.plist @@ -0,0 +1,16 @@ + + + + + public.kern1.brackets + + bracketleft + bracketright + + public.kern2.brackets + + bracketleft + bracketright + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/kerning.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/kerning.plist new file mode 100644 index 000000000..c49f61f57 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/kerning.plist @@ -0,0 +1,21 @@ + + + + + bracketleft + + bracketright + -150 + + exclam + + exclam + -100 + + hyphen + + hyphen + -50 + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/layercontents.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/layercontents.plist new file mode 100644 index 000000000..b9c1a4f27 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/layercontents.plist @@ -0,0 +1,10 @@ + + + + + + public.default + glyphs + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/lib.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/lib.plist new file mode 100644 index 000000000..5390b2cd8 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/lib.plist @@ -0,0 +1,55 @@ + + + + + com.github.googlei18n.ufo2ft.filters + + + name + eraseOpenCorners + namespace + glyphsLib.filters + pre + + + + com.schriftgestaltung.customParameter.GSFont.disablesAutomaticAlignment + + com.schriftgestaltung.customParameter.GSFont.useNiceNames + 1 + com.schriftgestaltung.customParameter.GSFontMaster.customValue + 0 + com.schriftgestaltung.customParameter.GSFontMaster.customValue1 + 0 + com.schriftgestaltung.customParameter.GSFontMaster.customValue2 + 0 + com.schriftgestaltung.customParameter.GSFontMaster.customValue3 + 0 + com.schriftgestaltung.customParameter.GSFontMaster.iconName + Bold + com.schriftgestaltung.customParameter.GSFontMaster.weightValue + 700 + com.schriftgestaltung.customParameter.GSFontMaster.widthValue + 100 + com.schriftgestaltung.fontMasterOrder + 1 + com.schriftgestaltung.weightValue + 700 + com.schriftgestaltung.widthValue + 100 + public.glyphOrder + + space + exclam + hyphen + bracketleft + bracketright + manual-component + + public.postscriptNames + + manual-component + manualcomponent + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/metainfo.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/metainfo.plist new file mode 100644 index 000000000..7b8b34ac6 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Bold.ufo/metainfo.plist @@ -0,0 +1,10 @@ + + + + + creator + com.github.fonttools.ufoLib + formatVersion + 3 + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/fontinfo.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/fontinfo.plist new file mode 100644 index 000000000..6fc0f394c --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/fontinfo.plist @@ -0,0 +1,65 @@ + + + + + ascender + 737 + capHeight + 702 + copyright + Copy! + descender + -42 + familyName + WghtVar + italicAngle + 0 + openTypeHeadCreated + 2022/12/01 04:52:20 + openTypeNameDescription + The greatest weight var + openTypeNameLicenseURL + https://example.com/my/font/license + openTypeNameVersion + New Value + openTypeOS2Selection + + 7 + 8 + + openTypeOS2Type + + 3 + + postscriptBlueValues + + -16 + 0 + 737 + 753 + + postscriptOtherBlues + + -58 + -42 + + postscriptUnderlinePosition + -100 + postscriptUnderlineThickness + 50 + styleMapFamilyName + WghtVar + styleMapStyleName + regular + styleName + Regular + unitsPerEm + 1000 + versionMajor + 42 + versionMinor + 42 + xHeight + 501 + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/bracketleft.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/bracketleft.glif new file mode 100644 index 000000000..b6bf45046 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/bracketleft.glif @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/bracketright.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/bracketright.glif new file mode 100644 index 000000000..6431af611 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/bracketright.glif @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/contents.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/contents.plist new file mode 100644 index 000000000..47862ecda --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/contents.plist @@ -0,0 +1,18 @@ + + + + + bracketleft + bracketleft.glif + bracketright + bracketright.glif + exclam + exclam.glif + hyphen + hyphen.glif + manual-component + manual-component.glif + space + space.glif + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/exclam.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/exclam.glif new file mode 100644 index 000000000..5bc6d8c77 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/exclam.glif @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/hyphen.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/hyphen.glif new file mode 100644 index 000000000..8b2d57e97 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/hyphen.glif @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/manual-component.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/manual-component.glif new file mode 100644 index 000000000..1da63bcd3 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/manual-component.glif @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/space.glif b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/space.glif new file mode 100644 index 000000000..c05cd73f7 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/glyphs/space.glif @@ -0,0 +1,7 @@ + + + + + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/groups.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/groups.plist new file mode 100644 index 000000000..15368f4da --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/groups.plist @@ -0,0 +1,16 @@ + + + + + public.kern1.brackets + + bracketleft + bracketright + + public.kern2.brackets + + bracketleft + bracketright + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/kerning.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/kerning.plist new file mode 100644 index 000000000..716f79663 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/kerning.plist @@ -0,0 +1,30 @@ + + + + + bracketleft + + bracketright + -300 + + exclam + + exclam + -360 + hyphen + 20 + public.kern2.brackets + -160 + + hyphen + + hyphen + -150 + + public.kern1.brackets + + exclam + -165 + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/layercontents.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/layercontents.plist new file mode 100644 index 000000000..b9c1a4f27 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/layercontents.plist @@ -0,0 +1,10 @@ + + + + + + public.default + glyphs + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/lib.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/lib.plist new file mode 100644 index 000000000..f6d8314a3 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/lib.plist @@ -0,0 +1,55 @@ + + + + + com.github.googlei18n.ufo2ft.filters + + + name + eraseOpenCorners + namespace + glyphsLib.filters + pre + + + + com.schriftgestaltung.customParameter.GSFont.disablesAutomaticAlignment + + com.schriftgestaltung.customParameter.GSFont.useNiceNames + 1 + com.schriftgestaltung.customParameter.GSFontMaster.customValue + 0 + com.schriftgestaltung.customParameter.GSFontMaster.customValue1 + 0 + com.schriftgestaltung.customParameter.GSFontMaster.customValue2 + 0 + com.schriftgestaltung.customParameter.GSFontMaster.customValue3 + 0 + com.schriftgestaltung.customParameter.GSFontMaster.iconName + + com.schriftgestaltung.customParameter.GSFontMaster.weightValue + 400 + com.schriftgestaltung.customParameter.GSFontMaster.widthValue + 100 + com.schriftgestaltung.fontMasterOrder + 0 + com.schriftgestaltung.weightValue + 400 + com.schriftgestaltung.widthValue + 100 + public.glyphOrder + + space + exclam + hyphen + bracketleft + bracketright + manual-component + + public.postscriptNames + + manual-component + manualcomponent + + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/metainfo.plist b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/metainfo.plist new file mode 100644 index 000000000..7b8b34ac6 --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar-Regular.ufo/metainfo.plist @@ -0,0 +1,10 @@ + + + + + creator + com.github.fonttools.ufoLib + formatVersion + 3 + + diff --git a/resources/testdata/designspace_from_glyphs/WghtVar.designspace b/resources/testdata/designspace_from_glyphs/WghtVar.designspace new file mode 100644 index 000000000..b955de11c --- /dev/null +++ b/resources/testdata/designspace_from_glyphs/WghtVar.designspace @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ufo2fontir/src/source.rs b/ufo2fontir/src/source.rs index 4fa608296..2adad62c6 100644 --- a/ufo2fontir/src/source.rs +++ b/ufo2fontir/src/source.rs @@ -904,7 +904,7 @@ impl Work for KerningWork { let resolve_participant = |name: &norad::Name| { let group_name = GroupName::from(name.as_str()); if kerning.groups.contains_key(&group_name) { - return Some(KernParticipant::GroupName(group_name)); + return Some(KernParticipant::Group(group_name)); } let glyph_name = GlyphName::from(name.as_str()); if static_metadata.glyph_order.contains(&glyph_name) {