Cross platform TTF font render from Python [was: Load TTF from pycairo under Windows]

David Boddie david at boddie.org.uk
Fri Sep 18 22:43:55 EDT 2009


On Friday 18 September 2009 08:54, Laszlo Nagy wrote:

> I need to render antialiased PNG images using TTF font files and UTF-8
> text. It needs to be available at least on Linux and Windows. This is
> what I have tried:

[...]

> #4. pygame - documentation looks great, it is cross platform. But the
> first example program I had tried has been terminated, printing out
> memory dump and complaining about double freeing some memory location.

I'm surprised this doesn't work. I've seen games that are distributed
with TrueType fonts, so I would expect them to work, or people would
probably say something. :-)

> What other options do we have?

PyQt4 can render Unicode text to all sorts of paint devices, and it supports
TrueType fonts, too. You basically do all the painting via a single API:

  http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qpainter.html

Here's a quick example of how it could be done:

  http://www.diotavelli.net/PyQtWiki/Paint%20on%20an%20image

All the relevant stuff happens in the updateImage() method.

David



More information about the Python-list mailing list