Skip to content

Commit

Permalink
Add test compiling VF with empty gvar
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed May 30, 2024
1 parent 8228814 commit f3c7154
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 0 deletions.
24 changes: 24 additions & 0 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2924,4 +2924,28 @@ mod tests {
.collect::<Vec<_>>()
);
}

#[test]
fn compile_empty_gvar_with_correct_axis_count() {
// The test font contains a 'wght' axis and only 1 UFO source with a variable
// FEA that varies the position of glyph 'A' based on the wght axis; the gvar
// actually contains no glyph variations. Taken from
// https://github.com/googlefonts/fontc/issues/815
let result = TestCompile::compile_source("varpos.designspace");
let font = result.font();

let fvar = font.fvar().unwrap();
let gvar = font.gvar().unwrap();

// We assert that axis_count matches fvar's despite the gvar being no-op
// (i.e. all glyph variations are empty)
assert_eq!(fvar.axis_count(), 1);
assert_eq!(fvar.axis_count(), gvar.axis_count());
let glyph_count = font.maxp().unwrap().num_glyphs();
assert_eq!(gvar.glyph_count(), glyph_count);
assert!((0..glyph_count).all(|gid| gvar
.glyph_variation_data(GlyphId::new(gid as u16))
// read-fonts would return an error when a glyph's variations are empty
.is_err()));
}
}
13 changes: 13 additions & 0 deletions resources/testdata/varpos.designspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<designspace format="5.0">
<axes>
<axis tag="wght" name="weight" minimum="100" maximum="900" default="400"/>
</axes>
<sources>
<source filename="varpos_Regular.ufo" stylename="Regular">
<location>
<dimension name="weight" xvalue="400"/>
</location>
</source>
</sources>
</designspace>
3 changes: 3 additions & 0 deletions resources/testdata/varpos_Regular.ufo/features.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
feature test {
pos A <100 0 (wght=400:200 wght=900:400) 0>;
} test;
30 changes: 30 additions & 0 deletions resources/testdata/varpos_Regular.ufo/fontinfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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>750</integer>
<key>capHeight</key>
<integer>750</integer>
<key>descender</key>
<integer>-250</integer>
<key>guidelines</key>
<array/>
<key>postscriptBlueValues</key>
<array/>
<key>postscriptFamilyBlues</key>
<array/>
<key>postscriptFamilyOtherBlues</key>
<array/>
<key>postscriptOtherBlues</key>
<array/>
<key>postscriptStemSnapH</key>
<array/>
<key>postscriptStemSnapV</key>
<array/>
<key>unitsPerEm</key>
<integer>1000</integer>
<key>xHeight</key>
<integer>500</integer>
</dict>
</plist>
27 changes: 27 additions & 0 deletions resources/testdata/varpos_Regular.ufo/glyphs/A_.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="A" format="2">
<advance width="500"/>
<unicode hex="0041"/>
<outline>
<contour>
<point x="0" y="500" type="line"/>
<point x="0" y="0" type="line"/>
<point x="500" y="0" type="line"/>
<point x="500" y="500" type="line"/>
</contour>
</outline>
<lib>
<dict>
<key>xyz.fontra.layer-names</key>
<dict>
<key>varpos_Regular/public.default</key>
<string>&lt;default&gt;</string>
</dict>
<key>xyz.fontra.source-names</key>
<dict>
<key>Regular</key>
<string>&lt;default&gt;</string>
</dict>
</dict>
</lib>
</glyph>
8 changes: 8 additions & 0 deletions resources/testdata/varpos_Regular.ufo/glyphs/contents.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>A</key>
<string>A_.glif</string>
</dict>
</plist>
8 changes: 8 additions & 0 deletions resources/testdata/varpos_Regular.ufo/glyphs/layerinfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>color</key>
<string>0.5,0,0.5,0.7</string>
</dict>
</plist>
10 changes: 10 additions & 0 deletions resources/testdata/varpos_Regular.ufo/layercontents.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>
10 changes: 10 additions & 0 deletions resources/testdata/varpos_Regular.ufo/lib.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">
<dict>
<key>public.glyphOrder</key>
<array>
<string>A</string>
</array>
</dict>
</plist>
10 changes: 10 additions & 0 deletions resources/testdata/varpos_Regular.ufo/metainfo.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">
<dict>
<key>creator</key>
<string>com.github.fonttools.ufoLib</string>
<key>formatVersion</key>
<integer>3</integer>
</dict>
</plist>

0 comments on commit f3c7154

Please sign in to comment.