[cairo] Freetype to Cairo - newb needs help

Donn donn.ingle at gmail.com
Mon Oct 22 06:55:17 PDT 2007

 I am completely out of my depth here really. I have been hacking together the 
attached code for days. Everything about C/C++ bewilders me, but I make notes 
and I have a manual! 

I'm on Kubuntu Dapper Drake. I have source-installed the latest cairo, 
pycairo, pygtk -- all seems good.

Anyway, on to the issue:
1. I want to use pure python.
2. I want to use Cairo to draw strings of text to a surface.
3. I want to specify the file (or files) of what font I want it to use.

Number 3 in the list is the rub. I see there is 
a "cairo_ft_font_face_create_for_ft_face" function in the c/c++ API, but 
nothing like it in pycairo. I have searched around and it seems to be a grey 
area of controversy for lofty reasons I will never grasp.

So, like a fool, I thought, why not just extend Python with a module that will 
open font Blah with Freetype2, get the Cairo font whatsis from that and then 
pass it back up to Python! Yeah, right ...

My basic idea was to be able to say:
import cairo
import Foo
font = Foo.getfont("some/path/to/font.ttf")
cr = cairo.Context(self.surface)
cr.select_font_face(font, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
cr.etc( :) )

I want it to open Type1 fonts too, but that's another story, I don't yet know 
how Cairo handles those kinds of fonts.

I have attached the Makefile (which I cobbled-together randomly over a long 
period of time) too.

I hope someone can point me in the right direction.

"When considering questions about the nature of the cosmos and our place 
within it, atheists tend to draw their opinions from science. This isn't 
arrogance; it is intellectual honesty."
-- Sam Harris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.c
Type: text/x-csrc
Size: 1878 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071022/6b4b06d7/attachment.c 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: text/x-makefile
Size: 411 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071022/6b4b06d7/attachment.bin 

More information about the cairo mailing list