[cairo-commit] 5 commits - src/cairo-atsui-font.c src/cairoint.h src/cairo-path-stroke.c src/cairo-rectangle.c src/cairo-traps.c test/dash-scale-ref.png test/Makefile.am

Vladimir Vukicevic vladimir at kemper.freedesktop.org
Tue Feb 5 15:06:14 PST 2008


 src/cairo-atsui-font.c  |   11 ++
 src/cairo-path-stroke.c |  260 +++++++++++++++++++++++++++++++-----------------
 src/cairo-rectangle.c   |   94 +++++++++++++++++
 src/cairo-traps.c       |    8 +
 src/cairoint.h          |   10 +
 test/Makefile.am        |    1 
 test/dash-scale-ref.png |binary
 7 files changed, 291 insertions(+), 93 deletions(-)

New commits:
commit 7b788ce7cace4fd24c568248c22b4ec6c88b563b
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Tue Feb 5 15:04:38 2008 -0800

    Update test ref images that changed with stroking changes

diff --git a/test/dash-scale-ref.png b/test/dash-scale-ref.png
index 60aab2f..e90e09a 100644
Binary files a/test/dash-scale-ref.png and b/test/dash-scale-ref.png differ
commit 4471e58c12c20723f1ddac3d0284239be6eb27a8
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Mon Feb 4 03:55:55 2008 -0800

    Optimize dashed strokes, part 2
    
    Pass down the bounding box to the stroker, and avoid doing expensive
    calculations for dash segments that are outside the box.

diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index 305f43f..71510b1 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -67,6 +67,9 @@ typedef struct cairo_stroker {
     cairo_bool_t dash_on;
     cairo_bool_t dash_starts_on;
     double dash_remain;
+
+    cairo_bool_t has_bounds;
+    cairo_box_t bounds;
 } cairo_stroker_t;
 
 /* private functions */
