[cairo] Reference counting of cairo free type face
Julian Viereck
julian.viereck at googlemail.com
Tue Nov 13 13:17:00 PST 2012
Hi there,
I try to add font support to the node-canvas [1] library, which uses
cairo for rendering. I use the freetype2 library to load a font face and
then use it in cairo. The font rendering is working, but I got stuck on
memory management of the cairo font face. In particular, the cairo font
face's reference counter is not reset to 1 at the point I expect it to be.
Here's what I'm doing. I concentrate on the essential parts only. Let
"ref(cr_face)" be "cairo_font_face_get_reference_count(cr_face)" to get
the internal reference counter for the cairo font face.
// Create a free type font face from a font file.
FT_New_Face(library, *filePath, faceIdx, &ft_face);
// Create a cairo font face.
cr_face = cairo_ft_font_face_create_for_ft_face(ft_face, 0);
// At this point ref(cr_face) == 1.
// Set the cairo font face on a cairo rendering context.
cairo_set_font_face(ctx, cr_face);
// At this point ref(cr_face) == 2. I guess that's okay, as the
font is requird for rendering.
cairo_text_path(ctx, str);
// At this point ref(cr_face) == 4.
cairo_destroy(ctx);
// At this point ref(cr_face) == 3.
Shouldn't the reference count after the "cairo_destory" be 1 again and
the cairo font face deleted? Do I need to perform some manually cleanup
first?
Hope someone can help me out here and very best,
Julian
PS: I use cairo 1.12.8 and the freetype 2.4.10 library.
---
[1]: https://github.com/LearnBoost/node-canvas
More information about the cairo
mailing list