Skip to content

Commit

Permalink
Add support for re-ordering glyphs in CFF fonts. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
garretrieger committed Sep 15, 2020
1 parent 7c78f3c commit d090835
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Optimizer/ReorderFont.py
Expand Up @@ -58,7 +58,7 @@ def dfs(table, font):
values = table
elif type(table) == dict:
values = table.values()
elif not table or type(table) == int or type(table) == str:
elif not table or type(table) == int or type(table) == str or type(table) == float:
values = []
else:
values = table.__dict__.values()
Expand Down Expand Up @@ -95,10 +95,18 @@ def reorderFont(input, fontNumber, desiredGlyphOrder, output):

font.setGlyphOrder(reorderedGlyphs)
# Glyph order is cached in a few places, clear those out.
del font["glyf"].glyphOrder
if "glyf" in font:
del font["glyf"].glyphOrder
if hasattr(font, "_reverseGlyphOrderDict"):
del font._reverseGlyphOrderDict

# CFF stores glyph order internally, set it:
if "CFF " in font:
cff = font["CFF "]
fontName = cff.cff.fontNames[0]
topDict = cff.cff[fontName]
topDict.charset = reorderedGlyphs

fixLayoutCoverage(font)

tmp = BytesIO()
Expand Down

0 comments on commit d090835

Please sign in to comment.