Skip to content

Commit

Permalink
Merge pull request #2467 from aschmitz/subset-hotspots
Browse files Browse the repository at this point in the history
subset: speed up subsetting of large fonts
  • Loading branch information
anthrotype committed Dec 15, 2021
2 parents d4b7ff6 + d9f9466 commit fe2ba42
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Lib/fontTools/subset/cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def _empty_charstring(font, glyphName, isCFF2, ignoreWidth=False):
c, fdSelectIndex = font.CharStrings.getItemAndSelector(glyphName)
if isCFF2 or ignoreWidth:
# CFF2 charstrings have no widths nor 'endchar' operators
c.decompile()
c.program = [] if isCFF2 else ['endchar']
c.setProgram([] if isCFF2 else ['endchar'])
else:
if hasattr(font, 'FDArray') and font.FDArray is not None:
private = font.FDArray[fdSelectIndex].Private
Expand Down Expand Up @@ -120,9 +119,12 @@ def subset_glyphs(self, s):
#sel.format = None
sel.format = 3
sel.gidArray = [sel.gidArray[i] for i in indices]
cs.charStrings = {g:indices.index(v)
for g,v in cs.charStrings.items()
if g in glyphs}
newCharStrings = {}
for indicesIdx, charsetIdx in enumerate(indices):
g = font.charset[charsetIdx]
if g in cs.charStrings:
newCharStrings[g] = indicesIdx
cs.charStrings = newCharStrings
else:
cs.charStrings = {g:v
for g,v in cs.charStrings.items()
Expand Down

0 comments on commit fe2ba42

Please sign in to comment.