From bdb4e1edadb78a2118ff70b28163f8bd4317f1ec Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 31 Jul 2006 14:44:42 -0400 Subject: [PATCH] Implement per-surface font options. New internal function _cairo_surface_set_font_options is used to set them. cairo_surface_create_similar propagates the font options of the other surface into the newly created surface. Fixes bugs with font options in fallback images and bug 4106. --- src/cairo-surface.c | 55 ++++++++++++++++++++++++++++++++++++++++----- src/cairoint.h | 12 ++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/cairo-surface.c b/src/cairo-surface.c index fb25e075b..914e2c713 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -234,6 +234,8 @@ _cairo_surface_init (cairo_surface_t *surface, surface->current_clip_serial = 0; surface->is_snapshot = FALSE; + + surface->has_font_options = FALSE; } cairo_surface_t * @@ -242,15 +244,23 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other, int width, int height) { + cairo_surface_t *surface; + cairo_font_options_t options; + cairo_format_t format = _cairo_format_from_content (content); if (other->status) return (cairo_surface_t*) &_cairo_surface_nil; if (other->backend->create_similar) - return other->backend->create_similar (other, content, width, height); + surface = other->backend->create_similar (other, content, width, height); else - return cairo_image_surface_create (format, width, height); + surface = cairo_image_surface_create (format, width, height); + + cairo_surface_get_font_options (other, &options); + _cairo_surface_set_font_options (surface, &options); + + return surface; } /** @@ -502,6 +512,33 @@ cairo_surface_set_user_data (cairo_surface_t *surface, key, user_data, destroy); } +/** + * _cairo_surface_set_font_options: + * @surface: a #cairo_surface_t + * @options: a #cairo_font_options_t object that contains the + * options to use for this surface instead of backend's default + * font options. + * + * Sets the default font rendering options for the surface. + * This is useful to correctly propagate default font options when + * falling back to an image surface in a backend implementation. + * This affects the options returned in cairo_surface_get_font_options(). + * + * If @options is %NULL the surface options are reset to those of + * the backend default. + **/ +void +_cairo_surface_set_font_options (cairo_surface_t *surface, + cairo_font_options_t *options) +{ + if (options) { + surface->has_font_options = TRUE; + _cairo_font_options_init_copy (&surface->font_options, options); + } else { + surface->has_font_options = FALSE; + } +} + /** * cairo_surface_get_font_options: * @surface: a #cairo_surface_t @@ -518,11 +555,17 @@ void cairo_surface_get_font_options (cairo_surface_t *surface, cairo_font_options_t *options) { - if (!surface->finished && surface->backend->get_font_options) { - surface->backend->get_font_options (surface, options); - } else { - _cairo_font_options_init_default (options); + if (!surface->has_font_options) { + surface->has_font_options = TRUE; + + if (!surface->finished && surface->backend->get_font_options) { + surface->backend->get_font_options (surface, &surface->font_options); + } else { + _cairo_font_options_init_default (&surface->font_options); + } } + + _cairo_font_options_init_copy (options, &surface->font_options); } /** diff --git a/src/cairoint.h b/src/cairoint.h index 4eb0c3cb3..7cf955dd3 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -893,6 +893,14 @@ struct _cairo_surface { /* A "snapshot" surface is immutable. See _cairo_surface_snapshot. */ cairo_bool_t is_snapshot; + + /* + * Surface font options, falling back to backend's default options, + * and set using _cairo_surface_set_font_options(), and propagated by + * cairo_surface_create_similar(). + */ + cairo_bool_t has_font_options; + cairo_font_options_t font_options; }; struct _cairo_image_surface { @@ -1670,6 +1678,10 @@ _cairo_surface_init (cairo_surface_t *surface, const cairo_surface_backend_t *backend, cairo_content_t content); +void +_cairo_surface_set_font_options (cairo_surface_t *surface, + cairo_font_options_t *options); + cairo_private cairo_clip_mode_t _cairo_surface_get_clip_mode (cairo_surface_t *surface);