diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2012-08-26 10:50:50 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2012-08-26 11:14:17 +0100 |
commit | 99593538a9d054aa1bb9fa620fced8c8b8ccdc9d (patch) | |
tree | 8ad257e226e238f208b6faab813c43cc1ebdd1ae | |
parent | 4eb8e9f8618c5c5c002b7fd72c0370451ae1f511 (diff) |
stroke: Convert fallback stroker to new pen vertex finder
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | src/cairo-path-stroke.c | 173 |
1 files changed, 95 insertions, 78 deletions
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c index bae66dca..8f9fa92f 100644 --- a/src/cairo-path-stroke.c +++ b/src/cairo-path-stroke.c @@ -220,100 +220,117 @@ _tessellate_fan (cairo_stroker_t *stroker, cairo_bool_t clockwise) { cairo_point_t stack_points[64], *points = stack_points; - int start, stop, step, i, npoints; + cairo_pen_t *pen = &stroker->pen; + int start, stop, num_points = 0; cairo_status_t status; + if (stroker->has_bounds && + ! _cairo_box_contains_point (&stroker->bounds, midpt)) + goto BEVEL; + + assert (stroker->pen.num_vertices); + if (clockwise) { - step = -1; - - start = _cairo_pen_find_active_ccw_vertex_index (&stroker->pen, - in_vector); - if (_cairo_slope_compare (&stroker->pen.vertices[start].slope_ccw, - in_vector) < 0) - start = _range_step (start, -1, stroker->pen.num_vertices); - - stop = _cairo_pen_find_active_ccw_vertex_index (&stroker->pen, - out_vector); - if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_cw, - out_vector) > 0) - { - stop = _range_step (stop, 1, stroker->pen.num_vertices); - if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_ccw, - in_vector) < 0) - { - goto BEVEL; - } - } + _cairo_pen_find_active_ccw_vertices (pen, + in_vector, out_vector, + &start, &stop); + if (stroker->add_external_edge) { + cairo_point_t last; + last = *inpt; + while (start != stop) { + cairo_point_t p = *midpt; + _translate_point (&p, &pen->vertices[start].point); - npoints = start - stop; - } else { - step = 1; - - start = _cairo_pen_find_active_cw_vertex_index (&stroker->pen, - in_vector); - if (_cairo_slope_compare (&stroker->pen.vertices[start].slope_cw, - in_vector) < 0) - start = _range_step (start, 1, stroker->pen.num_vertices); - - stop = _cairo_pen_find_active_cw_vertex_index (&stroker->pen, - out_vector); - if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_ccw, - out_vector) > 0) - { - stop = _range_step (stop, -1, stroker->pen.num_vertices); - if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_cw, - in_vector) < 0) - { + status = stroker->add_external_edge (stroker->closure, + &last, &p); + if (unlikely (status)) + return status; + last = p; + + if (start-- == 0) + start += pen->num_vertices; + } + status = stroker->add_external_edge (stroker->closure, + &last, outpt); + } else { + if (start == stop) goto BEVEL; + + num_points = stop - start; + if (num_points < 0) + num_points += pen->num_vertices; + num_points += 2; + if (num_points > ARRAY_LENGTH(stack_points)) { + points = _cairo_malloc_ab (num_points, sizeof (cairo_point_t)); + if (unlikely (points == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); } - } - npoints = stop - start; - } - stop = _range_step (stop, step, stroker->pen.num_vertices); + points[0] = *inpt; + num_points = 1; + while (start != stop) { + points[num_points] = *midpt; + _translate_point (&points[num_points], &pen->vertices[start].point); + num_points++; - if (npoints < 0) - npoints += stroker->pen.num_vertices; - npoints += 3; + if (start-- == 0) + start += pen->num_vertices; + } + points[num_points++] = *outpt; + } + } else { + _cairo_pen_find_active_cw_vertices (pen, + in_vector, out_vector, + &start, &stop); + if (stroker->add_external_edge) { + cairo_point_t last; + last = *inpt; + while (start != stop) { + cairo_point_t p = *midpt; + _translate_point (&p, &pen->vertices[start].point); - if (npoints <= 1) - goto BEVEL; + status = stroker->add_external_edge (stroker->closure, + &p, &last); + if (unlikely (status)) + return status; + last = p; - if (npoints > ARRAY_LENGTH (stack_points)) { - points = _cairo_malloc_ab (npoints, sizeof (cairo_point_t)); - if (unlikely (points == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } + if (++start == pen->num_vertices) + start = 0; + } + status = stroker->add_external_edge (stroker->closure, + outpt, &last); + } else { + if (start == stop) + goto BEVEL; + num_points = stop - start; + if (num_points < 0) + num_points += pen->num_vertices; + num_points += 2; + if (num_points > ARRAY_LENGTH(stack_points)) { + points = _cairo_malloc_ab (num_points, sizeof (cairo_point_t)); + if (unlikely (points == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } - /* Construct the fan. */ - npoints = 0; - points[npoints++] = *inpt; - for (i = start; - i != stop; - i = _range_step (i, step, stroker->pen.num_vertices)) - { - points[npoints] = *midpt; - _translate_point (&points[npoints], &stroker->pen.vertices[i].point); - npoints++; - } - points[npoints++] = *outpt; + points[0] = *inpt; + num_points = 1; + while (start != stop) { + points[num_points] = *midpt; + _translate_point (&points[num_points], &pen->vertices[start].point); + num_points++; - if (stroker->add_external_edge != NULL) { - for (i = 0; i < npoints - 1; i++) { - if (clockwise) { - status = stroker->add_external_edge (stroker->closure, - &points[i], &points[i+1]); - } else { - status = stroker->add_external_edge (stroker->closure, - &points[i+1], &points[i]); + if (++start == pen->num_vertices) + start = 0; } - if (unlikely (status)) - break; + points[num_points++] = *outpt; } - } else { + } + + if (num_points) { status = stroker->add_triangle_fan (stroker->closure, - midpt, points, npoints); + midpt, points, num_points); } if (points != stack_points) |