psCharStrings: only assert no extra args on stack upon compile, not in toXML

Fixes #1451
This commit is contained in:
Cosimo Lupo 2019-01-17 11:48:35 +00:00
parent dec9ec0e73
commit 1702536150
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482

View File

@ -1005,6 +1005,10 @@ class T2CharString(object):
bytecode.append(encodeFixed(token)) bytecode.append(encodeFixed(token))
else: else:
assert 0, "unsupported type: %s" % type(token) assert 0, "unsupported type: %s" % type(token)
if not isCFF2 and program and not isinstance(program[-1], basestring):
raise CharStringCompileError(
"T2CharString or Subr has items on the stack after last operator."
)
try: try:
bytecode = bytesjoin(bytecode) bytecode = bytesjoin(bytecode)
except TypeError: except TypeError:
@ -1088,13 +1092,12 @@ class T2CharString(object):
else: else:
args.append(token) args.append(token)
if args: if args:
if self.isCFF2: # NOTE: only CFF2 charstrings/subrs can have numeric arguments on
# CFF2Subr's can have numeric arguments on the stack after the last operator. # the stack after the last operator. Compiling this would fail if
args = [str(arg) for arg in args] # this is part of CFF 1.0 table.
line = ' '.join(args) args = [str(arg) for arg in args]
xmlWriter.write(line) line = ' '.join(args)
else: xmlWriter.write(line)
assert 0, "T2Charstring or Subr has items on the stack after last operator."
def fromXML(self, name, attrs, content): def fromXML(self, name, attrs, content):
from fontTools.misc.textTools import binary2num, readHex from fontTools.misc.textTools import binary2num, readHex