aboutsummaryrefslogtreecommitdiff
path: root/Tests/subset
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2019-02-01 17:02:23 -0800
committerHaibo Huang <hhb@google.com>2019-02-02 08:08:41 +0000
commitf08648c1c47988dac15b482a048685bf968f8216 (patch)
tree66627cf2059915c54933d5e5a9ed95a8817d8086 /Tests/subset
parent2995b148b5b97eec8eeed2f0ca97f513c5860674 (diff)
downloadfonttools-f08648c1c47988dac15b482a048685bf968f8216.tar.gz
Upgrade fonttools to 3.37.0
Test: build Change-Id: I8017400b21417deaefbe448e0880b06b66aefe8a
Diffstat (limited to 'Tests/subset')
-rw-r--r--Tests/subset/subset_test.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py
index 76d89c22..72fee41b 100644
--- a/Tests/subset/subset_test.py
+++ b/Tests/subset/subset_test.py
@@ -475,6 +475,107 @@ class SubsetTest(unittest.TestCase):
subset.main([fontpath, "--recalc-timestamp", "--output-file=%s" % subsetpath, "*"])
self.assertLess(modified, TTFont(subsetpath)['head'].modified)
+ def test_retain_gids_ttf(self):
+ _, fontpath = self.compile_font(self.getpath("TestTTF-Regular.ttx"), ".ttf")
+ font = TTFont(fontpath)
+
+ self.assertEqual(font["hmtx"]["A"], (500, 132))
+ self.assertEqual(font["hmtx"]["B"], (400, 132))
+
+ self.assertGreater(font["glyf"]["A"].numberOfContours, 0)
+ self.assertGreater(font["glyf"]["B"].numberOfContours, 0)
+
+ subsetpath = self.temp_path(".ttf")
+ subset.main(
+ [
+ fontpath,
+ "--retain-gids",
+ "--output-file=%s" % subsetpath,
+ "--glyph-names",
+ "A",
+ ]
+ )
+ subsetfont = TTFont(subsetpath)
+
+ self.assertEqual(subsetfont.getGlyphOrder(), font.getGlyphOrder())
+
+ hmtx = subsetfont["hmtx"]
+ self.assertEqual(hmtx["A"], (500, 132))
+ self.assertEqual(hmtx["B"], (0, 0))
+
+ glyf = subsetfont["glyf"]
+ self.assertGreater(glyf["A"].numberOfContours, 0)
+ self.assertEqual(glyf["B"].numberOfContours, 0)
+
+ def test_retain_gids_cff(self):
+ _, fontpath = self.compile_font(self.getpath("TestOTF-Regular.ttx"), ".otf")
+ font = TTFont(fontpath)
+
+ self.assertEqual(font["hmtx"]["A"], (500, 132))
+ self.assertEqual(font["hmtx"]["B"], (400, 132))
+
+ font["CFF "].cff[0].decompileAllCharStrings()
+ cs = font["CFF "].cff[0].CharStrings
+ self.assertGreater(len(cs["A"].program), 0)
+ self.assertGreater(len(cs["B"].program), 0)
+
+ subsetpath = self.temp_path(".otf")
+ subset.main(
+ [
+ fontpath,
+ "--retain-gids",
+ "--output-file=%s" % subsetpath,
+ "--glyph-names",
+ "A",
+ ]
+ )
+ subsetfont = TTFont(subsetpath)
+
+ self.assertEqual(subsetfont.getGlyphOrder(), font.getGlyphOrder())
+
+ hmtx = subsetfont["hmtx"]
+ self.assertEqual(hmtx["A"], (500, 132))
+ self.assertEqual(hmtx["B"], (0, 0))
+
+ subsetfont["CFF "].cff[0].decompileAllCharStrings()
+ cs = subsetfont["CFF "].cff[0].CharStrings
+ self.assertGreater(len(cs["A"].program), 0)
+ self.assertEqual(cs["B"].program, ["endchar"])
+
+ def test_retain_gids_cff2(self):
+ fontpath = self.getpath("../../varLib/data/TestCFF2VF.otf")
+ font = TTFont(fontpath)
+
+ self.assertEqual(font["hmtx"]["A"], (600, 31))
+ self.assertEqual(font["hmtx"]["T"], (600, 41))
+
+ font["CFF2"].cff[0].decompileAllCharStrings()
+ cs = font["CFF2"].cff[0].CharStrings
+ self.assertGreater(len(cs["A"].program), 0)
+ self.assertGreater(len(cs["T"].program), 0)
+
+ subsetpath = self.temp_path(".otf")
+ subset.main(
+ [
+ fontpath,
+ "--retain-gids",
+ "--output-file=%s" % subsetpath,
+ "A",
+ ]
+ )
+ subsetfont = TTFont(subsetpath)
+
+ self.assertEqual(len(subsetfont.getGlyphOrder()), len(font.getGlyphOrder()))
+
+ hmtx = subsetfont["hmtx"]
+ self.assertEqual(hmtx["A"], (600, 31))
+ self.assertEqual(hmtx["glyph00002"], (0, 0))
+
+ subsetfont["CFF2"].cff[0].decompileAllCharStrings()
+ cs = subsetfont["CFF2"].cff[0].CharStrings
+ self.assertGreater(len(cs["A"].program), 0)
+ self.assertEqual(cs["glyph00002"].program, [])
+
if __name__ == "__main__":
sys.exit(unittest.main())