static cairo_font_face_t * get_user_font_face (void) { if (!user_font_face) { cairo_font_face_t *fallback_font_face; user_font_face = cairo_user_font_face_create (); cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init); cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph); cairo_user_font_face_set_text_to_glyphs_func (user_font_face, test_scaled_font_text_to_glyphs); /* This also happens to be default font face on cairo_t, so does * not make much sense here. For demonstration only. */ fallback_font_face = cairo_toy_font_face_create ("", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_font_face_set_user_data (user_font_face, &fallback_font_key, fallback_font_face, (cairo_destroy_func_t) cairo_font_face_destroy); } return user_font_face; }
static cairo_status_t _user_font_face_create (cairo_font_face_t **out) { cairo_font_face_t *user_font_face; cairo_font_face_t *fallback_font_face; cairo_status_t status; user_font_face = cairo_user_font_face_create (); cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init); cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph); cairo_user_font_face_set_text_to_glyphs_func (user_font_face, test_scaled_font_text_to_glyphs); /* This also happens to be default font face on cairo_t, so does * not make much sense here. For demonstration only. */ fallback_font_face = cairo_toy_font_face_create ("", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); status = cairo_font_face_set_user_data (user_font_face, &fallback_font_key, fallback_font_face, (cairo_destroy_func_t) cairo_font_face_destroy); if (status) { cairo_font_face_destroy (fallback_font_face); cairo_font_face_destroy (user_font_face); return status; } *out = user_font_face; return CAIRO_STATUS_SUCCESS; }
static VALUE cr_user_font_face_initialize (VALUE self) { cairo_font_face_t *face; face = cairo_user_font_face_create (); cr_font_face_check_status (face); cairo_font_face_set_user_data (face, &ruby_object_key, (void *)self, NULL); cairo_user_font_face_set_init_func (face, cr_user_font_face_init_func); cairo_user_font_face_set_render_glyph_func (face, cr_user_font_face_render_glyph_func); cairo_user_font_face_set_text_to_glyphs_func (face, cr_user_font_face_text_to_glyphs_func); cairo_user_font_face_set_unicode_to_glyph_func (face, cr_user_font_face_unicode_to_glyph_func); rb_ivar_set (self, cr_id_init, Qnil); rb_ivar_set (self, cr_id_render_glyph, Qnil); rb_ivar_set (self, cr_id_text_to_glyphs, Qnil); rb_ivar_set (self, cr_id_unicode_to_glyph, Qnil); DATA_PTR (self) = face; return Qnil; }
UserFont::UserFont(SvgFont* instance){ this->face = cairo_user_font_face_create (); cairo_user_font_face_set_init_func (this->face, font_init_cb); cairo_user_font_face_set_render_glyph_func (this->face, font_render_glyph_cb); cairo_user_font_face_set_text_to_glyphs_func(this->face, font_text_to_glyphs_cb); cairo_font_face_set_user_data (this->face, &key, (void*)instance, (cairo_destroy_func_t) NULL); }