[cairo-commit] 2 commits - AUTHORS src/cairo-path-fixed.c test/close-path-current-point.c test/close-path-current-point.ref.png test/Makefile.am test/Makefile.sources

Chris Wilson ickle at kemper.freedesktop.org
Wed Jun 17 08:40:44 PDT 2009


 AUTHORS                               |    1 
 src/cairo-path-fixed.c                |    6 +-
 test/Makefile.am                      |    1 
 test/Makefile.sources                 |    1 
 test/close-path-current-point.c       |   95 ++++++++++++++++++++++++++++++++++
 test/close-path-current-point.ref.png |binary
 6 files changed, 101 insertions(+), 3 deletions(-)

New commits:
commit bc87074185592eae367b6c091241957b94202fda
Author: Nis Martensen <nis.martensen at web.de>
Date:   Tue Jun 16 23:27:20 2009 +0200

    [path] Fix missing implicit move-to
    
    When cairo_curve_to happens to start a new subpath (e.g., after a call
    to cairo_new_sub_path()), it also needs to update the last_move_point.
    Otherwise the new current point after a close_path() will be at an
    unexpected position.
    
    Therefore, call _cairo_path_fixed_move_to() explicitly.

diff --git a/AUTHORS b/AUTHORS
index 9856a88..7f7b0d1 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -51,6 +51,7 @@ Tor Lillqvist <tml at novell.com> win32 build fixes, build scripts
 Jinghua Luo <sunmoon1997 at gmail.com> Add bitmap glyph transformation, many freetype and glitz fixes
 Luke-Jr <luke-jr at utopios.org> Build fix for cross-compiling
 Kjartan Maraas <kmaraas at gnome.org> Several fixes for sparse, lots of debug help for multi-thread bugs
+Nis Martensen <nis.martensen at web.de> Bug fix for sub paths
 Jordi Mas <jordi at ximian.com> Bug fix for cairo_show_text
 Nicholas Miell <nmiell at gmail.com> Fixes for linking bugs on AMD64
 Eugeniy Meshcheryakov <eugen at debian.org> PS/PDF font subsetting improvements
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index 53d6cd4..f95c64a 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -414,7 +414,7 @@ _cairo_path_fixed_line_to (cairo_path_fixed_t *path,
 
     /* When there is not yet a current point, the line_to operation
      * becomes a move_to instead. Note: We have to do this by
-     * explicitly calling into _cairo_path_fixed_line_to to ensure
+     * explicitly calling into _cairo_path_fixed_move_to to ensure
      * that the last_move_point state is updated properly.
      */
     if (! path->has_current_point)
@@ -460,9 +460,9 @@ _cairo_path_fixed_curve_to (cairo_path_fixed_t	*path,
     point[1].x = x1; point[1].y = y1;
     point[2].x = x2; point[2].y = y2;
 
+    /* make sure subpaths are started properly */
     if (! path->has_current_point) {
-	status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_MOVE_TO,
-					&point[0], 1);
+	status = _cairo_path_fixed_move_to (path, point[0].x, point[0].y);
 	if (unlikely (status))
 	    return status;
     }
commit 3c5e57e694d1a8a0a48a66e0d61d8257c23a780e
Author: Nis Martensen <nis.martensen at web.de>
Date:   Tue Jun 16 23:38:50 2009 +0200

    [test] Verify current point position after subpath closure
    
    Make sure cairo_close_path always takes the current point where it
    should be.

diff --git a/test/Makefile.am b/test/Makefile.am
index 1472c5c..155077d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -218,6 +218,7 @@ REFERENCE_IMAGES = \
 	close-path.ps2.ref.png \
 	close-path.ps3.ref.png \
 	close-path.ref.png \
+	close-path-current-point.ref.png \
 	composite-integer-translate-over.ps2.ref.png \
 	composite-integer-translate-over.ps3.ref.png \
 	composite-integer-translate-over.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 23596f8..4604b1f 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -24,6 +24,7 @@ test_sources = \
 	clipped-group.c					\
 	clipped-surface.c				\
 	close-path.c					\
+	close-path-current-point.c			\
 	composite-integer-translate-source.c		\
 	composite-integer-translate-over.c		\
 	composite-integer-translate-over-repeat.c	\
diff --git a/test/close-path-current-point.c b/test/close-path-current-point.c
new file mode 100644
index 0000000..35f8d42
--- /dev/null
+++ b/test/close-path-current-point.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright © 2009 Nis Martensen
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of the copyright holder
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. The
+ * copyright holder makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without
+ * express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Nis Martensen <nis.martensen at web.de>
+ */
+
+#include "cairo-test.h"
+
+#define SIZE 20
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    /* subpath starts with cairo_move_to */
+    cairo_new_sub_path (cr);
+    cairo_move_to (cr, SIZE, SIZE);
+    cairo_rel_line_to (cr, SIZE, 0);
+    cairo_rel_line_to (cr, 0, SIZE);
+    cairo_close_path (cr);
+    cairo_rel_line_to (cr, 0.5 * SIZE, SIZE);
+
+    /* subpath starts with cairo_line_to */
+    cairo_new_sub_path (cr);
+    cairo_line_to (cr, SIZE, 3 * SIZE);
+    cairo_rel_line_to (cr, SIZE, 0);
+    cairo_rel_line_to (cr, 0, SIZE);
+    cairo_close_path (cr);
+    cairo_rel_line_to (cr, 0, SIZE);
+
+    /* subpath starts with cairo_curve_to */
+    cairo_new_sub_path (cr);
+    cairo_curve_to (cr,
+		    SIZE, 5 * SIZE,
+		    1.5 * SIZE, 6 * SIZE,
+		    2 * SIZE, 5 * SIZE);
+    cairo_rel_line_to (cr, 0, SIZE);
+    cairo_close_path (cr);
+    cairo_rel_line_to (cr, -0.5 * SIZE, SIZE);
+
+    /* subpath starts with cairo_arc */
+    cairo_new_sub_path (cr);
+    cairo_arc (cr,
+	       1.5 * SIZE, 7 * SIZE,
+	       0.5 * SIZE,
+	       M_PI, 2 * M_PI);
+    cairo_rel_line_to (cr, 0, SIZE);
+    cairo_close_path (cr);
+    cairo_rel_line_to (cr, -0.7 * SIZE, 0.7 * SIZE);
+
+    /* subpath starts with cairo_arc_negative */
+    cairo_new_sub_path (cr);
+    cairo_arc_negative (cr,
+			1.5 * SIZE, 9 * SIZE,
+			0.5 * SIZE,
+			M_PI, 2 * M_PI);
+    cairo_rel_line_to (cr, 0, SIZE);
+    cairo_close_path (cr);
+    cairo_rel_line_to (cr, -0.8 * SIZE, 0.3 * SIZE);
+
+    cairo_stroke (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (close_path_current_point,
+	    "Test some corner cases related to cairo path operations and the current point",
+	    "path", /* keywords */
+	    NULL, /* requirements */
+	    3 * SIZE, 11 * SIZE,
+	    NULL, draw)
diff --git a/test/close-path-current-point.ref.png b/test/close-path-current-point.ref.png
new file mode 100644
index 0000000..f30002c
Binary files /dev/null and b/test/close-path-current-point.ref.png differ


More information about the cairo-commit mailing list