summaryrefslogtreecommitdiff
path: root/src/cairo-gstate.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2012-04-29 14:32:14 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2012-04-29 14:32:14 +0100
commitf5df96748e39d1f1a3fddf63712318377211b12b (patch)
treedce44706a4c21f79f2bfa92b045394c676927f2e /src/cairo-gstate.c
parentba21231491dbed0252858ee8c2755db7b6f1c970 (diff)
downloadcairo-f5df96748e39d1f1a3fddf63712318377211b12b.tar.gz
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@chris-wilson.co.uk>
Diffstat (limited to 'src/cairo-gstate.c')
-rw-r--r--src/cairo-gstate.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 650ed3715..15dc46f6b 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)