Thanks, that sample code is very helpful for making the transition from cairo text rendering to cairo+pango text rendering.<br><br>Are there python examples for pango font metrics?<br>When just using cairo's font rendering, I would make calls such as
<br>x_bearing, y_bearing, width, height, x_advance, y_advance = ctx.text_extents( "how do i measure this in pango?" )<br><br>How do I measure these attributes in pango?<br><br>Thanks<br>Erik<br><br><div><span class="gmail_quote">
On 11/9/06, <b class="gmail_sendername">Behdad Esfahbod</b> <<a href="mailto:besfahbo@redhat.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">besfahbo@redhat.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Mon, 2006-11-06 at 21:08 -0500, Erik Blankinship wrote:<br>> Thanks for the warning about cairo's font rendering.<br>><br>> Could you please send a reference to how to use pangocairo with<br>> pycairo? I think that would be helpful for everyone on this list who
<br>> might use text in their application.<br><br>Attaching a complete test case. If you can find your way in the<br>example, the better, otherwise some explanation follows that may be<br>helpful mapping the C APIs to the pygtk ones.
<br><br><br>In the C API, there are three objects of interest:<br><br> cairo_t<br> PangoContext<br> PangoLayout<br><br>You can get a cairo_t for your widget using<br><br> gdk_cairo_create (widget->window)<br>
<br>You can also get a PangoContext using<br><br> gtk_widget_get_pango_context (widget)<br><br>You can create a PangoLayout either using a PangoContext:<br><br> pango_layout_new (pangocontext)<br><br>or get it directly from the widget:
<br><br> gtk_widget_create_pango_layout (widget)<br><br>There's also a third way, which is to create one using a cairo_t:<br><br> pango_cairo_create_layout (cr)<br><br><br>Of these, you should avoid the last one if possible, because that
<br>doesn't derive font and other properties from the widget style.<br><br><br>In pygtk, there is a convenience class hierarchy that doesn't really map<br>to the C api, so it's worth mentioning to reduce confusion:<br><br>
There is the cairo.Context object which is a cairo_t.<br><br>Then there is a pangocairo.CairoContext object which is a descendant of<br>cairo.Context, with additional methods mapping to the functions like<br>pango_cairo_create_layout() and pango_cairo_show_layout()... It
<br>actually makes sense, since those are functions taking a cairo_t as<br>their first argument, so they can be thought of as extended cairo_t<br>methods.<br><br>Then there is gtk.gdk.CairoContext that derives from<br>pangocairo.CairoContext
and extends that with some gdk methods, namely<br>set_source_color and set_source_pixbuf. Those too map to gkd_cairo_*()<br>functions that take a cairo_t as their first argument.<br><br>Now the cool part is that widget.window.cairo_create
() returns a<br>gtk.gdk.CairoContext, so you can do a show_layout() on it directly,<br>without having to create a pangocairo.CairoContext out of it.<br><br>The only thing to note is to not use the widget.window.cairo_create
()<br>context to create a PangoLayout directly (create_layout()) and use<br>widget.get_pango_context() instead, for reasons stated above.<br><br>behdad<br><br><br>> Erik<br>><br>> On 11/6/06, Behdad Esfahbod <
<a href="mailto:besfahbo@redhat.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">besfahbo@redhat.com</a>> wrote:<br>> On Fri, 2006-11-03 at 17:27 -0500, Erik Blankinship wrote:<br>
> > Hello<br>> ><br>> > If I want to use the system font in my cairo context, where
<br>> do I find<br>> > the font file to load in?<br>><br>> NEVER EVER use cairo's text rendering capabilities to render<br>> any text.<br>> Not in olpc at least. Use pangocairo ALL THE TIME.
<br>><br>> And for families, like others suggested, use "sans-serif",<br>> "serif", and<br>> "monospace".<br>><br>><br>> > Thanks,<br>
> > Erik
<br>><br>> --<br>> behdad<br>> <a href="http://behdad.org/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://behdad.org/</a><br>><br>><br>><br>--<br>
behdad<br><a href="http://behdad.org/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://behdad.org/</a><br><br>
<br></blockquote></div><br>