mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-06 01:30:19 +01:00
[cairo-font-options] Check for the nil-object.
The design is for the user to create a cairo_font_options_t object with cairo_font_options_create() and then is free to use it with any Cairo operation. This requires us to check when we may be about to overwrite the read-only nil object.
This commit is contained in:
parent
c441938569
commit
ede76a97ea
7 changed files with 35 additions and 9 deletions
|
|
@ -455,6 +455,11 @@ _cairo_toy_font_face_scaled_font_create (void *abstract_font_face
|
|||
{
|
||||
cairo_toy_font_face_t *font_face = abstract_font_face;
|
||||
const cairo_scaled_font_backend_t * backend = CAIRO_SCALED_FONT_BACKEND_DEFAULT;
|
||||
cairo_status_t status;
|
||||
|
||||
status = cairo_font_options_status ((cairo_font_options_t *) options);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
return backend->create_toy (font_face,
|
||||
font_matrix, ctm, options, scaled_font);
|
||||
|
|
|
|||
|
|
@ -113,8 +113,12 @@ slim_hidden_def (cairo_font_options_create);
|
|||
cairo_font_options_t *
|
||||
cairo_font_options_copy (const cairo_font_options_t *original)
|
||||
{
|
||||
cairo_font_options_t *options = malloc (sizeof (cairo_font_options_t));
|
||||
cairo_font_options_t *options;
|
||||
|
||||
if (original == &_cairo_font_options_nil)
|
||||
return (cairo_font_options_t *)&_cairo_font_options_nil;
|
||||
|
||||
options = malloc (sizeof (cairo_font_options_t));
|
||||
if (!options)
|
||||
return (cairo_font_options_t *)&_cairo_font_options_nil;
|
||||
|
||||
|
|
@ -157,6 +161,7 @@ cairo_font_options_status (cairo_font_options_t *options)
|
|||
else
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
slim_hidden_def (cairo_font_options_status);
|
||||
|
||||
/**
|
||||
* cairo_font_options_merge:
|
||||
|
|
|
|||
|
|
@ -1286,15 +1286,13 @@ _cairo_gstate_get_font_matrix (cairo_gstate_t *gstate,
|
|||
*matrix = gstate->font_matrix;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
void
|
||||
_cairo_gstate_set_font_options (cairo_gstate_t *gstate,
|
||||
const cairo_font_options_t *options)
|
||||
{
|
||||
_cairo_gstate_unset_scaled_font (gstate);
|
||||
|
||||
gstate->font_options = *options;
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -348,6 +348,10 @@ _cairo_scaled_font_init (cairo_scaled_font_t *scaled_font,
|
|||
cairo_matrix_t inverse;
|
||||
cairo_status_t status;
|
||||
|
||||
status = cairo_font_options_status ((cairo_font_options_t *) options);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* Initialize scaled_font->scale early for easier bail out on an
|
||||
* invalid matrix. */
|
||||
_cairo_scaled_font_init_key (scaled_font, font_face,
|
||||
|
|
@ -480,6 +484,9 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
|
|||
if (font_face->status)
|
||||
return (cairo_scaled_font_t *)&_cairo_scaled_font_nil;
|
||||
|
||||
if (cairo_font_options_status ((cairo_font_options_t *) options))
|
||||
return (cairo_scaled_font_t *)&_cairo_scaled_font_nil;
|
||||
|
||||
font_map = _cairo_scaled_font_map_lock ();
|
||||
if (font_map == NULL)
|
||||
return (cairo_scaled_font_t *)&_cairo_scaled_font_nil;
|
||||
|
|
@ -1644,6 +1651,9 @@ void
|
|||
cairo_scaled_font_get_font_options (cairo_scaled_font_t *scaled_font,
|
||||
cairo_font_options_t *options)
|
||||
{
|
||||
if (cairo_font_options_status (options))
|
||||
return;
|
||||
|
||||
if (scaled_font->status) {
|
||||
_cairo_font_options_init_default (options);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -603,6 +603,9 @@ void
|
|||
cairo_surface_get_font_options (cairo_surface_t *surface,
|
||||
cairo_font_options_t *options)
|
||||
{
|
||||
if (cairo_font_options_status (options))
|
||||
return;
|
||||
|
||||
if (!surface->has_font_options) {
|
||||
surface->has_font_options = TRUE;
|
||||
|
||||
|
|
|
|||
12
src/cairo.c
12
src/cairo.c
|
|
@ -2641,9 +2641,11 @@ cairo_set_font_options (cairo_t *cr,
|
|||
if (cr->status)
|
||||
return;
|
||||
|
||||
status = _cairo_gstate_set_font_options (cr->gstate, options);
|
||||
status = cairo_font_options_status ((cairo_font_options_t *) options);
|
||||
if (status)
|
||||
_cairo_set_error (cr, status);
|
||||
|
||||
_cairo_gstate_set_font_options (cr->gstate, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2661,6 +2663,10 @@ void
|
|||
cairo_get_font_options (cairo_t *cr,
|
||||
cairo_font_options_t *options)
|
||||
{
|
||||
/* check that we aren't trying to overwrite the nil object */
|
||||
if (cairo_font_options_status (options))
|
||||
return;
|
||||
|
||||
_cairo_gstate_get_font_options (cr->gstate, options);
|
||||
}
|
||||
|
||||
|
|
@ -2698,9 +2704,7 @@ cairo_set_scaled_font (cairo_t *cr,
|
|||
if (status)
|
||||
goto BAIL;
|
||||
|
||||
status = _cairo_gstate_set_font_options (cr->gstate, &scaled_font->options);
|
||||
if (status)
|
||||
goto BAIL;
|
||||
_cairo_gstate_set_font_options (cr->gstate, &scaled_font->options);
|
||||
|
||||
return;
|
||||
|
||||
|
|
|
|||
|
|
@ -1346,7 +1346,7 @@ cairo_private void
|
|||
_cairo_gstate_get_font_options (cairo_gstate_t *gstate,
|
||||
cairo_font_options_t *options);
|
||||
|
||||
cairo_private cairo_status_t
|
||||
cairo_private void
|
||||
_cairo_gstate_set_font_options (cairo_gstate_t *gstate,
|
||||
const cairo_font_options_t *options);
|
||||
|
||||
|
|
@ -2378,6 +2378,7 @@ slim_hidden_proto (cairo_font_options_set_antialias);
|
|||
slim_hidden_proto (cairo_font_options_set_hint_metrics);
|
||||
slim_hidden_proto (cairo_font_options_set_hint_style);
|
||||
slim_hidden_proto (cairo_font_options_set_subpixel_order);
|
||||
slim_hidden_proto (cairo_font_options_status);
|
||||
slim_hidden_proto (cairo_get_current_point);
|
||||
slim_hidden_proto (cairo_get_matrix);
|
||||
slim_hidden_proto (cairo_get_tolerance);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue