diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-12-09 20:15:34 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-12-12 11:11:48 +0000 |
commit | 68b29cafa597128e7cae86608e04ecae6070dad9 (patch) | |
tree | 853187df50aa7d02492914ba6a574b2d854fe9ab /src | |
parent | 2f3905dec38a710234aba30e1983b80ea3066a50 (diff) |
[spline] Propagate errors during add point.
Yikes! The callback could fail so we need to propagate the error status.
Diffstat (limited to 'src')
-rw-r--r-- | src/cairo-path-fill.c | 11 | ||||
-rw-r--r-- | src/cairo-path-fixed.c | 7 | ||||
-rw-r--r-- | src/cairo-path-in-fill.c | 7 | ||||
-rw-r--r-- | src/cairo-path-stroke.c | 14 | ||||
-rw-r--r-- | src/cairo-pen.c | 23 | ||||
-rw-r--r-- | src/cairo-spline.c | 40 | ||||
-rw-r--r-- | src/cairo-types-private.h | 6 | ||||
-rw-r--r-- | src/cairoint.h | 9 |
8 files changed, 52 insertions, 65 deletions
diff --git a/src/cairo-path-fill.c b/src/cairo-path-fill.c index 7af91d20..089232d4 100644 --- a/src/cairo-path-fill.c +++ b/src/cairo-path-fill.c @@ -122,19 +122,14 @@ _cairo_filler_curve_to (void *closure, cairo_spline_t spline; if (! _cairo_spline_init (&spline, - (cairo_add_point_func_t) _cairo_polygon_line_to, - &filler->polygon, + _cairo_filler_line_to, + filler, &filler->current_point, b, c, d)) { return CAIRO_STATUS_SUCCESS; } - _cairo_spline_decompose (&spline, filler->tolerance); - _cairo_spline_fini (&spline); - - filler->current_point = *d; - - return CAIRO_STATUS_SUCCESS; + return _cairo_spline_decompose (&spline, filler->tolerance); } static cairo_status_t diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c index dd25bb88..d423a167 100644 --- a/src/cairo-path-fixed.c +++ b/src/cairo-path-fixed.c @@ -895,19 +895,16 @@ _cpf_curve_to (void *closure, cairo_point_t *p0 = &cpf->current_point; if (! _cairo_spline_init (&spline, - (cairo_add_point_func_t) cpf->line_to, + cpf->line_to, cpf->closure, p0, p1, p2, p3)) { return CAIRO_STATUS_SUCCESS; } - _cairo_spline_decompose (&spline, cpf->tolerance); - _cairo_spline_fini (&spline); - cpf->current_point = *p3; - return CAIRO_STATUS_SUCCESS; + return _cairo_spline_decompose (&spline, cpf->tolerance); } static cairo_status_t diff --git a/src/cairo-path-in-fill.c b/src/cairo-path-in-fill.c index 0362bfb6..f7785e85 100644 --- a/src/cairo-path-in-fill.c +++ b/src/cairo-path-in-fill.c @@ -194,17 +194,14 @@ _cairo_in_fill_curve_to (void *closure, /* XXX Investigate direct inspection of the inflections? */ if (! _cairo_spline_init (&spline, - (cairo_add_point_func_t) _cairo_in_fill_line_to, + _cairo_in_fill_line_to, in_fill, &in_fill->current_point, b, c, d)) { return CAIRO_STATUS_SUCCESS; } - _cairo_spline_decompose (&spline, in_fill->tolerance); - _cairo_spline_fini (&spline); - - return CAIRO_STATUS_SUCCESS; + return _cairo_spline_decompose (&spline, in_fill->tolerance); } static cairo_status_t diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c index 8c3064ea..8d3a1a93 100644 --- a/src/cairo-path-stroke.c +++ b/src/cairo-path-stroke.c @@ -1080,11 +1080,12 @@ _cairo_stroker_curve_to_dashed (void *closure, cairo_spline_t spline; cairo_point_t *a = &stroker->current_point; cairo_line_join_t line_join_save; + cairo_status_t status; if (! _cairo_spline_init (&spline, stroker->dashed ? - (cairo_add_point_func_t) _cairo_stroker_line_to_dashed : - (cairo_add_point_func_t) _cairo_stroker_line_to, + _cairo_stroker_line_to_dashed : + _cairo_stroker_line_to, stroker, a, b, c, d)) { @@ -1094,21 +1095,18 @@ _cairo_stroker_curve_to_dashed (void *closure, /* If the line width is so small that the pen is reduced to a single point, then we have nothing to do. */ if (stroker->pen.num_vertices <= 1) - goto CLEANUP_SPLINE; + return CAIRO_STATUS_SUCCESS; /* Temporarily modify the stroker to use round joins to guarantee * smooth stroked curves. */ line_join_save = stroker->style->line_join; stroker->style->line_join = CAIRO_LINE_JOIN_ROUND; - _cairo_spline_decompose (&spline, stroker->tolerance); + status = _cairo_spline_decompose (&spline, stroker->tolerance); stroker->style->line_join = line_join_save; - CLEANUP_SPLINE: - _cairo_spline_fini (&spline); - - return CAIRO_STATUS_SUCCESS; + return status; } static cairo_status_t diff --git a/src/cairo-pen.c b/src/cairo-pen.c index 4158f175..a7576e1a 100644 --- a/src/cairo-pen.c +++ b/src/cairo-pen.c @@ -465,7 +465,9 @@ _cairo_pen_stroke_spline (cairo_pen_stroke_spline_t *stroker, &stroker->forward_hull_point, 1); - _cairo_spline_decompose (&stroker->spline, tolerance); + status = _cairo_spline_decompose (&stroker->spline, tolerance); + if (unlikely (status)) + return status; /* close the polygon */ slope = stroker->spline.final_slope; @@ -492,20 +494,20 @@ _cairo_pen_stroke_spline (cairo_pen_stroke_spline_t *stroker, status = _cairo_polygon_status (&stroker->polygon); if (unlikely (status)) - goto BAIL; + return status; status = _cairo_bentley_ottmann_tessellate_polygon (traps, &stroker->polygon, CAIRO_FILL_RULE_WINDING); -BAIL: return status; } -static void -_cairo_pen_stroke_spline_add_point (cairo_pen_stroke_spline_t *stroker, - const cairo_point_t *point) +static cairo_status_t +_cairo_pen_stroke_spline_add_point (void *closure, + cairo_point_t *point) { + cairo_pen_stroke_spline_t *stroker = closure; cairo_slope_t slope; _cairo_slope_init (&slope, &stroker->last_point, point); @@ -527,6 +529,8 @@ _cairo_pen_stroke_spline_add_point (cairo_pen_stroke_spline_t *stroker, stroker->backward_vertex, -1); stroker->last_point = *point; + + return CAIRO_STATUS_SUCCESS; } cairo_int_status_t @@ -540,7 +544,7 @@ _cairo_pen_stroke_spline_init (cairo_pen_stroke_spline_t *stroker, cairo_int_status_t status; if (! _cairo_spline_init (&stroker->spline, - (cairo_add_point_func_t) _cairo_pen_stroke_spline_add_point, + _cairo_pen_stroke_spline_add_point, stroker, a, b, c, d)) { @@ -548,10 +552,8 @@ _cairo_pen_stroke_spline_init (cairo_pen_stroke_spline_t *stroker, } status = _cairo_pen_init_copy (&stroker->pen, pen); - if (unlikely (status)) { - _cairo_spline_fini (&stroker->spline); + if (unlikely (status)) return status; - } _cairo_polygon_init (&stroker->polygon); @@ -564,6 +566,5 @@ void _cairo_pen_stroke_spline_fini (cairo_pen_stroke_spline_t *stroker) { _cairo_polygon_fini (&stroker->polygon); - _cairo_spline_fini (&stroker->spline); _cairo_pen_fini (&stroker->pen); } diff --git a/src/cairo-spline.c b/src/cairo-spline.c index b5285447..7e794cf5 100644 --- a/src/cairo-spline.c +++ b/src/cairo-spline.c @@ -38,7 +38,7 @@ cairo_bool_t _cairo_spline_init (cairo_spline_t *spline, - void (*add_point_func) (void*, const cairo_point_t *), + cairo_spline_add_point_func_t add_point_func, void *closure, const cairo_point_t *a, const cairo_point_t *b, const cairo_point_t *c, const cairo_point_t *d) @@ -70,22 +70,17 @@ _cairo_spline_init (cairo_spline_t *spline, return TRUE; } -void -_cairo_spline_fini (cairo_spline_t *spline) -{ -} - -static void -_cairo_spline_add_point (cairo_spline_t *spline, const cairo_point_t *point) +static cairo_status_t +_cairo_spline_add_point (cairo_spline_t *spline, cairo_point_t *point) { cairo_point_t *prev; prev = &spline->last_point; if (prev->x == point->x && prev->y == point->y) - return; + return CAIRO_STATUS_SUCCESS; - spline->add_point_func (spline->closure, point); spline->last_point = *point; + return spline->add_point_func (spline->closure, point); } static void @@ -181,30 +176,35 @@ _cairo_spline_error_squared (const cairo_spline_knots_t *knots) return cerr; } -static void +static cairo_status_t _cairo_spline_decompose_into (cairo_spline_knots_t *s1, double tolerance_squared, cairo_spline_t *result) { cairo_spline_knots_t s2; + cairo_status_t status; - if (_cairo_spline_error_squared (s1) < tolerance_squared) { - _cairo_spline_add_point (result, &s1->a); - return; - } + if (_cairo_spline_error_squared (s1) < tolerance_squared) + return _cairo_spline_add_point (result, &s1->a); _de_casteljau (s1, &s2); - _cairo_spline_decompose_into (s1, tolerance_squared, result); - _cairo_spline_decompose_into (&s2, tolerance_squared, result); + status = _cairo_spline_decompose_into (s1, tolerance_squared, result); + if (unlikely (status)) + return status; + + return _cairo_spline_decompose_into (&s2, tolerance_squared, result); } -void +cairo_status_t _cairo_spline_decompose (cairo_spline_t *spline, double tolerance) { cairo_spline_knots_t s1; + cairo_status_t status; s1 = spline->knots; spline->last_point = s1.a; - _cairo_spline_decompose_into (&s1, tolerance * tolerance, spline); + status = _cairo_spline_decompose_into (&s1, tolerance * tolerance, spline); + if (unlikely (status)) + return status; - _cairo_spline_add_point (spline, &spline->knots.d); + return _cairo_spline_add_point (spline, &spline->knots.d); } diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h index d8d5a2c0..f4d726d6 100644 --- a/src/cairo-types-private.h +++ b/src/cairo-types-private.h @@ -305,11 +305,15 @@ typedef struct _cairo_polygon { cairo_edge_t edges_embedded[32]; } cairo_polygon_t; +typedef cairo_status_t +(*cairo_spline_add_point_func_t) (void *closure, cairo_point_t *point); + typedef struct _cairo_spline_knots { cairo_point_t a, b, c, d; } cairo_spline_knots_t; + typedef struct _cairo_spline { - void (*add_point_func) (void *, const cairo_point_t *); + cairo_spline_add_point_func_t add_point_func; void *closure; cairo_spline_knots_t knots; diff --git a/src/cairoint.h b/src/cairoint.h index f5d5f94d..2c0e8662 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -2245,21 +2245,16 @@ _cairo_polygon_close (cairo_polygon_t *polygon); #define _cairo_polygon_status(P) (P)->status /* cairo-spline.c */ -typedef void (*cairo_add_point_func_t) (void*, const cairo_point_t *); - cairo_private cairo_bool_t _cairo_spline_init (cairo_spline_t *spline, - cairo_add_point_func_t add_point_func, + cairo_spline_add_point_func_t add_point_func, void *closure, const cairo_point_t *a, const cairo_point_t *b, const cairo_point_t *c, const cairo_point_t *d); -cairo_private void +cairo_private cairo_status_t _cairo_spline_decompose (cairo_spline_t *spline, double tolerance); -cairo_private void -_cairo_spline_fini (cairo_spline_t *spline); - /* cairo-matrix.c */ cairo_private void _cairo_matrix_get_affine (const cairo_matrix_t *matrix, |