summaryrefslogtreecommitdiff
path: root/src/cairo-font-options.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-02-11 14:58:21 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-02-15 13:50:42 +0000
commitad265cc9f26a20f2336747d69b28bc6ca0d91f4b (patch)
tree879b767e5d236214405704c56760acea25c5fa5d /src/cairo-font-options.c
parent790eaef71cbd30e1994c9499ab553f2ef5e5d620 (diff)
downloadcairo-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/cairo-font-options.c')
-rw-r--r--src/cairo-font-options.c36
1 files changed, 14 insertions, 22 deletions
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) |