@@ -187,6 +190,34 @@ _cairo_stroker_init (cairo_stroker_t		*stroker,
     else
 	stroker->dashed = FALSE;
 
+    stroker->has_bounds = _cairo_traps_get_limit (traps, &stroker->bounds);
+    if (stroker->has_bounds) {
+	/* Extend the bounds by the line width in each direction so that we correctly
+	 * capture segment endcaps and other similar renderings that would extend beyond
+	 * the segment itself.
+	 */
+	double width_x = stroker->style->line_width;
+	double width_y = stroker->style->line_width;
+
+	cairo_fixed_t fixed_x, fixed_y;
+
+	if (stroke_style->line_join == CAIRO_LINE_JOIN_MITER) {
+	    width_x *= stroker->style->miter_limit;
+	    width_y *= stroker->style->miter_limit;
+	}
+
+	cairo_matrix_transform_distance (stroker->ctm, &width_x, &width_y);
+
+	fixed_x = _cairo_fixed_from_double (width_x);
+	fixed_y = _cairo_fixed_from_double (width_y);
+
+	stroker->bounds.p1.x -= fixed_x;
+	stroker->bounds.p2.x += fixed_x;
+
+	stroker->bounds.p1.y -= fixed_y;
+	stroker->bounds.p2.y += fixed_y;
+    }
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -797,16 +828,24 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
     double mag, remain, step_length = 0;
     double slope_dx, slope_dy;
     double dx2, dy2;
-    cairo_point_t fd1, fd2;
     cairo_stroke_face_t sub_start, sub_end;
     cairo_point_t *p1 = &stroker->current_point;
     cairo_point_t *p2 = point;
+    cairo_bool_t fully_in_bounds = TRUE;
+    cairo_line_t segment;
 
     stroker->has_initial_sub_path = stroker->dash_starts_on;
 
     if (p1->x == p2->x && p1->y == p2->y)
 	return CAIRO_STATUS_SUCCESS;
 
+    if (stroker->has_bounds &&
+	(!_cairo_box_contains_point (&stroker->bounds, p1) ||
+	 !_cairo_box_contains_point (&stroker->bounds, p2)))
+    {
+	fully_in_bounds = FALSE;
+    }
+
     slope_dx = _cairo_fixed_to_double (p2->x - p1->x);
     slope_dy = _cairo_fixed_to_double (p2->y - p1->y);
 
@@ -814,58 +853,63 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
 	return CAIRO_STATUS_SUCCESS;
 
     remain = mag;
-    fd1 = *p1;
+    segment.p1 = *p1;
     while (remain) {
 	step_length = MIN (stroker->dash_remain, remain);
 	remain -= step_length;
 	dx2 = slope_dx * (mag - remain);
 	dy2 = slope_dy * (mag - remain);
 	cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2);
-	fd2.x = _cairo_fixed_from_double (dx2) + p1->x;
-	fd2.y = _cairo_fixed_from_double (dy2) + p1->y;
+	segment.p2.x = _cairo_fixed_from_double (dx2) + p1->x;
+	segment.p2.y = _cairo_fixed_from_double (dy2) + p1->y;
 
-	if (stroker->dash_on) {
-	    status = _cairo_stroker_add_sub_edge (stroker, &fd1, &fd2, slope_dx, slope_dy, &sub_start, &sub_end);
-	    if (status)
-		return status;
-
-	    if (stroker->has_current_face) {
-		/* Join with final face from previous segment */
-		status = _cairo_stroker_join (stroker, &stroker->current_face, &sub_start);
-		stroker->has_current_face = FALSE;
-		if (status)
-		    return status;
-	    } else if (!stroker->has_first_face && stroker->dash_starts_on) {
-		/* Save sub path's first face in case needed for closing join */
-		stroker->first_face = sub_start;
-		stroker->has_first_face = TRUE;
-	    } else {
-		/* Cap dash start if not connecting to a previous segment */
-		status = _cairo_stroker_add_leading_cap (stroker, &sub_start);
+	if (fully_in_bounds ||
+	    _cairo_box_intersects_line (&stroker->bounds, &segment))
+	{
+	    if (stroker->dash_on) {
+		status = _cairo_stroker_add_sub_edge (stroker, &segment.p1, &segment.p2, slope_dx, slope_dy, &sub_start, &sub_end);
 		if (status)
 		    return status;
-	    }
 
-	    if (remain) {
-		/* Cap dash end if not at end of segment */
-		status = _cairo_stroker_add_trailing_cap (stroker, &sub_end);
-		if (status)
-		    return status;
+		if (stroker->has_current_face) {
+		    /* Join with final face from previous segment */
+		    status = _cairo_stroker_join (stroker, &stroker->current_face, &sub_start);
+		    stroker->has_current_face = FALSE;
+		    if (status)
+			return status;
+		} else if (!stroker->has_first_face && stroker->dash_starts_on) {
+		    /* Save sub path's first face in case needed for closing join */
+		    stroker->first_face = sub_start;
+		    stroker->has_first_face = TRUE;
+		} else {
+		    /* Cap dash start if not connecting to a previous segment */
+		    status = _cairo_stroker_add_leading_cap (stroker, &sub_start);
+		    if (status)
+			return status;
+		}
+
+		if (remain) {
+		    /* Cap dash end if not at end of segment */
+		    status = _cairo_stroker_add_trailing_cap (stroker, &sub_end);
+		    if (status)
+			return status;
+		} else {
+		    stroker->current_face = sub_end;
+		    stroker->has_current_face = TRUE;
+		}
 	    } else {
-		stroker->current_face = sub_end;
-		stroker->has_current_face = TRUE;
-	    }
-	} else {
-	    if (stroker->has_current_face) {
-		/* Cap final face from previous segment */
-		status = _cairo_stroker_add_trailing_cap (stroker, &stroker->current_face);
-		if (status)
-		    return status;
-		stroker->has_current_face = FALSE;
+		if (stroker->has_current_face) {
+		    /* Cap final face from previous segment */
+		    status = _cairo_stroker_add_trailing_cap (stroker, &stroker->current_face);
+		    if (status)
+			return status;
+		    stroker->has_current_face = FALSE;
+		}
 	    }
 	}
+
 	_cairo_stroker_step_dash (stroker, step_length);
-	fd1 = fd2;
+	segment.p1 = segment.p2;
     }
 
     if (stroker->dash_on && !stroker->has_current_face) {
diff --git a/src/cairo-rectangle.c b/src/cairo-rectangle.c
index 5c68683..58426f3 100644
--- a/src/cairo-rectangle.c
+++ b/src/cairo-rectangle.c
@@ -1,3 +1,4 @@
+/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
 /* cairo - a vector graphics library with display and print output
  *
  * Copyright © 2002 University of Southern California
@@ -83,3 +84,96 @@ _cairo_rectangle_intersect (cairo_rectangle_int_t *dest, cairo_rectangle_int_t *
 	dest->height = y2 - y1;
     }
 }
+
+
+#define P1x (line->p1.x)
+#define P1y (line->p1.y)
+#define P2x (line->p2.x)
+#define P2y (line->p2.y)
+#define B1x (box->p1.x)
+#define B1y (box->p1.y)
+#define B2x (box->p2.x)
+#define B2y (box->p2.y)
+
+/*
+ * Check whether any part of line intersects box.  This function essentially
+ * computes whether the ray starting at line->p1 in the direction of line->p2
+ * intersects the box before it reaches p2.  Normally, this is done
+ * by dividing by the lengths of the line projected onto each axis.  Because
+ * we're in fixed point, this function does a bit more work to avoid having to
+ * do the division -- we don't care about the actual intersection point, so
+ * it's of no interest to us.
+ */
+
+cairo_bool_t
+_cairo_box_intersects_line (cairo_box_t *box, cairo_line_t *line)
+{
+    cairo_fixed_t t1, t2, t3, t4;
+    cairo_int64_t t1y, t2y, t3x, t4x;
+
+    cairo_fixed_t xlen = P2x - P1x;
+    cairo_fixed_t ylen = P2y - P1y;
+
+    if (xlen) {
+	if (xlen > 0) {
+	    t1 = B1x - P1x;
+	    t2 = B2x - P1x;
+	} else {
+	    t1 = P1x - B2x;
+	    t2 = P1x - B1x;
+	    xlen = - xlen;
+	}
+
+	if ((t1 < 0 || t1 > xlen) &&
+	    (t2 < 0 || t2 > xlen))
+	    return FALSE;
+    } else {
+	/* Fully vertical line -- check that X is in bounds */
+	if (P1x < B1x || P1x > B2x)
+	    return FALSE;
+    }
+
+    if (ylen) {
+	if (ylen > 0) {
+	    t3 = B1y - P1y;
+	    t4 = B2y - P1y;
+	} else {
+	    t3 = P1y - B2y;
+	    t4 = P1y - B1y;
+	    ylen = - ylen;
+	}
+
+	if ((t3 < 0 || t3 > ylen) &&
+	    (t4 < 0 || t4 > ylen))
+	    return FALSE;
+    } else {
+	/* Fully horizontal line -- check Y */
+	if (P1y < B1y || P1y > B2y)
+	    return FALSE;
+    }
+
+    /* If we had a horizontal or vertical line, then it's already been checked */
+    if (P1x == P2x || P1y == P2y)
+	return TRUE;
+
+    /* Check overlap.  Note that t1 < t2 and t3 < t4 here. */
+    t1y = _cairo_int32x32_64_mul (t1, ylen);
+    t2y = _cairo_int32x32_64_mul (t2, ylen);
+    t3x = _cairo_int32x32_64_mul (t3, xlen);
+    t4x = _cairo_int32x32_64_mul (t4, xlen);
+
+    if (_cairo_int64_lt(t1y, t4x) &&
+	_cairo_int64_lt(t3x, t2y))
+	return TRUE;
+
+    return FALSE;
+}
+
+cairo_bool_t
+_cairo_box_contains_point (cairo_box_t *box, cairo_point_t *point)
+{
+    if (point->x < box->p1.x || point->x > box->p2.x ||
+	point->y < box->p1.y || point->y > box->p2.y)
+	return FALSE;
+    return TRUE;
+}
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index 8b009b1..8d71607 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -75,6 +75,14 @@ _cairo_traps_limit (cairo_traps_t	*traps,
     traps->limits = *limits;
 }
 
+cairo_bool_t
+_cairo_traps_get_limit (cairo_traps_t *traps,
+			cairo_box_t   *limits)
+{
+    *limits = traps->limits;
+    return traps->has_limits;
+}
+
 void
 _cairo_traps_fini (cairo_traps_t *traps)
 {
diff --git a/src/cairoint.h b/src/cairoint.h
index 13f21fb..2a1df7b 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -179,6 +179,12 @@ _cairo_box_round_to_rectangle (cairo_box_t *box, cairo_rectangle_int_t *rectangl
 cairo_private void
 _cairo_rectangle_intersect (cairo_rectangle_int_t *dest, cairo_rectangle_int_t *src);
 
+cairo_private cairo_bool_t
+_cairo_box_intersects_line (cairo_box_t *box, cairo_line_t *line);
+
+cairo_private cairo_bool_t
+_cairo_box_contains_point (cairo_box_t *box, cairo_point_t *point);
+
 /* cairo_array.c structures and functions */
 
 cairo_private void
@@ -1996,6 +2002,10 @@ cairo_private void
 _cairo_traps_limit (cairo_traps_t	*traps,
 		    cairo_box_t		*limits);
 
+cairo_private cairo_bool_t
+_cairo_traps_get_limit (cairo_traps_t *traps,
+                        cairo_box_t   *limits);
+
 cairo_private cairo_status_t
 _cairo_traps_init_box (cairo_traps_t *traps,
 		       cairo_box_t   *box);
commit afbd82671fe5ebebe5d58bef3d372312be1c5aeb
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Sat Feb 2 23:48:16 2008 -0800

    Optimize stroker by hoisting some calculations out of loops
    
    sqrt and a few other floating-point operations were being done
    repeatedly within a loop; those are now precalculated and passed
    down where needed.

diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index 5705e0a..305f43f 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -1,3 +1,4 @@
+/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
 /* cairo - a vector graphics library with display and print output
  *
  * Copyright © 2002 University of Southern California
@@ -43,6 +44,8 @@ typedef struct cairo_stroker {
     cairo_matrix_t *ctm;
     cairo_matrix_t *ctm_inverse;
     double tolerance;
+    double ctm_determinant;
+    cairo_bool_t ctm_det_positive;
 
     cairo_traps_t *traps;
 
@@ -163,6 +166,12 @@ _cairo_stroker_init (cairo_stroker_t		*stroker,
     stroker->tolerance = tolerance;
     stroker->traps = traps;
 
+    _cairo_matrix_compute_determinant (stroker->ctm, &stroker->ctm_determinant);
+    if (stroker->ctm_determinant >= 0.0)
+	stroker->ctm_det_positive = TRUE;
+    else
+	stroker->ctm_det_positive = FALSE;
+
     status = _cairo_pen_init (&stroker->pen,
 		              stroke_style->line_width / 2.0,
 			      tolerance, ctm);
@@ -553,8 +562,42 @@ _cairo_stroker_add_trailing_cap (cairo_stroker_t     *stroker,
     return _cairo_stroker_add_cap (stroker, face);
 }
 
+static inline cairo_bool_t
+_compute_normalized_device_slope (double *dx, double *dy, cairo_matrix_t *ctm_inverse, double *mag_out)
+{
+    double dx0 = *dx, dy0 = *dy;
+    double mag;
+
+    cairo_matrix_transform_distance (ctm_inverse, &dx0, &dy0);
+
+    if (dx0 == 0.0 && dy0 == 0.0) {
+	if (mag_out)
+	    *mag_out = 0.0;
+	return FALSE;
+    }
+
+    if (dx0 == 0.0) {
+	mag = dy0;
+	*dx = 0.0;
+	*dy = 1.0;
+    } else if (dy0 == 0.0) {
+	mag = dx0;
+	*dx = 1.0;
+	*dy = 0.0;
+    } else {
+	mag = sqrt (dx0 * dx0 + dy0 * dy0);
+	*dx = dx0 / mag;
+	*dy = dy0 / mag;
+    }
+
+    if (mag_out)
+	*mag_out = mag;
+
+    return TRUE;
+}
+
 static void
-_compute_face (cairo_point_t *point, cairo_slope_t *slope, cairo_stroker_t *stroker, cairo_stroke_face_t *face);
+_compute_face (cairo_point_t *point, double slope_dx, double slope_dy, cairo_stroker_t *stroker, cairo_stroke_face_t *face);
 
 static cairo_status_t
 _cairo_stroker_add_caps (cairo_stroker_t *stroker)
@@ -567,12 +610,14 @@ _cairo_stroker_add_caps (cairo_stroker_t *stroker)
 	&& stroker->style->line_cap == CAIRO_LINE_JOIN_ROUND)
     {
 	/* pick an arbitrary slope to use */
-	cairo_slope_t slope = {1, 0};
+	double dx = 1.0, dy = 0.0;
 	cairo_stroke_face_t face;
 
+	_compute_normalized_device_slope (&dx, &dy, stroker->ctm_inverse, NULL);
+
 	/* arbitrarily choose first_point
 	 * first_point and current_point should be the same */
-	_compute_face (&stroker->first_point, &slope, stroker, &face);
+	_compute_face (&stroker->first_point, dx, dy, stroker, &face);
 
 	status = _cairo_stroker_add_leading_cap (stroker, &face);
 	if (status)
@@ -598,33 +643,11 @@ _cairo_stroker_add_caps (cairo_stroker_t *stroker)
 }
 
 static void
-_compute_face (cairo_point_t *point, cairo_slope_t *slope, cairo_stroker_t *stroker, cairo_stroke_face_t *face)
+_compute_face (cairo_point_t *point, double slope_dx, double slope_dy, cairo_stroker_t *stroker, cairo_stroke_face_t *face)
 {
-    double mag, det;
-    double line_dx, line_dy;
     double face_dx, face_dy;
-    cairo_point_double_t usr_vector;
     cairo_point_t offset_ccw, offset_cw;
 
-    line_dx = _cairo_fixed_to_double (slope->dx);
-    line_dy = _cairo_fixed_to_double (slope->dy);
-
-    /* faces are normal in user space, not device space */
-    cairo_matrix_transform_distance (stroker->ctm_inverse, &line_dx, &line_dy);
-
-    mag = sqrt (line_dx * line_dx + line_dy * line_dy);
-    if (mag == 0) {
-	/* XXX: Can't compute other face points. Do we want a tag in the face for this case? */
-	return;
-    }
-
-    /* normalize to unit length */
-    line_dx /= mag;
-    line_dy /= mag;
-
-    usr_vector.x = line_dx;
-    usr_vector.y = line_dy;
-
     /*
      * rotate to get a line_width/2 vector along the face, note that
      * the vector must be rotated the right direction in device space,
@@ -632,16 +655,15 @@ _compute_face (cairo_point_t *point, cairo_slope_t *slope, cairo_stroker_t *stro
      * whether the ctm reflects or not, and that can be determined
      * by looking at the determinant of the matrix.
      */
-    _cairo_matrix_compute_determinant (stroker->ctm, &det);
-    if (det >= 0)
+    if (stroker->ctm_det_positive)
     {
-	face_dx = - line_dy * (stroker->style->line_width / 2.0);
-	face_dy = line_dx * (stroker->style->line_width / 2.0);
+	face_dx = - slope_dy * (stroker->style->line_width / 2.0);
+	face_dy = slope_dx * (stroker->style->line_width / 2.0);
     }
     else
     {
-	face_dx = line_dy * (stroker->style->line_width / 2.0);
-	face_dy = - line_dx * (stroker->style->line_width / 2.0);
+	face_dx = slope_dy * (stroker->style->line_width / 2.0);
+	face_dy = - slope_dx * (stroker->style->line_width / 2.0);
     }
 
     /* back to device space */
@@ -660,25 +682,26 @@ _compute_face (cairo_point_t *point, cairo_slope_t *slope, cairo_stroker_t *stro
     face->cw = *point;
     _translate_point (&face->cw, &offset_cw);
 
-    face->usr_vector.x = usr_vector.x;
-    face->usr_vector.y = usr_vector.y;
+    face->usr_vector.x = slope_dx;
+    face->usr_vector.y = slope_dy;
 
-    face->dev_vector = *slope;
+    face->dev_vector.dx = _cairo_fixed_from_double (slope_dx);
+    face->dev_vector.dy = _cairo_fixed_from_double (slope_dy);
 }
 
 static cairo_status_t
 _cairo_stroker_add_sub_edge (cairo_stroker_t *stroker, cairo_point_t *p1, cairo_point_t *p2,
-			     cairo_slope_t *slope, cairo_stroke_face_t *start,
+			     double slope_dx, double slope_dy, cairo_stroke_face_t *start,
 			     cairo_stroke_face_t *end)
 {
     cairo_point_t rectangle[4];
 
-    _compute_face (p1, slope, stroker, start);
+    _compute_face (p1, slope_dx, slope_dy, 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_dx, slope_dy, stroker, end);
 
     if (p1->x == p2->x && p1->y == p2->y)
 	return CAIRO_STATUS_SUCCESS;
@@ -730,16 +753,18 @@ _cairo_stroker_line_to (void *closure, cairo_point_t *point)
     cairo_stroke_face_t start, end;
     cairo_point_t *p1 = &stroker->current_point;
     cairo_point_t *p2 = point;
-    cairo_slope_t slope;
+    double slope_dx, slope_dy;
 
     stroker->has_initial_sub_path = TRUE;
 
     if (p1->x == p2->x && p1->y == p2->y)
 	return CAIRO_STATUS_SUCCESS;
 
-    _cairo_slope_init (&slope, p1, p2);
+    slope_dx = _cairo_fixed_to_double (p2->x - p1->x);
+    slope_dy = _cairo_fixed_to_double (p2->y - p1->y);
+    _compute_normalized_device_slope (&slope_dx, &slope_dy, stroker->ctm_inverse, NULL);
 
-    status = _cairo_stroker_add_sub_edge (stroker, p1, p2, &slope, &start, &end);
+    status = _cairo_stroker_add_sub_edge (stroker, p1, p2, slope_dx, slope_dy, &start, &end);
     if (status)
 	return status;
 
@@ -770,40 +795,37 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
     cairo_stroker_t *stroker = closure;
     double mag, remain, step_length = 0;
-    double dx, dy;
+    double slope_dx, slope_dy;
     double dx2, dy2;
     cairo_point_t fd1, fd2;
     cairo_stroke_face_t sub_start, sub_end;
     cairo_point_t *p1 = &stroker->current_point;
     cairo_point_t *p2 = point;
-    cairo_slope_t slope;
 
     stroker->has_initial_sub_path = stroker->dash_starts_on;
 
     if (p1->x == p2->x && p1->y == p2->y)
 	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);
+    slope_dx = _cairo_fixed_to_double (p2->x - p1->x);
+    slope_dy = _cairo_fixed_to_double (p2->y - p1->y);
 
-    cairo_matrix_transform_distance (stroker->ctm_inverse, &dx, &dy);
+    if (!_compute_normalized_device_slope (&slope_dx, &slope_dy, stroker->ctm_inverse, &mag))
+	return CAIRO_STATUS_SUCCESS;
 
-    mag = sqrt (dx * dx + dy * dy);
     remain = mag;
     fd1 = *p1;
     while (remain) {
 	step_length = MIN (stroker->dash_remain, remain);
 	remain -= step_length;
-	dx2 = dx * (mag - remain)/mag;
-	dy2 = dy * (mag - remain)/mag;
+	dx2 = slope_dx * (mag - remain);
+	dy2 = slope_dy * (mag - remain);
 	cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2);
 	fd2.x = _cairo_fixed_from_double (dx2) + p1->x;
 	fd2.y = _cairo_fixed_from_double (dy2) + p1->y;
 
 	if (stroker->dash_on) {
-	    status = _cairo_stroker_add_sub_edge (stroker, &fd1, &fd2, &slope, &sub_start, &sub_end);
+	    status = _cairo_stroker_add_sub_edge (stroker, &fd1, &fd2, slope_dx, slope_dy, &sub_start, &sub_end);
 	    if (status)
 		return status;
 
@@ -854,7 +876,7 @@ _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
 	 * in the path. Whether this behaviour is desirable or not is debatable.
 	 * On one side these degnerate caps can not be reproduced with regular path stroking.
 	 * On the other side Acroread 7 also produces the degenerate caps. */
-	_compute_face (point, &slope, stroker, &stroker->current_face);
+	_compute_face (point, slope_dx, slope_dy, stroker, &stroker->current_face);
 	stroker->has_current_face = TRUE;
 	status = _cairo_stroker_add_leading_cap (stroker, &stroker->current_face);
 	if (status)
@@ -879,6 +901,8 @@ _cairo_stroker_curve_to (void *closure,
     cairo_stroke_face_t start, end;
     cairo_point_t extra_points[4];
     cairo_point_t *a = &stroker->current_point;
+    double initial_slope_dx, initial_slope_dy;
+    double final_slope_dx, final_slope_dy;
 
     status = _cairo_spline_init (&spline, a, b, c, d);
     if (status == CAIRO_INT_STATUS_DEGENERATE)
@@ -888,8 +912,16 @@ _cairo_stroker_curve_to (void *closure,
     if (status)
 	goto CLEANUP_SPLINE;
 
-    _compute_face (a, &spline.initial_slope, stroker, &start);
-    _compute_face (d, &spline.final_slope, stroker, &end);
+    initial_slope_dx = _cairo_fixed_to_double (spline.initial_slope.dx);
+    initial_slope_dy = _cairo_fixed_to_double (spline.initial_slope.dy);
+    final_slope_dx = _cairo_fixed_to_double (spline.final_slope.dx);
+    final_slope_dy = _cairo_fixed_to_double (spline.final_slope.dy);
+
+    if (_compute_normalized_device_slope (&initial_slope_dx, &initial_slope_dy, stroker->ctm_inverse, NULL))
+	_compute_face (a, initial_slope_dx, initial_slope_dy, stroker, &start);
+
+    if (_compute_normalized_device_slope (&final_slope_dx, &final_slope_dy, stroker->ctm_inverse, NULL))
+	_compute_face (d, final_slope_dx, final_slope_dy, stroker, &end);
 
     if (stroker->has_current_face) {
 	status = _cairo_stroker_join (stroker, &stroker->current_face, &start);
commit bda0baa255801dbc21b63b364eff32de98dd6c7f
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Tue Feb 5 15:04:15 2008 -0800

    Fix text-zero-len on ATSUI to not infinite loop

diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index 55629c5..74d3e9e 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -257,6 +257,8 @@ _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face,
     if (font == NULL)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
+    memset (font, 0, sizeof(cairo_atsui_font_t));
+
     status = _cairo_scaled_font_init (&font->base,
 				      font_face, font_matrix, ctm, options,
 				      &cairo_atsui_scaled_font_backend);
@@ -270,10 +272,18 @@ _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face,
     if (status)
 	goto FAIL;
 
+    /* ATS can't handle 0-sized bits; we end up in an odd infinite loop
+     * if we send down a size of 0. */
+    if (xscale == 0.0) {
+	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	goto FAIL;
+    }
+
     font->font_matrix = CGAffineTransformMake (1., 0.,
 					       0., yscale/xscale,
 					       0., 0.);
     font->size = FloatToFixed (xscale);
+    font->style = NULL;
 
     err = CreateSizedCopyOfStyle (style, &font->size, &font->font_matrix, &font->style);
     if (err != noErr) {
@@ -310,6 +320,7 @@ _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face,
 	if (font) {
 	    if (font->style)
 		ATSUDisposeStyle(font->style);
+	    _cairo_scaled_font_fini(font);
 	    free (font);
 	}
 
commit 03256d0f2be15e7ba57bc041f8cdfc1c3e718660
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date:   Tue Feb 5 15:04:11 2008 -0800

    Remove get-xrender-format from list of tests to be run on all platforms

diff --git a/test/Makefile.am b/test/Makefile.am
index 220ec73..09547be 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -57,7 +57,6 @@ get-and-set$(EXEEXT)					\
 get-clip$(EXEEXT)					\
 get-group-target$(EXEEXT)				\
 get-path-extents$(EXEEXT)				\
-get-xrender-format$(EXEEXT)				\
 gradient-alpha$(EXEEXT)					\
 gradient-zero-stops$(EXEEXT)				\
 infinite-join$(EXEEXT)					\


More information about the cairo-commit mailing list