diff options
author | Andrea Canciani <ranma42@gmail.com> | 2010-06-01 19:40:14 +0200 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2010-06-10 16:07:42 +0200 |
commit | 06c6207ad4205f211be70e324c6d32ea7d28dca8 (patch) | |
tree | 195943a09f3f5c1ca47d1f4ea7372d0087e0a0c9 /src | |
parent | 561625ee3bd2732457eaaf28937edf557ee7661d (diff) |
pattern: add gradient_is_solid function
It contains in a single place the logic needed to check if a gradient
pattern is solid (within a specified region).
Diffstat (limited to 'src')
-rw-r--r-- | src/cairo-pattern.c | 53 | ||||
-rw-r--r-- | src/cairoint.h | 5 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 2aa80d5e..319101f6 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -1790,6 +1790,59 @@ _gradient_is_clear (const cairo_gradient_pattern_t *gradient, } /** + * _cairo_gradient_pattern_is_solid + * + * Convenience function to determine whether a gradient pattern is + * a solid color within the given extents. In this case the color + * argument is initialized to the color the pattern represents. + * This functions doesn't handle completely transparent gradients, + * thus it should be called only after _cairo_pattern_is_clear has + * returned FALSE. + * + * Return value: %TRUE if the pattern is a solid color. + **/ +cairo_bool_t +_cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient, + const cairo_rectangle_int_t *extents, + cairo_color_t *color) +{ + unsigned int i; + + /* TODO: radial, degenerate linear */ + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + if (gradient->base.extend == CAIRO_EXTEND_NONE) { + cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; + double t[2]; + + /* We already know that the pattern is not clear, thus if some + * part of it is clear, the whole is not solid. + */ + + if (extents == NULL) + return FALSE; + + _extents_to_linear_parameter (linear, extents, t); + if (t[0] < 0.0 || t[1] > 1.0) + return FALSE; + } + } else + return FALSE; + + for (i = 1; i < gradient->n_stops; i++) + if (! _cairo_color_stop_equal (&gradient->stops[0].color, + &gradient->stops[i].color)) + return FALSE; + + _cairo_color_init_rgba (color, + gradient->stops[0].color.red, + gradient->stops[0].color.green, + gradient->stops[0].color.blue, + gradient->stops[0].color.alpha); + + return TRUE; +} + +/** * _cairo_pattern_is_opaque_solid * * Convenience function to determine whether a pattern is an opaque diff --git a/src/cairoint.h b/src/cairoint.h index 59af6844..b7c072d2 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -2216,6 +2216,11 @@ _cairo_pattern_transform (cairo_pattern_t *pattern, const cairo_matrix_t *ctm_inverse); cairo_private cairo_bool_t +_cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient, + const cairo_rectangle_int_t *extents, + cairo_color_t *color); + +cairo_private cairo_bool_t _cairo_pattern_is_opaque_solid (const cairo_pattern_t *pattern); cairo_private cairo_bool_t |