From 83379be568652ac6d4123cdc1073ff853f2b01b4 Mon Sep 17 00:00:00 2001 From: ReadRoberts Date: Thu, 2 Nov 2017 11:36:10 -0700 Subject: [PATCH] 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 --- Lib/fontTools/cffLib/__init__.py | 5 +++++ Lib/fontTools/misc/psCharStrings.py | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/cffLib/__init__.py b/Lib/fontTools/cffLib/__init__.py index 4a947527f..59f5ab5ac 100644 --- a/Lib/fontTools/cffLib/__init__.py +++ b/Lib/fontTools/cffLib/__init__.py @@ -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: diff --git a/Lib/fontTools/misc/psCharStrings.py b/Lib/fontTools/misc/psCharStrings.py index 8eabdfa9a..cd151cd49 100644 --- a/Lib/fontTools/misc/psCharStrings.py +++ b/Lib/fontTools/misc/psCharStrings.py @@ -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: - current = current + v + try: + current = current + v + except: + print(valueList) + import pdb + pdb.set_trace() + print("Hello") out.append(current) return out