Restructure code

This commit is contained in:
Nyshadh Reddy Rachamallu 2018-11-16 14:12:26 -05:00
parent dbfba397e0
commit e756d3eb52

View File

@ -122,16 +122,20 @@ def instantiateVariableFont(varfont, location, inplace=False):
log.info("Building interpolated tables")
merger.instantiate()
addidef = False
for glyph in glyf.glyphs.values():
if addidef:
break
if hasattr(glyph, "program"):
instructions = glyph.program.getAssembly()
# If GETVARIATION opcode is used in bytecode of any glyph add IDEF
addidef = False
for instruction in instructions:
if instruction.startswith("GETVARIATION"):
addidef = True
break
if addidef:
log.info("Adding IDEF to fpgm table for GETVARIATION opcode")
asm = []
if varfont.has_key('fpgm'):
fpgm = varfont['fpgm']
@ -140,7 +144,6 @@ def instantiateVariableFont(varfont, location, inplace=False):
fpgm = newTable('fpgm')
fpgm.program = ttProgram.Program()
varfont['fpgm'] = fpgm
log.info("Adding IDEF to fpgm table for GETVARIATION opcode")
asm.append("PUSHB[000] 145")
asm.append("IDEF[ ]")
args = [str(len(loc))]
@ -150,12 +153,17 @@ def instantiateVariableFont(varfont, location, inplace=False):
asm.append("ENDF[ ]")
fpgm.program.fromAssembly(asm)
# Change maxp attributes as IDEF is added
if varfont.has_key('maxp'):
if hasattr(varfont['maxp'], "maxInstructionDefs"):
varfont['maxp'].maxInstructionDefs += 1
if hasattr(varfont['maxp'], "maxStackElements"):
varfont['maxp'].maxStackElements += len(loc)
break
maxp = varfont['maxp']
if hasattr(maxp, "maxInstructionDefs"):
maxp.maxInstructionDefs += 1
else:
setattr(maxp, "maxInstructionDefs", 1)
if hasattr(maxp, "maxStackElements"):
maxp.maxStackElements += len(loc)
else:
setattr(maxp, "maxInstructionDefs", len(loc))
if 'name' in varfont:
log.info("Pruning name table")