diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index 569137d24..513a86741 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -2239,6 +2239,12 @@ def prune_pre_subset(self, font, options): return True # Required table +@_add_method(ttLib.getTableClass('head')) +def prune_post_subset(self, font, options): + # Force re-compiling head table, to update any recalculated values. + return True + + # TODO(behdad) OS/2 ulCodePageRange? # TODO(behdad) Drop AAT tables. # TODO(behdad) Drop unneeded GSUB/GPOS Script/LangSys entries. diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index d2623cf22..956197a32 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -465,6 +465,46 @@ class SubsetTest(unittest.TestCase): subsetfont = TTFont(subsetpath) self.expect_ttx(subsetfont, self.getpath("expect_notdef_width_cid.ttx"), ["CFF "]) + def test_recalc_bounds_ttf(self): + ttxpath = self.getpath("TestTTF-Regular.ttx") + font = TTFont() + font.importXML(ttxpath) + head = font['head'] + bounds = [head.xMin, head.yMin, head.xMax, head.yMax] + + _, fontpath = self.compile_font(ttxpath, ".ttf") + subsetpath = self.temp_path(".ttf") + + # by default, the subsetter does not recalculate the bounding box + subset.main([fontpath, "--output-file=%s" % subsetpath, "*"]) + head = TTFont(subsetpath)['head'] + self.assertEqual(bounds, [head.xMin, head.yMin, head.xMax, head.yMax]) + + subset.main([fontpath, "--recalc-bounds", "--output-file=%s" % subsetpath, "*"]) + head = TTFont(subsetpath)['head'] + bounds = [132, 304, 365, 567] + self.assertEqual(bounds, [head.xMin, head.yMin, head.xMax, head.yMax]) + + def test_recalc_bounds_otf(self): + ttxpath = self.getpath("TestOTF-Regular.ttx") + font = TTFont() + font.importXML(ttxpath) + head = font['head'] + bounds = [head.xMin, head.yMin, head.xMax, head.yMax] + + _, fontpath = self.compile_font(ttxpath, ".otf") + subsetpath = self.temp_path(".otf") + + # by default, the subsetter does not recalculate the bounding box + subset.main([fontpath, "--output-file=%s" % subsetpath, "*"]) + head = TTFont(subsetpath)['head'] + self.assertEqual(bounds, [head.xMin, head.yMin, head.xMax, head.yMax]) + + subset.main([fontpath, "--recalc-bounds", "--output-file=%s" % subsetpath, "*"]) + head = TTFont(subsetpath)['head'] + bounds = [132, 304, 365, 567] + self.assertEqual(bounds, [head.xMin, head.yMin, head.xMax, head.yMax]) + def test_recalc_timestamp_ttf(self): ttxpath = self.getpath("TestTTF-Regular.ttx") font = TTFont()