[cairo] font thrashing
David Reveman
c99drn at cs.umu.se
Sat May 1 08:47:56 PDT 2004
On Fri, 2004-04-30 at 16:15 -0400, John Ellson wrote:
> There needs to be some caching of font lookups, probably here in
> cairo_gstate.c:
>
>
> cairo_status_t
> _cairo_gstate_select_font (cairo_gstate_t *gstate,
> const char *family,
> cairo_font_slant_t slant,
> cairo_font_weight_t weight)
> {
> if (gstate->font != NULL)
> cairo_font_destroy (gstate->font);
>
>
>
> gstate->font = _cairo_font_create (family, slant, weight);
>
>
>
> return CAIRO_STATUS_SUCCESS;
> }
>
>
>
> If the same font request is repeated (from the SVG for example) then
> the previous font resolution (and its glyph caches) should be reused.
>
> Probably there should be a most-recently-used cache of 10 or so fonts.
>
> We noticed severe performance problems today when rendering an svg file
> that
> respecified the same font multiple times. David Reveman's glyph cache
> patch
> didn't help because the cache was destroyed each time the font was
> respecified.
>
>
> I wrote the generic font and glyph caching code in Tom Boutell's gd, so
> I could take a shot at coding this, unless anyone else wants to claim it?
The font and its glyph cache will not be destroyed if you take a
reference to the font.
example:
caior_select_font (cr, "Times",..
font1 = cairo_current_font (cr);
cairo_font_reference (font1);
caior_select_font (cr, "Sans",..
font2 = cairo_current_font (cr);
cairo_font_reference (font2);
...
font1 and font2 can then be set current with cairo_set_font and the
glyph cache will not be destroyed until you call cairo_font_destroy.
We can of course include this type of font caching in cairo but I think
it's better that we leave it to the application.
I cache fonts like this in Waimea WM and it works great. Adding this
kind of font cache to libsvg-cairo should be easy.
-David
More information about the cairo
mailing list