mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-07 01:40:35 +01:00
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.
This commit is contained in:
parent
a8a0082c53
commit
bdb4e1edad
2 changed files with 61 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue