From 898f6911f81fafa29bf95efc6d6cd1a6c242df76 Mon Sep 17 00:00:00 2001 From: Sascha Brawer Date: Thu, 31 Aug 2017 12:07:07 +0200 Subject: [PATCH] [AAT] Implement subsetting of anchor points table --- Lib/fontTools/subset/__init__.py | 8 + Tests/subset/data/TestANKR.ttx | 325 ++++++++++++++++++++++++++++++ Tests/subset/data/expect_ankr.ttx | 19 ++ Tests/subset/subset_test.py | 13 ++ 4 files changed, 365 insertions(+) create mode 100644 Tests/subset/data/TestANKR.ttx create mode 100644 Tests/subset/data/expect_ankr.ttx diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index 07a655ba1..58653daa2 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -1675,6 +1675,14 @@ def subset_glyphs(self, s): self.hdmx = {sz:_dict_subset(l, s.glyphs) for sz,l in self.hdmx.items()} return bool(self.hdmx) +@_add_method(ttLib.getTableClass('ankr')) +def subset_glyphs(self, s): + table = self.table.AnchorPoints + assert table.Format == 0, "unknown 'ankr' format %s" % table.Format + table.Anchors = {glyph: table.Anchors[glyph] for glyph in s.glyphs + if glyph in table.Anchors} + return len(table.Anchors) > 0 + @_add_method(ttLib.getTableClass('bsln')) def closure_glyphs(self, s): table = self.table.Baseline diff --git a/Tests/subset/data/TestANKR.ttx b/Tests/subset/data/TestANKR.ttx new file mode 100644 index 000000000..8bb37c794 --- /dev/null +++ b/Tests/subset/data/TestANKR.ttx @@ -0,0 +1,325 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TestANKR + + + Regular + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/subset/data/expect_ankr.ttx b/Tests/subset/data/expect_ankr.ttx new file mode 100644 index 000000000..faad14792 --- /dev/null +++ b/Tests/subset/data/expect_ankr.ttx @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index 09aa83429..e9b3cba99 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -95,6 +95,19 @@ class SubsetTest(unittest.TestCase): subsetfont = TTFont(subsetpath) self.expect_ttx(subsetfont, self.getpath("expect_no_notdef_outline_ttf.ttx"), ["glyf", "hmtx"]) + def test_subset_ankr(self): + _, fontpath = self.compile_font(self.getpath("TestANKR.ttx"), ".ttf") + subsetpath = self.temp_path(".ttf") + subset.main([fontpath, "--glyphs=one", "--output-file=%s" % subsetpath]) + subsetfont = TTFont(subsetpath) + self.expect_ttx(subsetfont, self.getpath("expect_ankr.ttx"), ["ankr"]) + + def test_subset_ankr_remove(self): + _, fontpath = self.compile_font(self.getpath("TestANKR.ttx"), ".ttf") + subsetpath = self.temp_path(".ttf") + subset.main([fontpath, "--glyphs=two", "--output-file=%s" % subsetpath]) + self.assertNotIn("ankr", TTFont(subsetpath)) + def test_subset_bsln_format_0(self): _, fontpath = self.compile_font(self.getpath("TestBSLN-0.ttx"), ".ttf") subsetpath = self.temp_path(".ttf")