[reportlab-users] Re: FutureWarnings in ttfonts.py with Python 2.3

Marius Gedminas reportlab-users@reportlab.com
Mon, 5 Apr 2004 03:26:34 +0300

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Apr 02, 2004 at 02:58:07PM -0500, Marc Stober wrote:
> Robin wrote:
> > .... I don't get that with the latest pyd's and the CVS code. It's an
> > utter pain that they did the unification without introducing=20
> > an unsigned
> > 32 bit int so the bit twiddling can continue. The fix seems=20
> > to be to use
> >=20
> > def _L2U32(L):
> >         return unpack('l',pack('L',L))[0]
> > .....
> >
> > _L2U32((hi << 16L) | (lo & 0xFFFF))
> Hi Robin,
> I worked out a solution. The function above helps, but it's a little more
> complicated. The future warning is still raised when the hi << 16L is
> evaluated, before being passed to the function.=20
> I think that I now understand this warning is trying to say, "warning,
> bit-shifting is an ugly hack for modulo multiplication." So, I was able to
> use modulo multiplication directly, such as:
> _L2U32((hi * (2**16) % (2**32)) ... etc.
> The _L2U32 function is still needed to convert the result back to regular
> (non-long) int.
> I've uploaded a revised version of ttfonts.py to the SourceForge Patches
> area and tested it under Python 2.2 and 2.3. (A simple test it to generate
> the ReportLab userguide.)

Does the user guide use TrueType fonts?  I thought it used the standard
14 built-in Type 1 fonts that are included with Acrobat Reader and do
not have to be embedded.

Did you run the unit test suite?

I spent a few minutes experimenting with various variants of add32 a
while ago.  I was quite suprised to find out that using Python's longs
with bit shifts/addition modulo 2**32 did not give the desired results
when negative numbers came into the picture.  The best variant I could
come up with looked like this:

    def add32(x, y):
        z =3D x + y
        if z > 2147483647:
            return int(z - 4294967296L)
        elif z < -2147483648:
            return int(z + 4294967296L)
            return z

It was a tad slower than the current version with those future warnings
and incompatible with older versions of Python that did not promote ints
to longs on overflow.  I gave up at that point.

> Also, I don't think you'd get these warnings if you have the _rl_accel dll
> installed, as the bit-shifting part will be executed in the dll.

I certainly hope no bit-shifting will be executed at all, because all
this bit-shifting magic does is equivalent to the following C statement:

   c =3D a + b;

where a, b, and c are 32-bit numbers (for the purposes of checksumming
it does not matter if they're signed or unsigned).

<looks at the source code>

Oh, it does some bit-shifting.  For portability to big-endian systems, I

Marius Gedminas
Your eyes are weary from staring at the CRT.  You feel sleepy.  Notice how
restful it is to watch the cursor blink.  Close your eyes.  The opinions
stated above are yours.  You cannot imagine why you ever felt otherwise.

Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

Version: GnuPG v1.2.4 (GNU/Linux)