[cairo] User font callbacks and user data

Torsten Schoenfeld kaffeetisch at gmx.de
Sun Oct 26 06:20:16 PDT 2008

Chris wrote:
> I noticed there were some user-font callbacks added in 1.8:
>   cairo_user_font_face_set_init_func
>   cairo_user_font_face_set_render_glyph_func
>   cairo_user_font_face_set_text_to_glyphs_func
>   cairo_user_font_face_set_unicode_to_glyph_func
> I'm trying to implement these in a scripting language but I'm having 
> trouble because unlike the other callbacks these do not seem to have a 
> "user data" parameter.  This is necessary to proxy the C function call 
> to a function in the scripting language.
> At first I was thinking I could set a user data on the font face but 
> then I realized that might not work because when the callbacks are 
> called they are using a scaled font type and not a font face.

I haven't looked into wrapping those myself, but if I understand the 
documentation[1] correctly, you can use cairo_font_face_set_user_data() to 
install font-face-specific user data.  Like a struct that contains all the 
information you need to marshal all the callbacks.  In your wrapper callbacks, 
you can then use cairo_scaled_font_get_font_face() to get the font face on which 
you can call cairo_font_face_get_user_data() to get your struct.


[1] http://cairographics.org/manual/cairo-user-font.html#cairo-user-font-face-create

More information about the cairo mailing list