diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-02-11 14:58:21 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-02-15 13:50:42 +0000 |
commit | ad265cc9f26a20f2336747d69b28bc6ca0d91f4b (patch) | |
tree | 879b767e5d236214405704c56760acea25c5fa5d /src | |
parent | 790eaef71cbd30e1994c9499ab553f2ef5e5d620 (diff) | |
download | cairo-ad265cc9f26a20f2336747d69b28bc6ca0d91f4b.tar.gz |
[cairo-font-options] Disallow use of NULL font-options.
Partial revert of commit 0086db893cba90dc73824d77c661d2965ad48112.
This is a follow to the earlier commit that allowed creation of scaled
fonts using a NULL font options (by interpreting the NULL as meaning
use the default options) to reflect the comments made by Behdad
(http://lists.cairographics.org/archives/cairo/2008-January/012714.html).
The intent is that the public font options getter/setter API has similar
defensive behaviour to that of the core objects - i.e. do not overwrite
the nil object and if the object is in error then return the default
value. For the indirect use of a NULL/nil font options (e.g. creation of
scaled fonts), then an error should be returned rather than crashing.
Diffstat (limited to 'src')
-rw-r--r-- | src/cairo-font-face.c | 8 | ||||
-rw-r--r-- | src/cairo-font-options.c | 36 | ||||
-rw-r--r-- | src/cairo-ft-font.c | 8 | ||||
-rw-r--r-- | src/cairo-scaled-font.c | 13 | ||||
-rw-r--r-- | src/cairo-win32-font.c | 4 | ||||
-rw-r--r-- | src/cairo.c | 10 |
6 files changed, 30 insertions, 49 deletions
diff --git a/src/cairo-font-face.c b/src/cairo-font-face.c index 397dd563b..20771209a 100644 --- a/src/cairo-font-face.c +++ b/src/cairo-font-face.c @@ -476,11 +476,9 @@ _cairo_toy_font_face_scaled_font_create (void *abstract_font_face if (font_face->base.status) return font_face->base.status; - if (options != NULL) { - status = cairo_font_options_status ((cairo_font_options_t *) options); - if (status) - return status; - } + status = cairo_font_options_status ((cairo_font_options_t *) options); + if (status) + return status; return _cairo_font_face_set_error (&font_face->base, backend->create_toy (font_face, diff --git a/src/cairo-font-options.c b/src/cairo-font-options.c index f9a10590b..c49603e92 100644 --- a/src/cairo-font-options.c +++ b/src/cairo-font-options.c @@ -52,9 +52,6 @@ static const cairo_font_options_t _cairo_font_options_nil = { void _cairo_font_options_init_default (cairo_font_options_t *options) { - if (cairo_font_options_status (options)) - return; - options->antialias = CAIRO_ANTIALIAS_DEFAULT; options->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; options->hint_style = CAIRO_HINT_STYLE_DEFAULT; @@ -65,13 +62,10 @@ void _cairo_font_options_init_copy (cairo_font_options_t *options, const cairo_font_options_t *other) { - if (other != NULL) { - options->antialias = other->antialias; - options->subpixel_order = other->subpixel_order; - options->hint_style = other->hint_style; - options->hint_metrics = other->hint_metrics; - } else - _cairo_font_options_init_default (options); + options->antialias = other->antialias; + options->subpixel_order = other->subpixel_order; + options->hint_style = other->hint_style; + options->hint_metrics = other->hint_metrics; } /** @@ -121,11 +115,8 @@ cairo_font_options_copy (const cairo_font_options_t *original) { cairo_font_options_t *options; - if (original != NULL && - cairo_font_options_status ((cairo_font_options_t *) original)) - { + if (cairo_font_options_status ((cairo_font_options_t *) original)) return (cairo_font_options_t *) &_cairo_font_options_nil; - } options = malloc (sizeof (cairo_font_options_t)); if (!options) { @@ -193,7 +184,6 @@ cairo_font_options_merge (cairo_font_options_t *options, if (cairo_font_options_status (options)) return; - /* A NULL other maps to the defaults and would not overwrite options */ if (cairo_font_options_status ((cairo_font_options_t *) other)) return; @@ -215,16 +205,18 @@ slim_hidden_def (cairo_font_options_merge); * * Compares two font options objects for equality. * - * Return value: %TRUE if all fields of the two font options objects match + * Return value: %TRUE if all fields of the two font options objects match. + * Note that this function will return %FALSE is either object is in + * error. **/ cairo_bool_t cairo_font_options_equal (const cairo_font_options_t *options, const cairo_font_options_t *other) { - if (options == NULL) - options = &_cairo_font_options_nil; - if (other == NULL) - other = &_cairo_font_options_nil; + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return FALSE; + if (cairo_font_options_status ((cairo_font_options_t *) other)) + return FALSE; if (options == other) return TRUE; @@ -251,8 +243,8 @@ slim_hidden_def (cairo_font_options_equal); unsigned long cairo_font_options_hash (const cairo_font_options_t *options) { - if (options == NULL) - options = &_cairo_font_options_nil; + if (cairo_font_options_status ((cairo_font_options_t *) options)) + options = &_cairo_font_options_nil; /* force default values */ return ((options->antialias) | (options->subpixel_order << 4) | diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c index 6f3a29f2c..504f4b138 100644 --- a/src/cairo-ft-font.c +++ b/src/cairo-ft-font.c @@ -1661,11 +1661,9 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t *toy_face, goto FREE_PATTERN; } - if (font_options != NULL) { - status = _cairo_ft_font_options_substitute (font_options, pattern); - if (status) - goto FREE_PATTERN; - } + status = _cairo_ft_font_options_substitute (font_options, pattern); + if (status) + goto FREE_PATTERN; FcDefaultSubstitute (pattern); diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index 1e532bc8c..8d79648f4 100644 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -466,11 +466,9 @@ _cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, { cairo_status_t status; - if (options != NULL) { - status = cairo_font_options_status ((cairo_font_options_t *) options); - if (status) - return status; - } + status = cairo_font_options_status ((cairo_font_options_t *) options); + if (status) + return status; _cairo_scaled_font_init_key (scaled_font, font_face, font_matrix, ctm, options); @@ -625,11 +623,8 @@ cairo_scaled_font_create (cairo_font_face_t *font_face, if (font_face->status) return (cairo_scaled_font_t *)&_cairo_scaled_font_nil; - if (options != NULL && - cairo_font_options_status ((cairo_font_options_t *) options)) - { + if (cairo_font_options_status ((cairo_font_options_t *) options)) return (cairo_scaled_font_t *)&_cairo_scaled_font_nil; - } /* Note that degenerate ctm or font_matrix *are* allowed. * We want to support a font size of 0. */ diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c index 34c273613..b560b48e6 100644 --- a/src/cairo-win32-font.c +++ b/src/cairo-win32-font.c @@ -277,7 +277,7 @@ _win32_scaled_font_create (LOGFONTW *logfont, * XXX: The other option we could pay attention to, but don't * here is the hint_metrics options. */ - if (options == NULL || options->antialias == CAIRO_ANTIALIAS_DEFAULT) + if (options->antialias == CAIRO_ANTIALIAS_DEFAULT) f->quality = _get_system_quality (); else { switch (options->antialias) { @@ -304,7 +304,7 @@ _win32_scaled_font_create (LOGFONTW *logfont, if (f->quality == logfont->lfQuality || (logfont->lfQuality == DEFAULT_QUALITY && - (options == NULL || options->antialias == CAIRO_ANTIALIAS_DEFAULT))) { + options->antialias == CAIRO_ANTIALIAS_DEFAULT)) { /* If face_hfont is non-NULL, then we can use it to avoid creating our * own --- because the constraints on face_hfont mentioned above * guarantee it was created in exactly the same way that diff --git a/src/cairo.c b/src/cairo.c index fd65a34f8..ebb660393 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -2764,12 +2764,10 @@ cairo_set_font_options (cairo_t *cr, if (cr->status) return; - if (options != NULL) { - status = cairo_font_options_status ((cairo_font_options_t *) options); - if (status) { - _cairo_set_error (cr, status); - return; - } + status = cairo_font_options_status ((cairo_font_options_t *) options); + if (status) { + _cairo_set_error (cr, status); + return; } _cairo_gstate_set_font_options (cr->gstate, options); |