[varLib] Minor optimizations in maxp and TThinting
This commit is contained in:
parent
f387620572
commit
f80e19da35
@ -303,9 +303,10 @@ def _remove_TTHinting(font):
|
|||||||
for tag in ("cvar", "cvt ", "fpgm", "prep"):
|
for tag in ("cvar", "cvt ", "fpgm", "prep"):
|
||||||
if tag in font:
|
if tag in font:
|
||||||
del font[tag]
|
del font[tag]
|
||||||
|
maxp = font['maxp']
|
||||||
for attr in ("maxTwilightPoints", "maxStorage", "maxFunctionDefs", "maxInstructionDefs", "maxStackElements", "maxSizeOfInstructions"):
|
for attr in ("maxTwilightPoints", "maxStorage", "maxFunctionDefs", "maxInstructionDefs", "maxStackElements", "maxSizeOfInstructions"):
|
||||||
setattr(font["maxp"], attr, 0)
|
setattr(maxp, attr, 0)
|
||||||
font["maxp"].maxZones = 1
|
maxp.maxZones = 1
|
||||||
font["glyf"].removeHinting()
|
font["glyf"].removeHinting()
|
||||||
# TODO: Modify gasp table to deactivate gridfitting for all ranges?
|
# TODO: Modify gasp table to deactivate gridfitting for all ranges?
|
||||||
|
|
||||||
@ -320,12 +321,9 @@ def _merge_TTHinting(font, masterModel, master_ttfs):
|
|||||||
|
|
||||||
for tag in ("fpgm", "prep"):
|
for tag in ("fpgm", "prep"):
|
||||||
all_pgms = [m[tag].program for m in master_ttfs if tag in m]
|
all_pgms = [m[tag].program for m in master_ttfs if tag in m]
|
||||||
if len(all_pgms) == 0:
|
if not all_pgms:
|
||||||
continue
|
continue
|
||||||
if tag in font:
|
font_pgm = font[tag].program if tag in font else None
|
||||||
font_pgm = font[tag].program
|
|
||||||
else:
|
|
||||||
font_pgm = Program()
|
|
||||||
if any(pgm != font_pgm for pgm in all_pgms):
|
if any(pgm != font_pgm for pgm in all_pgms):
|
||||||
log.warning("Masters have incompatible %s tables, hinting is discarded." % tag)
|
log.warning("Masters have incompatible %s tables, hinting is discarded." % tag)
|
||||||
_remove_TTHinting(font)
|
_remove_TTHinting(font)
|
||||||
@ -333,20 +331,18 @@ def _merge_TTHinting(font, masterModel, master_ttfs):
|
|||||||
|
|
||||||
# glyf table
|
# glyf table
|
||||||
|
|
||||||
|
font_glyf = font['glyf']
|
||||||
master_glyfs = [m['glyf'] for m in master_ttfs]
|
master_glyfs = [m['glyf'] for m in master_ttfs]
|
||||||
for name, glyph in font["glyf"].glyphs.items():
|
for name, glyph in font_glyf.glyphs.items():
|
||||||
all_pgms = [
|
all_pgms = [
|
||||||
glyf[name].program
|
getattr(glyf[name], 'program', None)
|
||||||
for glyf in master_glyfs
|
for glyf in master_glyfs
|
||||||
if name in glyf and hasattr(glyf[name], "program")
|
if name in glyf
|
||||||
]
|
]
|
||||||
if not any(all_pgms):
|
if not any(all_pgms):
|
||||||
continue
|
continue
|
||||||
glyph.expand(font["glyf"])
|
glyph.expand(font_glyf)
|
||||||
if hasattr(glyph, "program"):
|
font_pgm = getattr(glyph, 'program', None)
|
||||||
font_pgm = glyph.program
|
|
||||||
else:
|
|
||||||
font_pgm = Program()
|
|
||||||
if any(pgm != font_pgm for pgm in all_pgms if pgm):
|
if any(pgm != font_pgm for pgm in all_pgms if pgm):
|
||||||
log.warning("Masters have incompatible glyph programs in glyph '%s', hinting is discarded." % name)
|
log.warning("Masters have incompatible glyph programs in glyph '%s', hinting is discarded." % name)
|
||||||
# TODO Only drop hinting from this glyph.
|
# TODO Only drop hinting from this glyph.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user