summaryrefslogtreecommitdiff
path: root/src/cairo-surface.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2006-07-31 14:44:42 -0400
committerBehdad Esfahbod <behdad@behdad.org>2006-07-31 14:44:42 -0400
commitbdb4e1edadb78a2118ff70b28163f8bd4317f1ec (patch)
treec47566f83edc32e75d1e9dd0b1f53ac737e2afff /src/cairo-surface.c
parenta8a0082c53d060e07c10c6efda9bb808e354fd59 (diff)
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.
Diffstat (limited to 'src/cairo-surface.c')
-rw-r--r--src/cairo-surface.c55
1 files changed, 49 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;
}
/**
@@ -503,6 +513,33 @@ cairo_surface_set_user_data (cairo_surface_t *surface,
}
/**
+ * _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
* @options: a #cairo_font_options_t object into which to store
@@ -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);
}
/**