CFF2 Subr items can have values on the stack after the last operator. These were not getting written to XML. Added new class CFFSubr so that we can make an assertion error in this case if the item is not a CFF2 Subr, and otherwise write the last values on the stack to the XML file

This commit is contained in:
ReadRoberts 2017-11-02 11:36:10 -07:00
parent 8b02b5a294
commit 83379be568
2 changed files with 23 additions and 2 deletions

View File

@ -614,6 +614,11 @@ class GlobalSubrsIndex(Index):
self.fdSelect = fdSelect
if fdArray:
self.fdArray = fdArray
if isCFF2:
# CFF2Subr's can have numeric arguments on the stack after the last operator.
self.subrClass = psCharStrings.CFF2Subr
self.charStringClass = psCharStrings.CFF2Subr
def produceItem(self, index, data, file, offset):
if self.private is not None:

View File

@ -1102,6 +1102,15 @@ class T2CharString(object):
args = []
else:
args.append(token)
if args:
if not isinstance(self, CFF2Subr):
assert 0, "T2Charstring or Subr has items on the stack after last operator."
else:
# CFF2Subr's can have numeric arguments on the stack after the last operator.
args = [str(arg) for arg in args]
line = ' '.join(args)
xmlWriter.write(line)
def fromXML(self, name, attrs, content):
from fontTools.misc.textTools import binary2num, readHex
@ -1136,6 +1145,8 @@ class T2CharString(object):
program.append(token)
self.setProgram(program)
class CFF2Subr(T2CharString):
pass
class T1CharString(T2CharString):
@ -1173,7 +1184,6 @@ class T1CharString(T2CharString):
extractor.execute(self)
self.width = extractor.width
class DictDecompiler(object):
operandEncoding = cffDictOperandEncoding
@ -1286,7 +1296,13 @@ class DictDecompiler(object):
else:
current = 0
for v in valueList:
try:
current = current + v
except:
print(valueList)
import pdb
pdb.set_trace()
print("Hello")
out.append(current)
return out