[subset] set emptied CFF charstrings to 'endchar' with --retain-gids
Part of #1446
This commit is contained in:
parent
71dbe2daea
commit
af1a0d1fe5
@ -104,6 +104,13 @@ def subset_glyphs(self, s):
|
|||||||
font = cff[fontname]
|
font = cff[fontname]
|
||||||
cs = font.CharStrings
|
cs = font.CharStrings
|
||||||
|
|
||||||
|
if s.options.retain_gids:
|
||||||
|
for g in cs.keys():
|
||||||
|
if g in s.glyphs_emptied:
|
||||||
|
c = cs[g]
|
||||||
|
c.decompile()
|
||||||
|
c.program = ["endchar"]
|
||||||
|
else:
|
||||||
# Load all glyphs
|
# Load all glyphs
|
||||||
for g in font.charset:
|
for g in font.charset:
|
||||||
if g not in s.glyphs: continue
|
if g not in s.glyphs: continue
|
||||||
|
@ -475,7 +475,7 @@ class SubsetTest(unittest.TestCase):
|
|||||||
subset.main([fontpath, "--recalc-timestamp", "--output-file=%s" % subsetpath, "*"])
|
subset.main([fontpath, "--recalc-timestamp", "--output-file=%s" % subsetpath, "*"])
|
||||||
self.assertLess(modified, TTFont(subsetpath)['head'].modified)
|
self.assertLess(modified, TTFont(subsetpath)['head'].modified)
|
||||||
|
|
||||||
def test_retain_gids(self):
|
def test_retain_gids_ttf(self):
|
||||||
_, fontpath = self.compile_font(self.getpath("TestTTF-Regular.ttx"), ".ttf")
|
_, fontpath = self.compile_font(self.getpath("TestTTF-Regular.ttx"), ".ttf")
|
||||||
font = TTFont(fontpath)
|
font = TTFont(fontpath)
|
||||||
|
|
||||||
@ -507,6 +507,41 @@ class SubsetTest(unittest.TestCase):
|
|||||||
self.assertGreater(glyf["A"].numberOfContours, 0)
|
self.assertGreater(glyf["A"].numberOfContours, 0)
|
||||||
self.assertEqual(glyf["B"].numberOfContours, 0)
|
self.assertEqual(glyf["B"].numberOfContours, 0)
|
||||||
|
|
||||||
|
def test_retain_gids_otf(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(".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))
|
||||||
|
|
||||||
|
subsetfont["CFF "].cff[0].decompileAllCharStrings()
|
||||||
|
cs = subsetfont["CFF "].cff[0].CharStrings
|
||||||
|
self.assertGreater(len(cs["A"].program), 0)
|
||||||
|
self.assertEqual(cs["B"].program, ["endchar"])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(unittest.main())
|
sys.exit(unittest.main())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user