[cairo-commit] 2 commits - src/cairo-path-stroke-boxes.c test/Makefile.sources test/rectilinear-dash-scale.c test/reference
Chris Wilson
ickle at kemper.freedesktop.org
Wed Apr 18 07:29:32 PDT 2012
src/cairo-path-stroke-boxes.c | 11
test/Makefile.sources | 1
test/rectilinear-dash-scale.c | 196 ++++++++++
test/reference/rectilinear-dash-scale-unaligned.ref.png |binary
test/reference/rectilinear-dash-scale-unaligned.traps.ref.png |binary
test/reference/rectilinear-dash-scale.ref.png |binary
6 files changed, 204 insertions(+), 4 deletions(-)
New commits:
commit 70fc52cb80f21fff0ba960236f24b997692cce64
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Apr 18 15:24:41 2012 +0100
stroke(boxes): Apply user scale factors to dash segments
Fixes tests/rectilinear-dash-scale*
Reported-by: Guillaume Ayoub <xovni at wanadoo.fr>
Reported-by: Carlos Garcia Campos <carlosgc at gnome.org>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48818
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/src/cairo-path-stroke-boxes.c b/src/cairo-path-stroke-boxes.c
index cc9dd19..aca04c2 100644
--- a/src/cairo-path-stroke-boxes.c
+++ b/src/cairo-path-stroke-boxes.c
@@ -476,7 +476,7 @@ _cairo_rectilinear_stroker_line_to_dashed (void *closure,
const cairo_point_t *a = &stroker->current_point;
const cairo_point_t *b = point;
cairo_bool_t fully_in_bounds;
- double sign, remain;
+ double sf, sign, remain;
cairo_fixed_t mag;
cairo_status_t status;
cairo_line_t segment;
@@ -499,10 +499,13 @@ _cairo_rectilinear_stroker_line_to_dashed (void *closure,
}
is_horizontal = a->y == b->y;
- if (is_horizontal)
+ if (is_horizontal) {
mag = b->x - a->x;
- else
+ sf = fabs (stroker->ctm->xx);
+ } else {
mag = b->y - a->y;
+ sf = fabs (stroker->ctm->yy);
+ }
if (mag < 0) {
remain = _cairo_fixed_to_double (-mag);
sign = 1.;
@@ -515,7 +518,7 @@ _cairo_rectilinear_stroker_line_to_dashed (void *closure,
while (remain > 0.) {
double step_length;
- step_length = MIN (stroker->dash.dash_remain, remain);
+ step_length = MIN (sf * stroker->dash.dash_remain, remain);
remain -= step_length;
mag = _cairo_fixed_from_double (sign*remain);
commit 5ff32f70c14d89cb776a1a9da91089c258dbbf68
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Apr 18 15:20:57 2012 +0100
test: Add rectilinear-dash-scale
Exercise rectilinear dashes under a non-uniform scale factors.
References: https://bugs.freedesktop.org/show_bug.cgi?id=48818
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 025790f..7b66c94 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -267,6 +267,7 @@ test_sources = \
rectilinear-grid.c \
rectilinear-miter-limit.c \
rectilinear-dash.c \
+ rectilinear-dash-scale.c \
rectilinear-stroke.c \
reflected-stroke.c \
rel-path.c \
diff --git a/test/rectilinear-dash-scale.c b/test/rectilinear-dash-scale.c
new file mode 100644
index 0000000..1b69516
--- /dev/null
+++ b/test/rectilinear-dash-scale.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright © 2006 Red Hat, Inc.
+ * Copyright © 2008 Chris Wilson
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ * Chris Wilson <chris at chris-wilson.co.uk>
+ *
+ * Based on the original test/rectilinear-stroke.c by Carl D. Worth.
+ */
+
+#include "cairo-test.h"
+
+#define SIZE 50
+
+static void
+draw_dashes (cairo_t *cr)
+{
+ const double dash_square[4] = {4, 2, 2, 2};
+ const double dash_butt[4] = {5, 1, 3, 1};
+
+ cairo_save (cr);
+
+ cairo_set_dash (cr, dash_square, 4, 0);
+
+ cairo_set_line_width (cr, 1.0);
+ cairo_translate (cr, 1, 1);
+
+ /* Draw everything first with square caps. */
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+
+ /* Draw horizontal and vertical segments, each in both
+ * directions. */
+ cairo_move_to (cr, 4.5, 0.5);
+ cairo_rel_line_to (cr, 2.0, 0.0);
+
+ cairo_move_to (cr, 10.5, 4.5);
+ cairo_rel_line_to (cr, 0.0, 2.0);
+
+ cairo_move_to (cr, 6.5, 10.5);
+ cairo_rel_line_to (cr, -2.0, 0.0);
+
+ cairo_move_to (cr, 0.5, 6.5);
+ cairo_rel_line_to (cr, 0.0, -2.0);
+
+ /* Draw right angle turns in four directions. */
+ cairo_move_to (cr, 0.5, 2.5);
+ cairo_rel_line_to (cr, 0.0, -2.0);
+ cairo_rel_line_to (cr, 2.0, 0.0);
+
+ cairo_move_to (cr, 8.5, 0.5);
+ cairo_rel_line_to (cr, 2.0, 0.0);
+ cairo_rel_line_to (cr, 0.0, 2.0);
+
+ cairo_move_to (cr, 10.5, 8.5);
+ cairo_rel_line_to (cr, 0.0, 2.0);
+ cairo_rel_line_to (cr, -2.0, 0.0);
+
+ cairo_move_to (cr, 2.5, 10.5);
+ cairo_rel_line_to (cr, -2.0, 0.0);
+ cairo_rel_line_to (cr, 0.0, -2.0);
+
+ cairo_stroke (cr);
+
+ /* Draw a closed-path rectangle */
+ cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0);
+ cairo_set_dash (cr, dash_square, 4, 2);
+ cairo_stroke (cr);
+
+ cairo_translate (cr, 12, 0);
+
+ /* Now draw the same results, but with butt caps. */
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+ cairo_set_dash (cr, dash_butt, 4, 0.0);
+
+ /* Draw horizontal and vertical segments, each in both
+ * directions. */
+ cairo_move_to (cr, 4.0, 0.5);
+ cairo_rel_line_to (cr, 3.0, 0.0);
+
+ cairo_move_to (cr, 10.5, 4.0);
+ cairo_rel_line_to (cr, 0.0, 3.0);
+
+ cairo_move_to (cr, 7.0, 10.5);
+ cairo_rel_line_to (cr, -3.0, 0.0);
+
+ cairo_move_to (cr, 0.5, 7.0);
+ cairo_rel_line_to (cr, 0.0, -3.0);
+
+ /* Draw right angle turns in four directions. */
+ cairo_move_to (cr, 0.5, 3.0);
+ cairo_rel_line_to (cr, 0.0, -2.5);
+ cairo_rel_line_to (cr, 2.5, 0.0);
+
+ cairo_move_to (cr, 8.0, 0.5);
+ cairo_rel_line_to (cr, 2.5, 0.0);
+ cairo_rel_line_to (cr, 0.0, 2.5);
+
+ cairo_move_to (cr, 10.5, 8.0);
+ cairo_rel_line_to (cr, 0.0, 2.5);
+ cairo_rel_line_to (cr, -2.5, 0.0);
+
+ cairo_move_to (cr, 3.0, 10.5);
+ cairo_rel_line_to (cr, -2.5, 0.0);
+ cairo_rel_line_to (cr, 0.0, -2.5);
+
+ cairo_stroke (cr);
+
+ /* Draw a closed-path rectangle */
+ cairo_set_dash (cr, dash_butt, 4, 2.5);
+ cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0);
+ cairo_stroke (cr);
+
+ cairo_restore (cr);
+}
+
+static cairo_test_status_t
+dashes (cairo_t *cr)
+{
+ /* Paint background white, then draw in black. */
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ cairo_paint (cr);
+
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+ draw_dashes (cr);
+
+ cairo_save (cr);
+ cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
+ cairo_translate (cr, 0, SIZE);
+ cairo_scale (cr, 1, -1);
+ draw_dashes (cr);
+ cairo_restore (cr);
+
+ cairo_save (cr);
+ cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
+ cairo_translate (cr, SIZE, 0);
+ cairo_scale (cr, -1, 1);
+ draw_dashes (cr);
+ cairo_restore (cr);
+
+ cairo_save (cr);
+ cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
+ cairo_translate (cr, SIZE, SIZE);
+ cairo_scale (cr, -1, -1);
+ draw_dashes (cr);
+ cairo_restore (cr);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+aligned (cairo_t *cr, int width, int height)
+{
+ cairo_scale (cr, 4, 2);
+ return dashes(cr);
+}
+
+static cairo_test_status_t
+unaligned (cairo_t *cr, int width, int height)
+{
+ cairo_scale (cr, 3.9, 1.9);
+ return dashes(cr);
+}
+
+CAIRO_TEST (rectilinear_dash_scale,
+ "Test dashed rectilinear stroke operations (covering only whole pixels) after scaling",
+ "stroke dash", /* keywords */
+ NULL, /* requirements */
+ 4*SIZE, 2*SIZE,
+ NULL, aligned)
+
+CAIRO_TEST (rectilinear_dash_scale_unaligned,
+ "Test dashed rectilinear stroke operations (covering partial pixels) after scaling",
+ "stroke dash", /* keywords */
+ NULL, /* requirements */
+ 4*SIZE, 2*SIZE,
+ NULL, unaligned)
diff --git a/test/reference/rectilinear-dash-scale-unaligned.ref.png b/test/reference/rectilinear-dash-scale-unaligned.ref.png
new file mode 100644
index 0000000..ff16841
Binary files /dev/null and b/test/reference/rectilinear-dash-scale-unaligned.ref.png differ
diff --git a/test/reference/rectilinear-dash-scale-unaligned.traps.ref.png b/test/reference/rectilinear-dash-scale-unaligned.traps.ref.png
new file mode 100644
index 0000000..a1b7b35
Binary files /dev/null and b/test/reference/rectilinear-dash-scale-unaligned.traps.ref.png differ
diff --git a/test/reference/rectilinear-dash-scale.ref.png b/test/reference/rectilinear-dash-scale.ref.png
new file mode 100644
index 0000000..fb8f39a
Binary files /dev/null and b/test/reference/rectilinear-dash-scale.ref.png differ
More information about the cairo-commit
mailing list