Merge pull request #1612 from khaledhosny/subset-head

[subset] Update font extents in head table
This commit is contained in:
Khaled Hosny 2019-05-17 21:17:18 +02:00 committed by GitHub
commit 9c0811c066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View File

@ -2239,6 +2239,12 @@ def prune_pre_subset(self, font, options):
return True # Required table 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) OS/2 ulCodePageRange?
# TODO(behdad) Drop AAT tables. # TODO(behdad) Drop AAT tables.
# TODO(behdad) Drop unneeded GSUB/GPOS Script/LangSys entries. # TODO(behdad) Drop unneeded GSUB/GPOS Script/LangSys entries.

View File

@ -465,6 +465,46 @@ class SubsetTest(unittest.TestCase):
subsetfont = TTFont(subsetpath) subsetfont = TTFont(subsetpath)
self.expect_ttx(subsetfont, self.getpath("expect_notdef_width_cid.ttx"), ["CFF "]) 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): def test_recalc_timestamp_ttf(self):
ttxpath = self.getpath("TestTTF-Regular.ttx") ttxpath = self.getpath("TestTTF-Regular.ttx")
font = TTFont() font = TTFont()