diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2008-08-07 15:44:11 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2008-08-08 03:01:15 -0400 |
commit | b01ad0835d25fbee91d037e4484ba652075ffb39 (patch) | |
tree | a2ce730322ef064328bccc3fb16140ddef505c3c /src/cairo-user-font.c | |
parent | d6ae23478ae6bde0714a50b2ed77e788f17cc03d (diff) |
[user-font] Add a cairo_t argument to cairo_user_scaled_font_init_func_t
The init func does not actually need to draw anything, but having a cairo_t
similar to that passed to render_glyph is handy for computing font extents.
This is because cairo makes doing some things really hard (if not impossible)
without a cairo_t.
The user-font-proxy test case is a great example of how the added cairo_t
makes life much easier.
Diffstat (limited to 'src/cairo-user-font.c')
-rw-r--r-- | src/cairo-user-font.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c index cb15ca43..bcc3cfab 100644 --- a/src/cairo-user-font.c +++ b/src/cairo-user-font.c @@ -74,6 +74,28 @@ typedef struct _cairo_user_scaled_font { /* #cairo_user_scaled_font_t */ +static cairo_t * +_cairo_user_scaled_font_create_meta_context (cairo_user_scaled_font_t *scaled_font) +{ + cairo_content_t content; + cairo_surface_t *meta_surface; + cairo_t *cr; + + content = scaled_font->base.options.antialias == CAIRO_ANTIALIAS_SUBPIXEL ? + CAIRO_CONTENT_COLOR_ALPHA : + CAIRO_CONTENT_ALPHA; + + meta_surface = _cairo_meta_surface_create (content, -1, -1); + cr = cairo_create (meta_surface); + cairo_surface_destroy (meta_surface); + + cairo_set_matrix (cr, &scaled_font->base.scale); + cairo_set_font_size (cr, 1.0); + cairo_set_font_options (cr, &scaled_font->base.options); + + return cr; +} + static const cairo_scaled_font_backend_t cairo_user_scaled_font_backend; static cairo_int_status_t @@ -89,17 +111,9 @@ _cairo_user_scaled_glyph_init (void *abstract_font, cairo_user_font_face_t *face = (cairo_user_font_face_t *) scaled_font->base.font_face; cairo_text_extents_t extents = scaled_font->default_glyph_extents; - cairo_content_t content = scaled_font->base.options.antialias == CAIRO_ANTIALIAS_SUBPIXEL ? - CAIRO_CONTENT_COLOR_ALPHA : - CAIRO_CONTENT_ALPHA; cairo_t *cr; - meta_surface = _cairo_meta_surface_create (content, -1, -1); - cr = cairo_create (meta_surface); - - cairo_set_matrix (cr, &scaled_font->base.scale); - cairo_set_font_size (cr, 1.0); - cairo_set_font_options (cr, &scaled_font->base.options); + cr = _cairo_user_scaled_font_create_meta_context (scaled_font); if (face->scaled_font_methods.render_glyph) status = face->scaled_font_methods.render_glyph ((cairo_scaled_font_t *)scaled_font, @@ -111,6 +125,8 @@ _cairo_user_scaled_glyph_init (void *abstract_font, if (status == CAIRO_STATUS_SUCCESS) status = cairo_status (cr); + meta_surface = cairo_surface_reference (cairo_get_target (cr)); + cairo_destroy (cr); if (status) { @@ -377,6 +393,8 @@ _cairo_user_font_face_scaled_font_create (void *abstract_ if (status == CAIRO_STATUS_SUCCESS && font_face->scaled_font_methods.init != NULL) { + cairo_t *cr; + /* Lock the scaled_font mutex such that user doesn't accidentally try * to use it just yet. */ CAIRO_MUTEX_LOCK (user_scaled_font->base.mutex); @@ -384,9 +402,17 @@ _cairo_user_font_face_scaled_font_create (void *abstract_ /* Give away fontmap lock such that user-font can use other fonts */ _cairo_scaled_font_register_placeholder_and_unlock_font_map (&user_scaled_font->base); + cr = _cairo_user_scaled_font_create_meta_context (user_scaled_font); + status = font_face->scaled_font_methods.init (&user_scaled_font->base, + cr, &font_extents); + if (status == CAIRO_STATUS_SUCCESS) + status = cairo_status (cr); + + cairo_destroy (cr); + _cairo_scaled_font_unregister_placeholder_and_lock_font_map (&user_scaled_font->base); CAIRO_MUTEX_UNLOCK (user_scaled_font->base.mutex); |