[cairo-commit] 3 commits - src/cairo-path-fixed.c src/cairo-script-surface.c test/Makefile.am test/Makefile.sources test/stroke-open-box.c test/stroke-open-box.ref.png

Andrea Canciani ranma42 at kemper.freedesktop.org
Fri Mar 18 03:20:06 PDT 2011


 src/cairo-path-fixed.c       |    5 +++-
 src/cairo-script-surface.c   |    2 -
 test/Makefile.am             |    1 
 test/Makefile.sources        |    1 
 test/stroke-open-box.c       |   51 +++++++++++++++++++++++++++++++++++++++++++
 test/stroke-open-box.ref.png |binary
 6 files changed, 58 insertions(+), 2 deletions(-)

New commits:
commit f99358acf70e976a6cf8e5084770d540e08d22ad
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Fri Mar 18 10:50:23 2011 +0100

    script: Fix stroking of 3 sided boxes
    
    3-sided boxes can be replaced with rectangles when clipping and
    filling, but not when stroking. _emit_path() is used for all of these
    operations, so it cannot perform the optimization except for 4-sided
    boxes.
    
    Fixes stroke-open-box.

diff --git a/src/cairo-script-surface.c b/src/cairo-script-surface.c
index b975afa..e925269 100644
--- a/src/cairo-script-surface.c
+++ b/src/cairo-script-surface.c
@@ -1728,7 +1728,7 @@ _emit_path (cairo_script_surface_t *surface,
 
     if (path == NULL) {
 	_cairo_path_fixed_init (&surface->cr.current_path);
-    } else if (_cairo_path_fixed_is_box (path, &box)) {
+    } else if (_cairo_path_fixed_is_rectangle (path, &box)) {
 	double x1 = _cairo_fixed_to_double (box.p1.x);
 	double y1 = _cairo_fixed_to_double (box.p1.y);
 	double x2 = _cairo_fixed_to_double (box.p2.x);
commit c0fe55651565fa63586b7e4d675149a98c7e549c
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Mar 8 10:26:06 2011 +0100

    path: Fix _cairo_path_fixed_is_rectangle()
    
    __cairo_path_fixed_is_rectangle() is used by the PS and PDF backends
    to check if a path is equivalent to a rectangle when stroking. This is
    different from being a rectangle when filling, because of the implicit
    close_path appended to every subpath when filling.
    
    Fixes stroke-open-box.
    
    See https://bugs.freedesktop.org/show_bug.cgi?id=34560

diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index e3e273b..58d4f4b 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -1290,8 +1290,11 @@ _cairo_path_fixed_is_rectangle (const cairo_path_fixed_t *path,
     if (! _cairo_path_fixed_is_box (path, box))
 	return FALSE;
 
+    /* This check is valid because the current implementation of
+     * _cairo_path_fixed_is_box () only accepts rectangles like:
+     * move,line,line,line[,line|close[,close|move]]. */
     buf = cairo_path_head (path);
-    if (buf->points[0].y == buf->points[1].y)
+    if (buf->num_ops > 4)
 	return TRUE;
 
     return FALSE;
commit 43692559614e841dc169e3cec213033b0298da87
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Tue Mar 8 10:13:24 2011 +0100

    test: Add stroke-open-box
    
    Add a new test to check that the stroking of a 3-sided box is not
    "optimized" to a 4-sided box.
    
    Test case based on the code by Simon Kellner in
    https://bugs.freedesktop.org/show_bug.cgi?id=34560

diff --git a/test/Makefile.am b/test/Makefile.am
index a49ec62..afe00af 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1282,6 +1282,7 @@ REFERENCE_IMAGES = \
 	stroke-image.quartz.ref.png \
 	stroke-image.ref.png \
 	stroke-image.xlib.ref.png \
+	stroke-open-box.ref.png \
 	subsurface.ref.png \
 	subsurface.image16.ref.png \
 	subsurface.ps.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 588d145..f241e51 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -235,6 +235,7 @@ test_sources = \
 	scaled-font-zero-matrix.c			\
 	stroke-ctm-caps.c				\
 	stroke-image.c				        \
+	stroke-open-box.c				\
 	select-font-face.c				\
 	select-font-no-show-text.c			\
 	self-copy.c					\
diff --git a/test/stroke-open-box.c b/test/stroke-open-box.c
new file mode 100644
index 0000000..b1dae50
--- /dev/null
+++ b/test/stroke-open-box.c
@@ -0,0 +1,51 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2011 Simon Kellner
+ *
+ * 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: Simon Kellner <kellner at kit.edu>
+ */
+
+#include "cairo-test.h"
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+
+    cairo_set_source_rgb (cr, 0, 0, 0);
+    cairo_move_to (cr, 5, 7);
+    cairo_rel_line_to (cr, 20, 0);
+    cairo_rel_line_to (cr, 0, 15);
+    cairo_rel_line_to (cr, -20, 0);
+    cairo_stroke (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (stroke_open_box,
+	    "Tests stroking of a 3-sided box",
+	    "stroke,box", /* keywords */
+	    NULL, /* requirements */
+	    30, 32,
+	    NULL, draw)
diff --git a/test/stroke-open-box.ref.png b/test/stroke-open-box.ref.png
new file mode 100644
index 0000000..b5f5bd5
Binary files /dev/null and b/test/stroke-open-box.ref.png differ


More information about the cairo-commit mailing list