Skip to content

Commit

Permalink
meh
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Jun 7, 2023
1 parent e22ac04 commit 5121112
Show file tree
Hide file tree
Showing 32 changed files with 696 additions and 5 deletions.
102 changes: 101 additions & 1 deletion fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Vec<_>>(),
)
})
.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");
}
}
4 changes: 2 additions & 2 deletions fontir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ pub struct Kerning {
/// Concretely, a glyph or a group of glyphs.
///
/// <https://unifiedfontobject.org/versions/ufo3/kerning.plist/#kerning-pair-types>
#[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 {
Expand Down
2 changes: 1 addition & 1 deletion glyphs2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions resources/testdata/designspace_from_glyphs/README.md
Original file line number Diff line number Diff line change
@@ -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/
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ascender</key>
<integer>800</integer>
<key>capHeight</key>
<integer>700</integer>
<key>copyright</key>
<string>Copy!</string>
<key>descender</key>
<integer>-200</integer>
<key>familyName</key>
<string>WghtVar</string>
<key>italicAngle</key>
<integer>0</integer>
<key>openTypeHeadCreated</key>
<string>2022/12/01 04:52:20</string>
<key>openTypeNameDescription</key>
<string>The greatest weight var</string>
<key>openTypeNameLicenseURL</key>
<string>https://example.com/my/font/license</string>
<key>openTypeNameVersion</key>
<string>New Value</string>
<key>openTypeOS2Selection</key>
<array>
<integer>7</integer>
<integer>8</integer>
</array>
<key>openTypeOS2Type</key>
<array>
<integer>3</integer>
</array>
<key>postscriptUnderlinePosition</key>
<integer>-100</integer>
<key>postscriptUnderlineThickness</key>
<integer>50</integer>
<key>styleMapFamilyName</key>
<string>WghtVar</string>
<key>styleMapStyleName</key>
<string>bold</string>
<key>styleName</key>
<string>Bold</string>
<key>unitsPerEm</key>
<integer>1000</integer>
<key>versionMajor</key>
<integer>42</integer>
<key>versionMinor</key>
<integer>42</integer>
<key>xHeight</key>
<integer>500</integer>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="bracketleft" format="2">
<advance width="600"/>
<unicode hex="005B"/>
<outline>
<contour>
<point x="454" y="629" type="line"/>
<point x="324" y="629" type="line"/>
<point x="324" y="58" type="line"/>
<point x="454" y="58" type="line"/>
<point x="454" y="-17" type="line"/>
<point x="243" y="-17" type="line"/>
<point x="243" y="704" type="line"/>
<point x="454" y="704" type="line"/>
</contour>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="bracketright" format="2">
<advance width="600"/>
<unicode hex="005D"/>
<outline>
<contour>
<point x="243" y="629" type="line"/>
<point x="243" y="704" type="line"/>
<point x="454" y="704" type="line"/>
<point x="454" y="-17" type="line"/>
<point x="243" y="-17" type="line"/>
<point x="243" y="58" type="line"/>
<point x="373" y="58" type="line"/>
<point x="373" y="629" type="line"/>
</contour>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bracketleft</key>
<string>bracketleft.glif</string>
<key>bracketright</key>
<string>bracketright.glif</string>
<key>exclam</key>
<string>exclam.glif</string>
<key>hyphen</key>
<string>hyphen.glif</string>
<key>manual-component</key>
<string>manual-component.glif</string>
<key>space</key>
<string>space.glif</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="exclam" format="2">
<advance width="600"/>
<unicode hex="0021"/>
<outline>
<contour>
<point x="228" y="174" type="line"/>
<point x="364" y="176" type="line"/>
<point x="434" y="605" type="line"/>
<point x="159" y="605" type="line"/>
</contour>
<contour>
<point x="228" y="-20" type="line"/>
<point x="364" y="-20" type="line"/>
<point x="364" y="94" type="line"/>
<point x="228" y="94" type="line"/>
</contour>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="hyphen" format="2">
<advance width="600"/>
<unicode hex="002D"/>
<outline>
<contour>
<point x="92" y="356" type="line"/>
<point x="92" y="224" type="line"/>
<point x="508" y="224" type="line"/>
<point x="508" y="356" type="line"/>
</contour>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="manual-component" format="2">
<advance width="600"/>
<unicode hex="003D"/>
<outline>
<component base="hyphen" xScale="1.15" yScale="1.25" xOffset="10" yOffset="100"/>
<component base="hyphen"/>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="space" format="2">
<advance width="600"/>
<unicode hex="0020"/>
<outline>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>public.kern1.brackets</key>
<array>
<string>bracketleft</string>
<string>bracketright</string>
</array>
<key>public.kern2.brackets</key>
<array>
<string>bracketleft</string>
<string>bracketright</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bracketleft</key>
<dict>
<key>bracketright</key>
<integer>-150</integer>
</dict>
<key>exclam</key>
<dict>
<key>exclam</key>
<integer>-100</integer>
</dict>
<key>hyphen</key>
<dict>
<key>hyphen</key>
<integer>-50</integer>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<array>
<string>public.default</string>
<string>glyphs</string>
</array>
</array>
</plist>
Loading

0 comments on commit 5121112

Please sign in to comment.