diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-01-17 22:31:05 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-01-17 22:38:02 +0000 |
commit | 0086db893cba90dc73824d77c661d2965ad48112 (patch) | |
tree | 4b7ef3959d890c2e7956fce9ec9af160efcbd688 /src/cairo-font-options.c | |
parent | 02d0e070638f668bf50a8ce2174c21e5614dd6c4 (diff) | |
download | cairo-0086db893cba90dc73824d77c661d2965ad48112.tar.gz |
[cairo-font-options] Treat NULL as a default cairo_font_options_t
Interpret a NULL cairo_font_options_t as the default values - i.e
as if it were a fresh pointer returned by cairo_font_options_create().
Diffstat (limited to 'src/cairo-font-options.c')
-rw-r--r-- | src/cairo-font-options.c | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/src/cairo-font-options.c b/src/cairo-font-options.c index a2cce35e1..700579038 100644 --- a/src/cairo-font-options.c +++ b/src/cairo-font-options.c @@ -65,10 +65,13 @@ void _cairo_font_options_init_copy (cairo_font_options_t *options, const cairo_font_options_t *other) { - options->antialias = other->antialias; - options->subpixel_order = other->subpixel_order; - options->hint_style = other->hint_style; - options->hint_metrics = other->hint_metrics; + 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); } /** @@ -91,7 +94,7 @@ cairo_font_options_create (void) options = malloc (sizeof (cairo_font_options_t)); if (!options) { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_options_t *)&_cairo_font_options_nil; + return (cairo_font_options_t *) &_cairo_font_options_nil; } _cairo_font_options_init_default (options); @@ -118,13 +121,16 @@ cairo_font_options_copy (const cairo_font_options_t *original) { cairo_font_options_t *options; - if (cairo_font_options_status ((cairo_font_options_t *) original)) - return (cairo_font_options_t *)&_cairo_font_options_nil; + if (original != NULL && + 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) { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_options_t *)&_cairo_font_options_nil; + return (cairo_font_options_t *) &_cairo_font_options_nil; } _cairo_font_options_init_copy (options, original); @@ -163,7 +169,7 @@ cairo_font_options_status (cairo_font_options_t *options) { if (options == NULL) return CAIRO_STATUS_NULL_POINTER; - else if (options == (cairo_font_options_t *)&_cairo_font_options_nil) + else if (options == (cairo_font_options_t *) &_cairo_font_options_nil) return CAIRO_STATUS_NO_MEMORY; else return CAIRO_STATUS_SUCCESS; @@ -187,6 +193,10 @@ 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; + if (other->antialias != CAIRO_ANTIALIAS_DEFAULT) options->antialias = other->antialias; if (other->subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) @@ -211,6 +221,14 @@ 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 (options == other) + return TRUE; + return (options->antialias == other->antialias && options->subpixel_order == other->subpixel_order && options->hint_style == other->hint_style && @@ -233,6 +251,9 @@ 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; + return ((options->antialias) | (options->subpixel_order << 4) | (options->hint_style << 8) | @@ -270,6 +291,9 @@ slim_hidden_def (cairo_font_options_set_antialias); cairo_antialias_t cairo_font_options_get_antialias (const cairo_font_options_t *options) { + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_ANTIALIAS_DEFAULT; + return options->antialias; } @@ -307,6 +331,9 @@ slim_hidden_def (cairo_font_options_set_subpixel_order); cairo_subpixel_order_t cairo_font_options_get_subpixel_order (const cairo_font_options_t *options) { + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_SUBPIXEL_ORDER_DEFAULT; + return options->subpixel_order; } @@ -343,6 +370,9 @@ slim_hidden_def (cairo_font_options_set_hint_style); cairo_hint_style_t cairo_font_options_get_hint_style (const cairo_font_options_t *options) { + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_HINT_STYLE_DEFAULT; + return options->hint_style; } @@ -379,5 +409,8 @@ slim_hidden_def (cairo_font_options_set_hint_metrics); cairo_hint_metrics_t cairo_font_options_get_hint_metrics (const cairo_font_options_t *options) { + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_HINT_METRICS_DEFAULT; + return options->hint_metrics; } |