[sugar] New version of piemenu.py, and some cairo questions

Marco Pesenti Gritti mpg
Tue Feb 27 04:46:47 EST 2007


On Tue, 2007-02-27 at 10:45 +0200, Antoine van Gelder wrote:
> Don Hopkins wrote:
> > I could use some tips about measuring the bounding box of fonts and text 
> > in cairo, please.
> 
> 
> I gave up entirely on straight cairo text rendering and switched to 
> pango - which ended up looking something like this:
> 
> self.pango_context = self.create_pango_context()
> self.layout = pango.Layout(self.pango_context)
> fontDescription = pango.FontDescription("Monospace 8")
> self.layout.set_font_description(fontDescription)
> self.layout.set_text(text)
> (self.pixel_width, self.pixel_height) = self.layout.get_pixel_size()
> cairo_context.show_layout(self.layout)

Yeah, I think the preferred way to do text rendering is to use pango.
For a more complex example see the hippo canvas text item:

http://svn.mugshot.org/dumbhippo/trunk/client/common/canvas/hippo/hippo-canvas-text.c

Marco



More information about the Sugar-devel mailing list