[cairo] Long line test

Emmanuel Pacaud emmanuel.pacaud at univ-poitiers.fr
Wed Aug 9 15:45:42 PDT 2006


Hi,

You'll find attached a test for the long line bug.

That's a bug we hit easily in goffice graph when using our cairo
renderer. (A workaround we could use would be to clamp coordinates to
something safe (it looks like it's +/-10000, without using
transformation), but since clamping bound is quite low, that leads to
incorrect display in some cases. Something more correct would be to clip
our paths before sending them to cairo).

A thing that makes this bug annoying is the fact that bounds in which
cairo output is correct is not predictable, and seems to also depends on
line width. 

I thought it was due to a bug in cairo_fixed_from_double, where values >
32767.0 are converted to -32768, but fixing that bug does not fix the
long line bug.

	Emmanuel.
-------------- next part --------------
>From nobody Mon Sep 17 00:00:00 2001
From: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date: Thu, 10 Aug 2006 00:25:34 +0200
Subject: [PATCH] New test for long line bug.

---

 test/.gitignore         |    1 +
 test/Makefile.am        |    2 +
 test/long-lines-ref.png |  Bin
 test/long-lines.c       |   92 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100644 test/long-lines-ref.png
 create mode 100644 test/long-lines.c

2f53c877698b45f84a4756967ae65bcaa29c42e8
diff --git a/test/.gitignore b/test/.gitignore
index 0f56121..ff2c13b 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -57,6 +57,7 @@ leaky-polygon
 line-width
 line-width-scale
 linear-gradient
+long-lines
 mask
 mask-ctm
 mask-surface-ctm
diff --git a/test/Makefile.am b/test/Makefile.am
index 968e090..ef02186 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -41,6 +41,7 @@ leaky-polygon			\
 line-width			\
 line-width-scale		\
 linear-gradient			\
+long-lines			\
 mask				\
 mask-ctm			\
 mask-surface-ctm		\
@@ -229,6 +230,7 @@ line-width-ref.png					\
 line-width-ps-argb32-ref.png				\
 line-width-scale-ref.png				\
 line-width-scale-ps-argb32-ref.png			\
+long-lines-ref.png					\
 mask-ref.png						\
 mask-rgb24-ref.png					\
 mask-beos_bitmap-argb32-ref.png				\
diff --git a/test/long-lines-ref.png b/test/long-lines-ref.png
new file mode 100644
index 0000000..6119204
Binary files /dev/null and b/test/long-lines-ref.png differ
diff --git a/test/long-lines.c b/test/long-lines.c
new file mode 100644
index 0000000..445ac66
--- /dev/null
+++ b/test/long-lines.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright ?? 2005 Red Hat, Inc.
+ *
+ * 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
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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.
+ *
+ * Authors: Carl D. Worth <cworth at cworth.org>
+ * 	    Emmanuel Pacaud <emmanuel.pacaud at lapp.in2p3.fr>
+ */
+
+#include "cairo-test.h"
+
+#define LINE_WIDTH 	1.
+#define SIZE 		10
+#define LINE_NBR	6
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "long-lines",
+    "Test long lines",
+    SIZE * (LINE_NBR + 1),
+    SIZE * (LINE_NBR + 1),
+    draw
+};
+
+struct {
+    double length;
+    double red, green, blue;
+} lines[LINE_NBR] = {
+    {      100.0, 1.0, 0.0, 0.0 },
+    {    10000.0, 0.0, 1.0, 0.0 },
+    {   100000.0, 0.0, 0.0, 1.0 },
+    {  1000000.0, 1.0, 1.0, 0.0 },
+    { 10000000.0, 0.0, 1.0, 1.0 },
+    {100000000.0, 1.0, 0.0, 1.0 }
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    double pos;
+    int i;
+
+    /* 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);
+
+
+    cairo_set_line_width (cr, LINE_WIDTH);
+
+    pos = SIZE + .5;
+    for (i = 0; i < LINE_NBR; i++) {
+	cairo_move_to (cr, pos, -lines[i].length);
+	cairo_line_to (cr, pos, +lines[i].length);
+	cairo_set_source_rgb (cr, lines[i].red, lines[i].green, lines[i].blue);
+	cairo_stroke (cr);
+	pos += SIZE;
+    }
+
+    /* This should display a perfect vertically centered black line */
+    cairo_move_to (cr, 0.5, -1e100);
+    cairo_line_to (cr, pos,  1e100);
+    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+    cairo_stroke (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
-- 
1.3.2



More information about the cairo mailing list