Cross platform TTF font render from Python [was: Load TTF from pycairo under Windows]
robin at reportlab.com
Fri Sep 18 12:05:59 CEST 2009
Laszlo Nagy wrote:
> Hi All,
> 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:
> #1. PIL - it has some problems and I cannot use it. Specifically, the
> ImageFont.getsize() returns bad value for some fonts, and there are some
> TTF fonts that are rendered incorrectly (UTF-8)
> #2. pycairo - very sophisticated, nice features, knows and does
> everything correctly. However, has no native support for libfreetype. I
> could write an extension in C and use it from Linux. Not available on
> #3. gdmodule - I tried to install in under windows without success. No
> binary installer available.
> #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.
the reportlab graphics renderPM(_renderPM) module does most things with T1 and
TTF and works linux/win32. We use freetype2 internally to extract the curves
from ttf and then draw them with libart_lgpl which does anti-aliasing.
However, we don't render the fonts using freetype so hinting etc etc don't get done.
I think something similar could be done directly with PIL and the antigrain
I'm surprised when you say that libfreetype isn't available on windows. It's a
fairly hard road, but it can be travelled; certainly we built the parts of
freetype that we needed into our extension. That required only a static library
from freetype. I haven't needed to do this on windows since 2.1.5 so perhaps
it's harder now.
More information about the Python-list