[cairo] Loading font from a file in pycairo

Steven Chaplin stevech1097 at yahoo.com.au
Tue Aug 14 18:04:14 PDT 2007

On Tue, 2007-08-14 at 08:50 -0700, Carl Worth wrote: 
> On Fri, 10 Aug 2007 14:36:44 -0400, Michael Droettboom wrote:
> > It looks like it is possible in C to load a freetype font with
> > FT_Open_Face and then use cairo_ft_font_face_create_for_ft_face.
> Yes, that's possible.
> > Is freetype always assumed to be on all platforms,
> No.
> > or would one have to use
> > cairo_win32_font_face_create_for_hfont, for example, on Windows?
> Yes. By design, cairo does not abstract away the native font
> system. So, portable applications need to be able to talk to the
> native font system, (or else use a portable library like pango that
> does do some of that abstraction).
> > Are there any thoughts about exposing this in pycairo?  Is this just a
> > bad idea for reasons that I might be missing?
> Any functionality that cairo has should definitely be exposed in
> pycairo, (or any other language binding for cairo), in my opinion at
> least.

I would qualify that and say pycairo should expose all cairo
functionality when it is possible to do so. For example, pycairo does
not expose all the cairo xlib_surface functions because the required
Xlib Python bindings do not exist. Pycairo has a similar problem
exposing the cairo Font support for FreeType.

I think what Michael is suggesting is not exposing cairo functionality
in pycairo but extending cairo functionality by writing a pycairo
function that uses FreeType and Win32 C code to create a generic way to
load fonts from a file. Pycairo did previously have a couple of
functions which extended cairo functionality but they were criticised
for deviating from the cairo API and being confusing, and were removed.
So I don't think its a good idea to add more of these functions.

One possible solution would be for Matplotlib to release their FreeType
Python bindings as a stand-alone Python package. Then Pycairo could use
these bindings to provide access to the cairo FreeType fonts. But I
think a problem would be that the Matplotlib FreeType bindings are
customised for Matplotlib and do not expose the underlying FreeType
functions, and also they are written in C++ rather than C.


More information about the cairo mailing list