[varLib.mutator] Move test for interpolating CFF2 tables
from varLib_test.py to mutator_test.py
This commit is contained in:
parent
bde62cd653
commit
cf38e84f85
@ -2401,19 +2401,15 @@ class _DehintingT2Decompiler(psCharStrings.T2WidthExtractor):
|
|||||||
|
|
||||||
class _DesubroutinizingT2Decompiler(psCharStrings.SimpleT2Decompiler):
|
class _DesubroutinizingT2Decompiler(psCharStrings.SimpleT2Decompiler):
|
||||||
|
|
||||||
def __init__(self, localSubrs, globalSubrs):
|
def __init__(self, localSubrs, globalSubrs, private=None):
|
||||||
psCharStrings.SimpleT2Decompiler.__init__(self,
|
psCharStrings.SimpleT2Decompiler.__init__(self,
|
||||||
localSubrs,
|
localSubrs,
|
||||||
globalSubrs)
|
globalSubrs, private)
|
||||||
|
|
||||||
def execute(self, charString):
|
def execute(self, charString):
|
||||||
# Note: Currently we recompute _desubroutinized each time.
|
if (hasattr(charString, '_desubroutinized') and
|
||||||
# This is more robust in some cases, but in other places we assume
|
charString._desubroutinized):
|
||||||
# that each subroutine always expands to the same code, so
|
return
|
||||||
# maybe it doesn't matter. To speed up we can just not
|
|
||||||
# recompute _desubroutinized if it's there. For now I just
|
|
||||||
# double-check that it desubroutinized to the same thing.
|
|
||||||
old_desubroutinized = charString._desubroutinized if hasattr(charString, '_desubroutinized') else None
|
|
||||||
|
|
||||||
charString._patches = []
|
charString._patches = []
|
||||||
psCharStrings.SimpleT2Decompiler.execute(self, charString)
|
psCharStrings.SimpleT2Decompiler.execute(self, charString)
|
||||||
@ -2425,19 +2421,17 @@ class _DesubroutinizingT2Decompiler(psCharStrings.SimpleT2Decompiler):
|
|||||||
if expansion[-1] == 'return':
|
if expansion[-1] == 'return':
|
||||||
expansion = expansion[:-1]
|
expansion = expansion[:-1]
|
||||||
desubroutinized[idx-2:idx] = expansion
|
desubroutinized[idx-2:idx] = expansion
|
||||||
if 'endchar' in desubroutinized:
|
if not charString.isCFF2:
|
||||||
# Cut off after first endchar
|
if 'endchar' in desubroutinized:
|
||||||
desubroutinized = desubroutinized[:desubroutinized.index('endchar') + 1]
|
# Cut off after first endchar
|
||||||
else:
|
desubroutinized = desubroutinized[:desubroutinized.index('endchar') + 1]
|
||||||
if not len(desubroutinized) or desubroutinized[-1] != 'return':
|
else:
|
||||||
desubroutinized.append('return')
|
if not len(desubroutinized) or desubroutinized[-1] != 'return':
|
||||||
|
desubroutinized.append('return')
|
||||||
|
|
||||||
charString._desubroutinized = desubroutinized
|
charString._desubroutinized = desubroutinized
|
||||||
del charString._patches
|
del charString._patches
|
||||||
|
|
||||||
if old_desubroutinized:
|
|
||||||
assert desubroutinized == old_desubroutinized
|
|
||||||
|
|
||||||
def op_callsubr(self, index):
|
def op_callsubr(self, index):
|
||||||
subr = self.localSubrs[self.operandStack[-1]+self.localBias]
|
subr = self.localSubrs[self.operandStack[-1]+self.localBias]
|
||||||
psCharStrings.SimpleT2Decompiler.op_callsubr(self, index)
|
psCharStrings.SimpleT2Decompiler.op_callsubr(self, index)
|
||||||
@ -2596,6 +2590,30 @@ def _delete_empty_subrs(private_dict):
|
|||||||
del private_dict.rawDict['Subrs']
|
del private_dict.rawDict['Subrs']
|
||||||
del private_dict.Subrs
|
del private_dict.Subrs
|
||||||
|
|
||||||
|
@_add_method(ttLib.getTableClass('CFF2'))
|
||||||
|
def desubroutinize(self, font):
|
||||||
|
cff = self.cff
|
||||||
|
for fontname in cff.keys():
|
||||||
|
font = cff[fontname]
|
||||||
|
cs = font.CharStrings
|
||||||
|
for g in font.charset:
|
||||||
|
c, _ = cs.getItemAndSelector(g)
|
||||||
|
c.decompile()
|
||||||
|
subrs = getattr(c.private, "Subrs", [])
|
||||||
|
decompiler = _DesubroutinizingT2Decompiler(subrs, c.globalSubrs, c.private)
|
||||||
|
decompiler.execute(c)
|
||||||
|
c.program = c._desubroutinized
|
||||||
|
# Since we have flattened all the charstrings,
|
||||||
|
# we need to delete the subrs.
|
||||||
|
if font.GlobalSubrs:
|
||||||
|
del font.GlobalSubrs
|
||||||
|
if hasattr(font, 'FDArray'):
|
||||||
|
for fd in font.FDArray:
|
||||||
|
pd = fd.Private
|
||||||
|
subrs = getattr(pd, "Subrs", [])
|
||||||
|
if subrs:
|
||||||
|
del pd.Subrs
|
||||||
|
del pd.rawDict['Subrs']
|
||||||
|
|
||||||
@_add_method(ttLib.getTableClass('cmap'))
|
@_add_method(ttLib.getTableClass('cmap'))
|
||||||
def closure_glyphs(self, s):
|
def closure_glyphs(self, s):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user