[reportlab-users] Marius' TTFontFile breaks in 2.2
Robin Becker
reportlab-users@reportlab.com
Mon, 27 May 2002 19:33:36 +0100
Hi, we're trying to get a release out this week and I'm having problems
with the Checksum for Marius' TTFont check sum. I suspect that the
Python 2.2 changes to int/long in the following code are causing the
problem.
checkSum = calcChecksum(self._data)
checkSum = _add32(0xB1B0AFBA, -checkSum)
where
def _add32(x, y):
"Calculate (x + y) modulo 2**32"
try:
return x + y
except OverflowError:
lo = (x & 0xFFFF) + (y & 0xFFFF)
hi = (x >> 16) + (y >> 16) + (lo >> 16)
return (hi << 16) | (lo & 0xFFFF)
def calcChecksum(stream):
"""Calculates PDF-style checksums"""
if len(stream) & 3:
stream = stream + "\0\0\0"
stream = stream[:len(stream)&~3]
sum = 0
for n in unpack(">%dl" % (len(stream)/4), stream):
try:
sum = sum + n
except OverflowError:
# This is just (sum + n) with overflow ignored
lo = (sum & 0xFFFF) + (n & 0xFFFF)
hi = (sum >> 16) + (n >> 16) + (lo >> 16)
sum = (hi << 16) | (lo & 0xFFFF)
return sum
--
Robin Becker