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

Add/update test files with kerning data #331

Merged
merged 3 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,12 @@ mod tests {
);

assert_eq!(
(0..4).map(GlyphId::new).collect::<Vec<_>>(),
vec![
GlyphId::new(0),
GlyphId::new(1),
GlyphId::new(2),
GlyphId::new(5),
],
[0x20, 0x21, 0x2d, 0x3d]
.iter()
.map(|cp| font.cmap().unwrap().map_codepoint(*cp as u32).unwrap())
Expand Down
62 changes: 55 additions & 7 deletions glyphs-reader/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ impl FeatureSnippet {
pub struct Glyph {
pub glyphname: String,
pub layers: Vec<Layer>,
/// The left kerning group
pub left_kern: Option<String>,
/// The right kerning group
pub right_kern: Option<String>,
}

#[derive(Debug, PartialEq, Hash)]
Expand Down Expand Up @@ -166,6 +170,8 @@ pub struct Axis {
pub struct RawGlyph {
pub layers: Vec<RawLayer>,
pub glyphname: String,
pub kern_left: Option<String>,
pub kern_right: Option<String>,
#[fromplist(rest)]
pub other_stuff: BTreeMap<String, Plist>,
}
Expand Down Expand Up @@ -975,6 +981,14 @@ impl RawFont {
if let Some(kerning) = self.other_stuff.remove("kerning") {
self.other_stuff.insert("kerningLTR".to_string(), kerning);
};
for glyph in self.glyphs.iter_mut() {
if let Some(Plist::String(group)) = glyph.other_stuff.remove("leftKerningGroup") {
glyph.kern_left = Some(group);
}
if let Some(Plist::String(group)) = glyph.other_stuff.remove("rightKerningGroup") {
glyph.kern_right = Some(group);
}
}
Ok(())
}

Expand Down Expand Up @@ -1340,6 +1354,8 @@ impl TryFrom<RawGlyph> for Glyph {
Ok(Glyph {
glyphname: from.glyphname,
layers: instances,
left_kern: from.kern_left,
right_kern: from.kern_right,
})
}
}
Expand Down Expand Up @@ -1953,7 +1969,14 @@ mod tests {
fn glyph_order_default_is_file_order() {
let font = Font::load(&glyphs3_dir().join("WghtVar.glyphs")).unwrap();
assert_eq!(
vec!["space", "exclam", "hyphen", "manual-component"],
vec![
"space",
"exclam",
"hyphen",
"bracketleft",
"bracketright",
"manual-component"
],
font.glyph_order
);
}
Expand Down Expand Up @@ -2192,6 +2215,22 @@ mod tests {
.collect::<HashSet<_>>()
);

let actual_groups: Vec<_> = font
.glyphs
.iter()
.filter_map(|(name, glyph)| {
if glyph.left_kern.is_some() || glyph.right_kern.is_some() {
Some((
name.as_str(),
glyph.left_kern.as_deref(),
glyph.right_kern.as_deref(),
))
} else {
None
}
})
.collect();

let actual_kerning = font
.kerning_ltr
.get("m01")
Expand All @@ -2201,12 +2240,21 @@ mod tests {
.collect::<Vec<_>>();

assert_eq!(
vec![
("exclam", "exclam", -360),
("exclam", "hyphen", 20),
("hyphen", "hyphen", -150),
],
actual_kerning,
(
vec![
("bracketleft", Some("brackets"), Some("brackets")),
("bracketright", Some("brackets"), Some("brackets")),
],
vec![
("@MMK_L_brackets", "exclam", -165),
("bracketleft", "bracketright", -300),
("exclam", "@MMK_R_brackets", -160),
("exclam", "exclam", -360),
("exclam", "hyphen", 20),
("hyphen", "hyphen", -150),
],
),
(actual_groups, actual_kerning),
);
}
}
24 changes: 19 additions & 5 deletions glyphs2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,14 @@ mod tests {
#[test]
fn find_glyphs() {
assert_eq!(
HashSet::from(["space", "hyphen", "exclam", "manual-component"]),
HashSet::from([
"space",
"hyphen",
"exclam",
"bracketleft",
"bracketright",
"manual-component"
]),
glyph_state_for_file(&glyphs3_dir(), "WghtVar.glyphs")
.keys()
.map(|k| k.as_str())
Expand Down Expand Up @@ -685,10 +692,17 @@ mod tests {
.map(|a| a.tag)
.collect::<Vec<_>>()
);
let expected: IndexSet<GlyphName> = vec!["space", "exclam", "hyphen", "manual-component"]
.iter()
.map(|s| (*s).into())
.collect();
let expected: IndexSet<GlyphName> = vec![
"space",
"exclam",
"hyphen",
"bracketleft",
"bracketright",
"manual-component",
]
.iter()
.map(|s| (*s).into())
.collect();
assert_eq!(expected, context.get_init_static_metadata().glyph_order);
}

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