[cairo] [PATCH 2/5] Move calculation of slope outside of
_cairo_stroker_add_sub_edge.
Jeff Muizelaar
jeff at infidigm.net
Sun Apr 9 20:10:59 PDT 2006
This makes the slope calculation more accurate for dashed lines by computing it
once for the entire line instead for each individual dash segment. It also
adjusts stroker_line_to() to match the new convention for
stroker_add_sub_edge().
---
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index 36cfcc6..633b048 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -548,11 +548,11 @@ _compute_face (cairo_point_t *point, cai
static cairo_status_t
_cairo_stroker_add_sub_edge (cairo_stroker_t *stroker, cairo_point_t *p1, cairo_point_t *p2,
- cairo_stroke_face_t *start, cairo_stroke_face_t *end)
+ cairo_slope_t *slope, cairo_stroke_face_t *start,
+ cairo_stroke_face_t *end)
{
cairo_status_t status;
cairo_polygon_t polygon;
- cairo_slope_t slope;
if (p1->x == p2->x && p1->y == p2->y) {
/* XXX: Need to rethink how this case should be handled, (both
@@ -561,13 +561,12 @@ _cairo_stroker_add_sub_edge (cairo_strok
return CAIRO_STATUS_SUCCESS;
}
- _cairo_slope_init (&slope, p1, p2);
- _compute_face (p1, &slope, stroker, start);
+ _compute_face (p1, slope, stroker, start);
/* XXX: This could be optimized slightly by not calling
_compute_face again but rather translating the relevant
fields from start. */
- _compute_face (p2, &slope, stroker, end);
+ _compute_face (p2, slope, stroker, end);
/* XXX: I should really check the return value of the
move_to/line_to functions here to catch out of memory
@@ -623,6 +622,7 @@ _cairo_stroker_line_to (void *closure, c
cairo_stroke_face_t start, end;
cairo_point_t *p1 = &stroker->current_point;
cairo_point_t *p2 = point;
+ cairo_slope_t slope;
if (!stroker->has_current_point)
return _cairo_stroker_move_to (stroker, point);
@@ -634,8 +634,10 @@ _cairo_stroker_line_to (void *closure, c
as possible. */
return CAIRO_STATUS_SUCCESS;
}
+
+ _cairo_slope_init (&slope, p1, p2);
- status = _cairo_stroker_add_sub_edge (stroker, p1, p2, &start, &end);
+ status = _cairo_stroker_add_sub_edge (stroker, p1, p2, &slope, &start, &end);
if (status)
return status;
@@ -673,6 +675,7 @@ _cairo_stroker_line_to_dashed (void *clo
cairo_stroke_face_t sub_start, sub_end;
cairo_point_t *p1 = &stroker->current_point;
cairo_point_t *p2 = point;
+ cairo_slope_t slope;
if (!stroker->has_current_point)
return _cairo_stroker_move_to (stroker, point);
@@ -684,6 +687,8 @@ _cairo_stroker_line_to_dashed (void *clo
as possible. */
return CAIRO_STATUS_SUCCESS;
}
+
+ _cairo_slope_init (&slope, p1, p2);
dx = _cairo_fixed_to_double (p2->x - p1->x);
dy = _cairo_fixed_to_double (p2->y - p1->y);
@@ -709,7 +714,7 @@ _cairo_stroker_line_to_dashed (void *clo
* XXX simplify this case analysis
*/
if (stroker->dash_on) {
- status = _cairo_stroker_add_sub_edge (stroker, &fd1, &fd2, &sub_start, &sub_end);
+ status = _cairo_stroker_add_sub_edge (stroker, &fd1, &fd2, &slope, &sub_start, &sub_end);
if (status)
return status;
if (!first) {
More information about the cairo
mailing list