Refactor glyf and cmap code
Thanks @anthrotype!
This commit is contained in:
parent
a6543c344a
commit
f6be200765
|
@ -172,6 +172,8 @@ def add_glyph_data(font, seqs, seq_to_advance, vadvance):
|
||||||
pen = TTGlyphPen(None)
|
pen = TTGlyphPen(None)
|
||||||
empty_glyph = pen.glyph()
|
empty_glyph = pen.glyph()
|
||||||
glyf = font['glyf']
|
glyf = font['glyf']
|
||||||
|
else:
|
||||||
|
glyf = None
|
||||||
|
|
||||||
# We don't expect sequences to be in the glyphOrder, since we removed all the
|
# We don't expect sequences to be in the glyphOrder, since we removed all the
|
||||||
# single-cp sequences from it and don't expect it to already contain names
|
# single-cp sequences from it and don't expect it to already contain names
|
||||||
|
@ -196,7 +198,7 @@ def add_glyph_data(font, seqs, seq_to_advance, vadvance):
|
||||||
if name not in reverseGlyphMap:
|
if name not in reverseGlyphMap:
|
||||||
font.glyphOrder.append(name)
|
font.glyphOrder.append(name)
|
||||||
updatedGlyphOrder=True
|
updatedGlyphOrder=True
|
||||||
if 'glyf' in font:
|
if glyf is not None:
|
||||||
glyf[name] = empty_glyph
|
glyf[name] = empty_glyph
|
||||||
|
|
||||||
if updatedGlyphOrder:
|
if updatedGlyphOrder:
|
||||||
|
@ -349,12 +351,9 @@ def add_cmap_format_4(font):
|
||||||
newtable.platformID = 3
|
newtable.platformID = 3
|
||||||
newtable.platEncID = 1
|
newtable.platEncID = 1
|
||||||
newtable.language = 0
|
newtable.language = 0
|
||||||
newtable.cmap = {}
|
|
||||||
|
|
||||||
# Format 4 only has unicode values 0x0000 to 0xFFFF
|
# Format 4 only has unicode values 0x0000 to 0xFFFF
|
||||||
for cp, name in cmap.items():
|
newtable.cmap = newtable.cmap = {cp: name for cp, name in cmap.items() if cp <= 0xFFFF}
|
||||||
if cp < 65535:
|
|
||||||
newtable.cmap[cp] = name
|
|
||||||
|
|
||||||
font['cmap'].tables.append(newtable)
|
font['cmap'].tables.append(newtable)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user