Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cffLib] Fix for #1451 #1456

Merged
merged 2 commits into from Jan 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions Lib/fontTools/misc/psCharStrings.py
Expand Up @@ -983,6 +983,16 @@ def compile(self, isCFF2=False):
return
opcodes = self.opcodes
program = self.program

if isCFF2:
# If present, remove return and endchar operators.
if program and program[-1] in ("return", "endchar"):
program = program[:-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

del program[-1] would avoid the copy

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I thought it was nicer to not alter self.program. But I can change it if you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, you mean, in case the reference to program list was shared by some other object.. Ok, let's leave it like that.

elif program and not isinstance(program[-1], basestring):
raise CharStringCompileError(
"T2CharString or Subr has items on the stack after last operator."
)

bytecode = []
encodeInt = self.getIntEncoder()
encodeFixed = self.getFixedEncoder()
Expand All @@ -1005,22 +1015,13 @@ def compile(self, isCFF2=False):
bytecode.append(encodeFixed(token))
else:
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:
bytecode = bytesjoin(bytecode)
except TypeError:
log.error(bytecode)
raise
self.setBytecode(bytecode)

if isCFF2:
# If present, remove return and endchar operators.
if self.bytecode and (byteord(self.bytecode[-1]) in (11, 14)):
self.bytecode = self.bytecode[:-1]

def needsDecompilation(self):
return self.bytecode is not None

Expand Down