diff options
author | Carl Worth <cworth@cworth.org> | 2006-08-08 00:19:51 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2006-08-08 00:19:51 -0700 |
commit | 401f0ce3c444e263f03055174791e993e6270c39 (patch) | |
tree | e260cd86bf00160d46dc624ebaf2c6fba887b830 /src | |
parent | 77fd0efa9a055c13e685f4c6b01597ae67a36fb7 (diff) | |
parent | 02b54ca6200b3e5a914b293dd4a0d56f432a5a9b (diff) |
Merge branch 'surface-font-options' into cairo
Diffstat (limited to 'src')
-rw-r--r-- | src/cairo-paginated-surface.c | 37 | ||||
-rw-r--r-- | src/cairo-pdf-surface.c | 15 | ||||
-rw-r--r-- | src/cairo-ps-surface.c | 15 | ||||
-rw-r--r-- | src/cairo-surface.c | 71 | ||||
-rw-r--r-- | src/cairo-xlib-surface.c | 5 | ||||
-rw-r--r-- | src/cairoint.h | 12 |
6 files changed, 106 insertions, 49 deletions
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c index 4938b381..79b39560 100644 --- a/src/cairo-paginated-surface.c +++ b/src/cairo-paginated-surface.c @@ -163,6 +163,25 @@ _cairo_paginated_surface_finish (void *abstract_surface) return CAIRO_STATUS_SUCCESS; } +static cairo_surface_t * +_cairo_paginated_surface_create_image_surface (void *abstract_surface, + int width, + int height) +{ + cairo_paginated_surface_t *surface = abstract_surface; + cairo_surface_t *image; + cairo_font_options_t options; + + image = _cairo_image_surface_create_with_content (surface->content, + width, + height); + + cairo_surface_get_font_options (surface, &options); + _cairo_surface_set_font_options (image, &options); + + return image; +} + static cairo_status_t _cairo_paginated_surface_acquire_source_image (void *abstract_surface, cairo_image_surface_t **image_out, @@ -174,9 +193,9 @@ _cairo_paginated_surface_acquire_source_image (void *abstract_surface, _cairo_surface_get_extents (surface->target, &extents); - image = _cairo_image_surface_create_with_content (surface->content, - extents.width, - extents.height); + image = _cairo_paginated_surface_create_image_surface (surface, + extents.width, + extents.height); _cairo_meta_surface_replay (surface->meta, image); @@ -221,9 +240,9 @@ _paint_page (cairo_paginated_surface_t *surface) double y_scale = surface->base.y_fallback_resolution / 72.0; cairo_matrix_t matrix; - image = _cairo_image_surface_create_with_content (surface->content, - surface->width * x_scale, - surface->height * y_scale); + image = _cairo_paginated_surface_create_image_surface (surface, + surface->width * x_scale, + surface->height * y_scale); _cairo_surface_set_device_scale (image, x_scale, y_scale); _cairo_meta_surface_replay (surface->meta, image); @@ -460,9 +479,9 @@ _cairo_paginated_surface_snapshot (void *abstract_other) _cairo_surface_get_extents (other->target, &extents); - surface = _cairo_image_surface_create_with_content (other->content, - extents.width, - extents.height); + surface = _cairo_paginated_surface_create_image_surface (other, + extents.width, + extents.height); _cairo_meta_surface_replay (other->meta, surface); diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index 132c604d..b546fcf0 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -454,19 +454,6 @@ _cairo_pdf_surface_clear (cairo_pdf_surface_t *surface) _cairo_array_truncate (&surface->streams, 0); } -static cairo_surface_t * -_cairo_pdf_surface_create_similar (void *abstract_src, - cairo_content_t content, - int width, - int height) -{ - cairo_format_t format = _cairo_format_from_content (content); - - /* Just return an image for now, until PDF surface can be used - * as source. */ - return cairo_image_surface_create (format, width, height); -} - static cairo_pdf_resource_t _cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface, const char *fmt, @@ -2646,7 +2633,7 @@ _cairo_pdf_surface_set_paginated_mode (void *abstract_surface, static const cairo_surface_backend_t cairo_pdf_surface_backend = { CAIRO_SURFACE_TYPE_PDF, - _cairo_pdf_surface_create_similar, + NULL, /* create_similar */ _cairo_pdf_surface_finish, NULL, /* acquire_source_image */ NULL, /* release_source_image */ diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index e0b611de..fd58a9e8 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -1140,19 +1140,6 @@ cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface) } } -static cairo_surface_t * -_cairo_ps_surface_create_similar (void *abstract_src, - cairo_content_t content, - int width, - int height) -{ - cairo_format_t format = _cairo_format_from_content (content); - - /* Just return an image for now, until PS surface can be used - * as source. */ - return cairo_image_surface_create (format, width, height); -} - static cairo_status_t _cairo_ps_surface_finish (void *abstract_surface) { @@ -2127,7 +2114,7 @@ _cairo_ps_surface_set_paginated_mode (void *abstract_surface, static const cairo_surface_backend_t cairo_ps_surface_backend = { CAIRO_SURFACE_TYPE_PS, - _cairo_ps_surface_create_similar, + NULL, /* create_similar */ _cairo_ps_surface_finish, NULL, /* acquire_source_image */ NULL, /* release_source_image */ diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 777b9542..3fd9176c 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -237,6 +237,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 * @@ -245,15 +247,28 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other, int width, int height) { + cairo_surface_t *surface = NULL; + 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); - else - return cairo_image_surface_create (format, width, height); + surface = other->backend->create_similar (other, content, width, height); + + if (!surface) + surface = cairo_image_surface_create (format, width, height); + + cairo_surface_get_font_options (other, &options); + _cairo_surface_set_font_options (surface, &options); + + cairo_surface_set_fallback_resolution (surface, + other->x_fallback_resolution, + other->y_fallback_resolution); + + return surface; } /** @@ -264,9 +279,12 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other, * @height: height of the new surface (in device-space units) * * Create a new surface that is as compatible as possible with an - * existing surface. The new surface will use the same backend as - * @other unless that is not possible for some reason. The type of the - * returned surface may be examined with cairo_surface_get_type(). + * existing surface. For example the new surface will have the same + * fallback resolution and font options as @other. Generally, the new + * surface will also use the same backend as @other, unless that is + * not possible for some reason. The type of the returned surface may + * be examined with cairo_surface_get_type(). + * * Initially the surface contents are all 0 (transparent if contents * have transparency, black otherwise.) * @@ -506,6 +524,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 @@ -521,11 +566,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/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index faf132a3..4ed29b7e 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -221,10 +221,11 @@ _cairo_xlib_surface_create_similar_with_format (void *abstract_src, /* As a good first approximation, if the display doesn't have even * the most elementary RENDER operation, then we're better off - * using image surfaces for all temporary operations + * using image surfaces for all temporary operations, so return NULL + * and let the fallback code happen. */ if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE(src)) { - return cairo_image_surface_create (format, width, height); + return NULL; } pix = XCreatePixmap (dpy, RootWindowOfScreen (src->screen), diff --git a/src/cairoint.h b/src/cairoint.h index 7d7a7f23..034463aa 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -932,6 +932,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 { @@ -1709,6 +1717,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); |