[cairo-commit] 2 commits - src/cairo-gstate.c test/degenerate-solid-dash.c test/reference

Chris Wilson ickle at kemper.freedesktop.org
Sun Apr 29 06:34:23 PDT 2012


 src/cairo-gstate.c                           |   37 +++++++++++++--------------
 test/degenerate-solid-dash.c                 |    4 +-
 test/reference/degenerate-solid-dash.ref.png |binary
 3 files changed, 20 insertions(+), 21 deletions(-)

New commits:
commit f5df96748e39d1f1a3fddf63712318377211b12b
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Apr 29 14:32:14 2012 +0100

    gstate: Correctly compact degenerate dash segments
    
    The danger of the incomplete test masking the failure to correctly skip
    the degenerate elements in the final dash state.
    
    Fixes the fixed degenerate-solid-dash.
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 650ed37..15dc46f 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -519,7 +519,7 @@ cairo_status_t
 _cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dashes, double offset)
 {
     double dash_total, on_total, off_total;
-    int i;
+    int i, j;
 
     free (gstate->stroke_style.dash);
 
@@ -537,28 +537,27 @@ _cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dash
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
-    memcpy (gstate->stroke_style.dash, dash, gstate->stroke_style.num_dashes * sizeof (double));
-
     on_total = off_total = dash_total = 0.0;
-    for (i = 0; i < num_dashes; i++) {
-	if (gstate->stroke_style.dash[i] < 0)
+    for (i = j = 0; i < num_dashes; i++) {
+	if (dash[i] < 0)
 	    return _cairo_error (CAIRO_STATUS_INVALID_DASH);
 
-	if (gstate->stroke_style.dash[i] == 0) {
-	    if (i > 0 && i < num_dashes - 1) {
-		gstate->stroke_style.dash[i-1] +=
-		    gstate->stroke_style.dash[i+1];
-		gstate->stroke_style.num_dashes -= 2;
-		i++;
-		continue;
-	    }
-	}
+	if (dash[i] == 0 && i > 0 && i < num_dashes - 1) {
+	    if (dash[++i] < 0)
+		return _cairo_error (CAIRO_STATUS_INVALID_DASH);
 
-	dash_total += gstate->stroke_style.dash[i];
-	if ((i & 1) == 0)
-	    on_total += gstate->stroke_style.dash[i];
-	else
-	    off_total += gstate->stroke_style.dash[i];
+	    gstate->stroke_style.dash[j-1] += dash[i];
+	    gstate->stroke_style.num_dashes -= 2;
+	} else
+	    gstate->stroke_style.dash[j++] = dash[i];
+
+	if (dash[i]) {
+	    dash_total += dash[i];
+	    if ((i & 1) == 0)
+		on_total += dash[i];
+	    else
+		off_total += dash[i];
+	}
     }
 
     if (dash_total == 0.0)
commit ba21231491dbed0252858ee8c2755db7b6f1c970
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Apr 29 14:23:11 2012 +0100

    test: Fix array lengths for degenerate-solid-dash
    
    The latter arrays were meant to test compaction.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/test/degenerate-solid-dash.c b/test/degenerate-solid-dash.c
index 18457b4..293a808 100644
--- a/test/degenerate-solid-dash.c
+++ b/test/degenerate-solid-dash.c
@@ -49,12 +49,12 @@ draw (cairo_t *cr, int width, int height)
     cairo_stroke (cr);
 
     cairo_translate (cr, 0, 50);
-    cairo_set_dash (cr, dashes_2, 2, 0);
+    cairo_set_dash (cr, dashes_2, 4, 0);
     cairo_rectangle (cr, 10, 10, 30, 30);
     cairo_stroke (cr);
 
     cairo_translate (cr, -50, 0);
-    cairo_set_dash (cr, dashes_3, 2, 0);
+    cairo_set_dash (cr, dashes_3, 4, 0);
     cairo_rectangle (cr, 10, 10, 30, 30);
     cairo_stroke (cr);
 
diff --git a/test/reference/degenerate-solid-dash.ref.png b/test/reference/degenerate-solid-dash.ref.png
index e58c2e4..92e2712 100644
Binary files a/test/reference/degenerate-solid-dash.ref.png and b/test/reference/degenerate-solid-dash.ref.png differ


More information about the cairo-commit mailing list