[cairo] Cairo Font Cache
Edward.Zimmermann at cib.de
Wed Oct 23 16:39:50 CEST 2013
I'm trying to understand Cairo's font mechanism...
I create a face using Freetype and then create a Cairo font face.
fface = cairo_ft_font_face_create_for_ft_face (ft_face, load_flags);
when I am finished.. I destroy the fface, destroy the Freetype font and destroy the freetype library instance..
I don't use the font after I've chosen to destroy it..
What I have found is that the reference count does up when I set it into a drawing context.. Up again
when I apply a matrix--- backend does a scaled font and increases the reference count.
Even if I do a set font to NULL in my drawing context: cairo_set_font_face(cairo, NULL)
it seems that the reference count is still UP. Internally it seems that the scaled font is still waiting...
Only when the drawing context is destroyed does it go down.. But even at that time the font still is
in Cairo's own cache.
Again if I don't use the font.. why does it matter?
I would assume that this should not bother me since if I don't reference the font there is nothing to go
wrong.. right? Well I've found that after running for a while new fonts don't get correctly added and
we see zombies.. Fonts with characters that seem to pointing to the wrong glyphs!
Create a surface. Make a drawing context. Create a Freetype face, create a Cairo face on the Freetype face..
set a matrix.. use in a context.. draw a glyph... destroy Cairo face, FT_Done_Face on freetype face.. destroy
drawing context... destroy surface..
Yes when we've free'd the Freetype buffers there was stiff a reference count on the Cairo face.. But no more
Same things repeated over an over.. After a number of cycles a font can show a few wrong glyphs... No memory
faults.. Just wrong paths!
In the source and documentation it suggests that one install a callback via
cairo_font_face_set_user_data to destroy things..
1) I've found that the cairo_destroy_func_t does not get called at the end after I've destroyed everything..
2) If I've destroyed the freetype object myself when I was done with it, roughly at the time when the
callback would be called that zombies "can" appear. In a font its not all the characters that are wrong... we've
never seem this.. Only some seemingly random ones in a font.. The data is pointing to font paths since its
drawing.. just not the right paths...
Anyway to force the Cairo cache to sync itself? Why if I don't use any references to a Cairo font can't I
destroy the Freetype face behind it without having it mess up a different Cairo face?
Edward C. Zimmermann
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo