[cairo] user-font proxies
Behdad Esfahbod
behdad at behdad.org
Mon May 26 12:00:38 PDT 2008
On Sun, 2008-05-25 at 01:30 -0400, Behdad Esfahbod wrote:
>
>
> The create part was uglier:
>
> static cairo_status_t
> test_scaled_font_init (cairo_scaled_font_t *scaled_font,
> cairo_font_extents_t *extents)
> {
> cairo_t *cr;
> cairo_surface_t *surface;
> cairo_matrix_t ctm;
> cairo_font_options_t *font_options;
> cairo_scaled_font_t *fallback_scaled_font;
>
> /* painful way to get default font face used by toy api */
> surface = cairo_image_surface_create (CAIRO_FORMAT_A8, 0, 0);
> cr = cairo_create (surface);
> cairo_surface_destroy (surface);
>
> cairo_set_font_size (cr, 1.);
> cairo_scaled_font_get_scale_matrix (scaled_font, &ctm);
> cairo_set_matrix (cr, &ctm);
>
> font_options = cairo_font_options_create ();
> cairo_scaled_font_get_font_options (scaled_font, font_options);
> cairo_set_font_options (cr, font_options);
> cairo_font_options_destroy (font_options);
>
> fallback_scaled_font = cairo_scaled_font_reference (cairo_get_scaled_font (cr)),
> cairo_scaled_font_set_user_data (scaled_font,
> &fallback_scaled_font_key,
> fallback_scaled_font,
> cairo_scaled_font_destroy);
>
> cairo_destroy (cr);
>
> cairo_scaled_font_extents (fallback_scaled_font, extents);
>
> return CAIRO_STATUS_SUCCESS;
> }
>
> Still not too bad if we correctly document the API and provide samples.
> Most of the pain is in getting the default toy font face without having
> a cairo_t around.
To fix this (and bridge some missing API gaps), I like to add:
void
cairo_toy_font_face_create (const char *family,
cairo_font_slant_t slant,
cairo_font_weight_t weight);
const char *
cairo_toy_font_face_get_family (cairo_font_face_t *font_face);
cairo_font_slant_t
cairo_toy_font_face_get_slant (cairo_font_face_t *font_face);
cairo_font_weight_t
cairo_toy_font_face_get_weight (cairo_font_face_t *font_face);
I probably will do this tomorrow. Comments?
--
behdad
http://behdad.org/
"Those who would give up Essential Liberty to purchase a little
Temporary Safety, deserve neither Liberty nor Safety."
-- Benjamin Franklin, 1759
More information about the cairo
mailing list