[cairo] Pango Layout lifecycle questions

Theo Veenker T.J.G.Veenker at uu.nl
Wed Aug 11 00:13:31 PDT 2010


On 08/11/2010 01:31 AM, Travis Griggs wrote:
> The first time I did a Pango binding to Smalltalk, I did it for simple
> cases, and kinda cheated, and didn't bind much. I'm going through and
> doing a more thorough/complete binding now. All of my Pango stuff is in
> the context of Cairo.
>
> The general problem I have, is that it's nice for an application to
> create a Layout object, and then just repeatedly draw it each time a
> display event happens. We map a CairoContext object, but they tend to be
> managed transiently, e.g.
>
> displayCallback
> create cairo context
> draw stuff
> unref context
>
> So the CairoContext tends to be unique or each draw cycle. But the
> apparent life cycle of a PangoLayout object is something like
>
> create PangoContext from CairoContext
> create Layout from PangoContext
>
> but I don't want to have to recreate the Layout every time I go through
> a display cycle. What's the better approach?

I'm creating the PangoContext without a cairo context! like this:

     PangoFontMap* fontmap = pango_cairo_font_map_get_default();
#if PANGO_VERSION_CHECK(1,21,4)
     pangocontext = pango_font_map_create_context(fontmap);
#else
     pangocontext = pango_cairo_font_map_create_context((PangoCairoFontMap*)fontmap);
#endif
     set font options, font description and resolution on pangocontext

The pangocontext I only recreate on font change. And I only recreate a layout
when I have to (text change, font change, alignment etc).

Theo


More information about the cairo mailing list