[cairo] Problem with cairo_set_font_face (cr, NULL);

Peter Clifton pcjc2 at cam.ac.uk
Sun Aug 10 17:35:45 PDT 2008


Hi,

Apologies for the lack of in-depth debugging with this one, but I've
just rebuild cairo from GIT, and found that my app isn't rendering text
correctly. It is using toy text for the moment, and relies on the fact
it can call:

cairo_set_font_face (cr, NULL);

(NULL is sometimes passed from a function which I've got setup to choose
a font face).

Seems like the surface is thrown into error, as all future drawing stops
after attempting text.

It works if I do this:

+  if (face == NULL) {
+    cairo_select_font_face (w_current->cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+    face = cairo_get_font_face (w_current->cr);
+    cairo_font_face_reference (face);
+    /* Leak a reference so font face is never destroyed */
+  }

In the function I have which returns the font face. NB: The function
stashes the face in a static variable, returning the same one each time
it is called, so doesn't really leak that much memory.

FWIW, that function can also be built with some conditional compilation
to use the userfont API to create a face. That still works fine,
thankfully. It is just the case where userfont isn't available, the
function tries to return NULL to get a default toy font.

Regards,

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)



More information about the cairo mailing list