Return three-byte operands from encodeIntCFF

This commit is contained in:
David Corbett 2023-07-06 15:45:31 -04:00 committed by Behdad Esfahbod
parent 3235454fcd
commit 4660b8c359

View File

@ -197,11 +197,14 @@ t2Operators = [
def getIntEncoder(format):
if format == "cff":
twoByteOp = bytechr(28)
fourByteOp = bytechr(29)
elif format == "t1":
twoByteOp = None
fourByteOp = bytechr(255)
else:
assert format == "t2"
twoByteOp = bytechr(28)
fourByteOp = None
def encodeInt(
@ -210,6 +213,7 @@ def getIntEncoder(format):
bytechr=bytechr,
pack=struct.pack,
unpack=struct.unpack,
twoByteOp=twoByteOp,
):
if -107 <= value <= 107:
code = bytechr(value + 139)
@ -219,11 +223,9 @@ def getIntEncoder(format):
elif -1131 <= value <= -108:
value = -value - 108
code = bytechr((value >> 8) + 251) + bytechr(value & 0xFF)
elif twoByteOp is not None and -32768 <= value <= 32767:
code = twoByteOp + pack(">h", value)
elif fourByteOp is None:
# T2 only supports 2 byte ints
if -32768 <= value <= 32767:
code = bytechr(28) + pack(">h", value)
else:
# Backwards compatible hack: due to a previous bug in FontTools,
# 16.16 fixed numbers were written out as 4-byte ints. When
# these numbers were small, they were wrongly written back as