[reportlab-users] Marius' TTFontFile breaks in 2.2

Robin Becker reportlab-users@reportlab.com
Tue, 28 May 2002 14:47:28 +0100


well for the purposes of getting going I used the following code

def _add32(x, y):
    "Calculate (x + y) modulo 2**32"
    lo = (x & 0xFFFF) + (y & 0xFFFF)
    hi = (x >> 16) + (y >> 16) + (lo >> 16)
    return (hi << 16) | (lo & 0xFFFF)

def calcChecksum(data):
    """Calculates PDF-style checksums"""
    if len(data)&3: data = data + (4-(len(data)&3))*"\0"
    sum = 0
    for n in unpack(">%dl" % (len(data)>>2), data):
        lo = (sum & 0xFFFF) + (n & 0xFFFF)
        hi = (sum >> 16) + (n >> 16) + (lo >> 16)
        sum = (hi << 16) | (lo & 0xFFFF)
    return sum

and this although inefficient seems to work across the 2.2 int/long
unification. I will eventually put this into the _rl_accel extension if
it costs too much. I don't expect that it's really thatmuch of a worry
unless we're doing many large ttf files.
-- 
Robin Becker