[cairo-commit] 4 commits - src/cairo-quartz-surface.c test/a1-bug.c test/aliasing.c test/api-special-cases.c test/cairo-test.h test/clear-source.c test/clip-disjoint.c test/clip-draw-unbounded.c test/clip-group-shapes.c test/clip-operator.c test/dash-caps-joins.c test/dash-offset.c test/dash-scale.c test/degenerate-dash.c test/degenerate-path.c test/fallback-resolution.c test/filter-nearest-transformed.c test/joins.c test/line-width-scale.c test/long-dashed-lines.c test/Makefile.am test/Makefile.sources test/mask.c test/mask-glyphs.c test/operator-clear.c test/operator-source.c test/path-precision.c test/pattern-getters.c test/pdf-features.c test/ps-features.c test/radial-gradient.c test/reflected-stroke.c test/show-glyphs-advance.c test/show-glyphs-advance.image16.ref.png test/show-glyphs-advance.ps.ref.png test/show-glyphs-advance.quartz.ref.png test/show-glyphs-advance.ref.png test/show-glyphs-advance.svg.ref.png test/subsurface-outside-target.c test/trap-clip.c test/unbounded-o perator.c test/zero-mask.c

Andrea Canciani ranma42 at kemper.freedesktop.org
Fri Mar 18 01:42:42 PDT 2011


 src/cairo-quartz-surface.c               |   12 +--
 test/Makefile.am                         |    5 +
 test/Makefile.sources                    |    1 
 test/a1-bug.c                            |    2 
 test/aliasing.c                          |    6 -
 test/api-special-cases.c                 |    1 
 test/cairo-test.h                        |   12 +++
 test/clear-source.c                      |    1 
 test/clip-disjoint.c                     |    2 
 test/clip-draw-unbounded.c               |    2 
 test/clip-group-shapes.c                 |    2 
 test/clip-operator.c                     |    5 -
 test/dash-caps-joins.c                   |    2 
 test/dash-offset.c                       |   16 ++--
 test/dash-scale.c                        |    6 -
 test/degenerate-dash.c                   |    4 -
 test/degenerate-path.c                   |    4 -
 test/fallback-resolution.c               |    2 
 test/filter-nearest-transformed.c        |    2 
 test/joins.c                             |    2 
 test/line-width-scale.c                  |    2 
 test/long-dashed-lines.c                 |    2 
 test/mask-glyphs.c                       |    2 
 test/mask.c                              |   13 +--
 test/operator-clear.c                    |    9 +-
 test/operator-source.c                   |    9 +-
 test/path-precision.c                    |    2 
 test/pattern-getters.c                   |    2 
 test/pdf-features.c                      |    4 -
 test/ps-features.c                       |    4 -
 test/radial-gradient.c                   |    4 -
 test/reflected-stroke.c                  |    2 
 test/show-glyphs-advance.c               |  107 +++++++++++++++++++++++++++++++
 test/show-glyphs-advance.image16.ref.png |binary
 test/show-glyphs-advance.ps.ref.png      |binary
 test/show-glyphs-advance.quartz.ref.png  |binary
 test/show-glyphs-advance.ref.png         |binary
 test/show-glyphs-advance.svg.ref.png     |binary
 test/subsurface-outside-target.c         |    2 
 test/trap-clip.c                         |   13 +--
 test/unbounded-operator.c                |    9 +-
 test/zero-mask.c                         |    2 
 42 files changed, 186 insertions(+), 91 deletions(-)

New commits:
commit c42d7f7acfaf8f67d0df2bda7c54148030705b12
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Wed Mar 16 17:12:59 2011 +0100

    quartz: Fix y glyph advance
    
    The advances must be transformed by the "quartz inverse scale",
    i.e. (scale_inverse * scale(1,-1)).
    
    Fixes show-glyph-advance.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index bb7be48..1b97aec 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -2061,16 +2061,18 @@ _cairo_quartz_surface_show_glyphs_cg (cairo_quartz_surface_t *surface,
 	cg_advances = (CGSize*) (cg_glyphs + num_glyphs);
     }
 
+    /* scale(1,-1) * scaled_font->scale */
     textTransform = CGAffineTransformMake (scaled_font->scale.xx,
 					   scaled_font->scale.yx,
-					   scaled_font->scale.xy,
-					   scaled_font->scale.yy,
+					   -scaled_font->scale.xy,
+					   -scaled_font->scale.yy,
 					   0.0, 0.0);
 
+    /* scaled_font->scale_inverse * scale(1,-1) */
     invTextTransform = CGAffineTransformMake (scaled_font->scale_inverse.xx,
-					      scaled_font->scale_inverse.yx,
+					      -scaled_font->scale_inverse.yx,
 					      scaled_font->scale_inverse.xy,
-					      scaled_font->scale_inverse.yy,
+					      -scaled_font->scale_inverse.yy,
 					      0.0, 0.0);
 
     CGContextSetTextPosition (state.cgMaskContext, 0.0, 0.0);
@@ -2095,14 +2097,12 @@ _cairo_quartz_surface_show_glyphs_cg (cairo_quartz_surface_t *surface,
     /* Translate to the first glyph's position before drawing */
     CGContextTranslateCTM (state.cgMaskContext, glyphs[0].x, glyphs[0].y);
     CGContextConcatCTM (state.cgMaskContext, textTransform);
-    CGContextScaleCTM (state.cgMaskContext, 1.0, -1.0);
 
     CGContextShowGlyphsWithAdvances (state.cgMaskContext,
 				     cg_glyphs,
 				     cg_advances,
 				     num_glyphs);
 
-    CGContextScaleCTM (state.cgMaskContext, 1.0, -1.0);
     CGContextConcatCTM (state.cgMaskContext, invTextTransform);
     CGContextTranslateCTM (state.cgMaskContext, -glyphs[0].x, -glyphs[0].y);
 
commit db04ab8f6357a682fbf31b8d34592fde0def961b
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Wed Mar 16 16:24:51 2011 +0100

    test: Add show-glyphs-advance
    
    This new test (based on show-glyphs-many) checks that the glyphs
    advances are respected along both axes.
    
    9c0d761bfcdd28d52c83d74f46dd3c709ae0fa69 introduced a bug which
    regresses this test in quartz.
    
    Thanks to Jeff Muizelaar for the report!

diff --git a/test/Makefile.am b/test/Makefile.am
index 8a62c13..a49ec62 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1197,6 +1197,11 @@ REFERENCE_IMAGES = \
 	self-intersecting.xlib.ref.png \
 	set-source.ref.png \
 	set-source.rgb24.ref.png \
+	show-glyphs-advance.image16.ref.png \
+	show-glyphs-advance.ps.ref.png \
+	show-glyphs-advance.quartz.ref.png \
+	show-glyphs-advance.ref.png \
+	show-glyphs-advance.svg.ref.png \
 	show-glyphs-many.ref.png \
 	show-text-current-point.image16.ref.png \
 	show-text-current-point.ps2.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index e88c85c..588d145 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -241,6 +241,7 @@ test_sources = \
 	self-copy-overlap.c				\
 	self-intersecting.c				\
 	set-source.c					\
+	show-glyphs-advance.c				\
 	show-glyphs-many.c				\
 	show-text-current-point.c			\
 	skew-extreme.c					\
diff --git a/test/show-glyphs-advance.c b/test/show-glyphs-advance.c
new file mode 100644
index 0000000..5fe9ec8
--- /dev/null
+++ b/test/show-glyphs-advance.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright © 2006 Red Hat, Inc.
+ * Copyright © 2011 Andrea Canciani
+ *
+ * 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>
+ *         Andrea Canciani <ranma42 at gmail.com>
+ */
+
+#include "cairo-test.h"
+
+static cairo_test_status_t
+get_glyph (const cairo_test_context_t *ctx,
+	   cairo_scaled_font_t *scaled_font,
+	   const char *utf8,
+	   cairo_glyph_t *glyph)
+{
+    cairo_glyph_t *text_to_glyphs;
+    cairo_status_t status;
+    int i;
+
+    text_to_glyphs = glyph;
+    i = 1;
+    status = cairo_scaled_font_text_to_glyphs (scaled_font,
+					       0, 0,
+					       utf8, -1,
+					       &text_to_glyphs, &i,
+					       NULL, NULL,
+					       0);
+    if (status != CAIRO_STATUS_SUCCESS)
+	return cairo_test_status_from_status (ctx, status);
+
+    if (text_to_glyphs != glyph) {
+	*glyph = text_to_glyphs[0];
+	cairo_glyph_free (text_to_glyphs);
+    }
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+static const char *characters[] = { "A", "B", "C", "D" };
+
+#define NUM_CHARS ARRAY_LENGTH (characters)
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
+    cairo_scaled_font_t *scaled_font;
+    cairo_glyph_t *glyphs = xmalloc (NUM_CHARS  * sizeof (cairo_glyph_t));
+    int i;
+    cairo_status_t status;
+
+    /* Paint white background. */
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+
+    scaled_font = cairo_get_scaled_font (cr);
+
+    for (i = 0; i < NUM_CHARS; i++) {
+	status = get_glyph (ctx, scaled_font, characters[i], &glyphs[i]);
+	if (status)
+	    goto BAIL;
+
+	glyphs[i].x = 10.0 + 10.0 * (i % 2);
+	glyphs[i].y = 20.0 + 10.0 * (i / 2);
+    }
+
+    cairo_set_source_rgb (cr, 0, 0, 0);
+    cairo_show_glyphs (cr, glyphs, 4);
+
+    cairo_translate (cr, 40., 20.);
+    cairo_rotate (cr, M_PI / 4.);
+
+    cairo_show_glyphs (cr, glyphs, NUM_CHARS);
+
+  BAIL:
+    free(glyphs);
+
+    return status;
+}
+
+CAIRO_TEST (show_glyphs_advance,
+	    "Test that glyph advances work as expected along both axes",
+	    "text, matrix", /* keywords */
+	    NULL, /* requirements */
+	    64, 64,
+	    NULL, draw)
diff --git a/test/show-glyphs-advance.image16.ref.png b/test/show-glyphs-advance.image16.ref.png
new file mode 100644
index 0000000..dd2f18d
Binary files /dev/null and b/test/show-glyphs-advance.image16.ref.png differ
diff --git a/test/show-glyphs-advance.ps.ref.png b/test/show-glyphs-advance.ps.ref.png
new file mode 100644
index 0000000..96a80f9
Binary files /dev/null and b/test/show-glyphs-advance.ps.ref.png differ
diff --git a/test/show-glyphs-advance.quartz.ref.png b/test/show-glyphs-advance.quartz.ref.png
new file mode 100644
index 0000000..4750308
Binary files /dev/null and b/test/show-glyphs-advance.quartz.ref.png differ
diff --git a/test/show-glyphs-advance.ref.png b/test/show-glyphs-advance.ref.png
new file mode 100644
index 0000000..bf44a8f
Binary files /dev/null and b/test/show-glyphs-advance.ref.png differ
diff --git a/test/show-glyphs-advance.svg.ref.png b/test/show-glyphs-advance.svg.ref.png
new file mode 100644
index 0000000..914d4d6
Binary files /dev/null and b/test/show-glyphs-advance.svg.ref.png differ
commit 0ce4face45392cd4a44179062fb4a5715f18bb85
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Wed Mar 16 16:55:50 2011 +0100

    test: Use ARRAY_LENGTH() macro
    
    Some tests hand-code ARRAY_LENGTH(). It is now provided by
    cairo-test.h, so it can be reused.

diff --git a/test/a1-bug.c b/test/a1-bug.c
index bdbecea..9166ff5 100644
--- a/test/a1-bug.c
+++ b/test/a1-bug.c
@@ -40,7 +40,7 @@ draw (cairo_t *cr, int width, int height)
     cairo_set_source_rgb (cr, 0, 0, 0);
     cairo_paint (cr);
 
-    for (i = 0; i < sizeof (xy) / sizeof (xy[0]); i++)
+    for (i = 0; i < ARRAY_LENGTH (xy); i++)
 	cairo_line_to (cr, xy[i].x, xy[i].y);
 
     cairo_set_source_rgb (cr, 1, 0, 0);
diff --git a/test/clip-disjoint.c b/test/clip-disjoint.c
index 797898e..28bb963 100644
--- a/test/clip-disjoint.c
+++ b/test/clip-disjoint.c
@@ -45,7 +45,7 @@ paint_curve (cairo_t *cr)
     cairo_set_line_width (cr, 2);
     cairo_move_to (cr, points[0].x, points[0].y);
 
-    for (i = 1; i < sizeof (points) / sizeof (points[0]) - 2; i += 3) {
+    for (i = 1; i < ARRAY_LENGTH (points) - 2; i += 3) {
 	cairo_curve_to (cr,
 			points[i].x, points[i].y,
 			points[i + 1].x, points[i + 1].y,
diff --git a/test/clip-draw-unbounded.c b/test/clip-draw-unbounded.c
index ce9b2e4..6b9263b 100644
--- a/test/clip-draw-unbounded.c
+++ b/test/clip-draw-unbounded.c
@@ -129,7 +129,7 @@ draw (cairo_t *cr, void (*shapes)(cairo_t *))
     cairo_set_source_rgb (cr, 1, 1, 1);
     cairo_paint (cr);
 
-    for (i = 0; i < sizeof (clip_funcs) / sizeof (clip_funcs[0]); i++) {
+    for (i = 0; i < ARRAY_LENGTH (clip_funcs); i++) {
 	cairo_translate (cr, translations[i][0], translations[i][1]);
 
 	cairo_save (cr);
diff --git a/test/dash-caps-joins.c b/test/dash-caps-joins.c
index 4347c6d..ace27e9 100644
--- a/test/dash-caps-joins.c
+++ b/test/dash-caps-joins.c
@@ -64,7 +64,7 @@ draw (cairo_t *cr, int width, int height)
     for (i=0; i<2; i++) {
 	cairo_save (cr);
 	cairo_set_line_width (cr, LINE_WIDTH);
-	cairo_set_dash (cr, dash, sizeof(dash)/sizeof(dash[0]), dash_offset);
+	cairo_set_dash (cr, dash, ARRAY_LENGTH (dash), dash_offset);
 
 	cairo_translate (cr, PAD, PAD);
 
diff --git a/test/dash-scale.c b/test/dash-scale.c
index afe3f9e..fd51702 100644
--- a/test/dash-scale.c
+++ b/test/dash-scale.c
@@ -82,7 +82,7 @@ draw (cairo_t *cr, int width, int height)
 
     cairo_translate (cr, PAD, PAD);
 
-    cairo_set_dash (cr, dash, sizeof(dash)/sizeof(dash[0]), - 2 * LINE_WIDTH);
+    cairo_set_dash (cr, dash, ARRAY_LENGTH (dash), - 2 * LINE_WIDTH);
     cairo_set_line_width (cr, LINE_WIDTH);
     draw_three_shapes (cr);
 
@@ -90,7 +90,7 @@ draw (cairo_t *cr, int width, int height)
 
     cairo_save (cr);
     {
-	cairo_set_dash (cr, dash, sizeof(dash)/sizeof(dash[0]), - 2 * LINE_WIDTH);
+	cairo_set_dash (cr, dash, ARRAY_LENGTH (dash), - 2 * LINE_WIDTH);
 	cairo_set_line_width (cr, LINE_WIDTH);
 	cairo_scale (cr, 1, 2);
 	draw_three_shapes (cr);
@@ -102,7 +102,7 @@ draw (cairo_t *cr, int width, int height)
     cairo_save (cr);
     {
 	cairo_scale (cr, 1, 2);
-	cairo_set_dash (cr, dash, sizeof(dash)/sizeof(dash[0]), - 2 * LINE_WIDTH);
+	cairo_set_dash (cr, dash, ARRAY_LENGTH (dash), - 2 * LINE_WIDTH);
 	cairo_set_line_width (cr, LINE_WIDTH);
 	draw_three_shapes (cr);
     }
diff --git a/test/fallback-resolution.c b/test/fallback-resolution.c
index 1d05973..5447a56 100644
--- a/test/fallback-resolution.c
+++ b/test/fallback-resolution.c
@@ -346,7 +346,7 @@ preamble (cairo_test_context_t *ctx)
     int n, num_ppi;
     const char *path = _cairo_test_mkdir (CAIRO_TEST_OUTPUT_DIR) ? CAIRO_TEST_OUTPUT_DIR : ".";
 
-    num_ppi = sizeof (ppi) / sizeof (ppi[0]);
+    num_ppi = ARRAY_LENGTH (ppi);
 
 #if GENERATE_REFERENCE
     for (n = 0; n < num_ppi; n++) {
diff --git a/test/filter-nearest-transformed.c b/test/filter-nearest-transformed.c
index 9629558..ba56f7c 100644
--- a/test/filter-nearest-transformed.c
+++ b/test/filter-nearest-transformed.c
@@ -79,7 +79,7 @@ draw (cairo_t *cr, int width, int height)
 
     cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
 
-    for (k = 0; k < sizeof (transform) / sizeof (transform[0]); k++) {
+    for (k = 0; k < ARRAY_LENGTH (transform); k++) {
 	/* draw a "large" section from an image */
 	cairo_save (cr); {
 	    cairo_set_matrix(cr, &ctx_transform[k]);
diff --git a/test/joins.c b/test/joins.c
index 10f9fe7..66847dc 100644
--- a/test/joins.c
+++ b/test/joins.c
@@ -42,7 +42,7 @@ make_path (cairo_t *cr)
     };
     unsigned int i, j;
 
-    for (j = 0; j < sizeof (scales) / sizeof (scales[0]); j++) {
+    for (j = 0; j < ARRAY_LENGTH (scales); j++) {
 	cairo_save (cr);
 	/* include reflections to flip the orientation of the join */
 	cairo_scale (cr, scales[j].x, scales[j].y);
diff --git a/test/long-dashed-lines.c b/test/long-dashed-lines.c
index cd940fb..215bd91 100644
--- a/test/long-dashed-lines.c
+++ b/test/long-dashed-lines.c
@@ -49,7 +49,7 @@ draw (cairo_t *cr, int width, int height)
     /* completely invisible rectangle */
     cairo_rectangle (cr, -5, -5, 70, 70);
 
-    cairo_set_dash (cr, dashes, sizeof (dashes) / sizeof (dashes[0]), 0.);
+    cairo_set_dash (cr, dashes, ARRAY_LENGTH (dashes), 0.);
     cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
     cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
     cairo_set_source_rgb (cr, 0, 0, 0);
diff --git a/test/mask-glyphs.c b/test/mask-glyphs.c
index 0a912e1..9ac0272 100644
--- a/test/mask-glyphs.c
+++ b/test/mask-glyphs.c
@@ -128,7 +128,7 @@ _render_image (cairo_t *cr,
     cairo_set_font_size (cr, 5);
     scaled_font = cairo_get_scaled_font (cr);
 
-    for (i = 0; i < sizeof (channel) / sizeof (channel[0]); i++) {
+    for (i = 0; i < ARRAY_LENGTH (channel); i++) {
 	cairo_push_group_with_content (cr, CAIRO_CONTENT_ALPHA);
 	for (n = 0; n < 256; n++) {
 	    cairo_status_t status;
diff --git a/test/path-precision.c b/test/path-precision.c
index 3261fb4..3a7fb11 100644
--- a/test/path-precision.c
+++ b/test/path-precision.c
@@ -57,7 +57,7 @@ draw (cairo_t *cr, int width, int height)
     cairo_test_status_t result = CAIRO_TEST_SUCCESS;
 
     path.status = CAIRO_STATUS_SUCCESS;
-    path.num_data = sizeof (path_data) / sizeof (path_data[0]);
+    path.num_data = ARRAY_LENGTH (path_data);
     path.data = path_data;
 
     cairo_new_path (cr);
diff --git a/test/pattern-getters.c b/test/pattern-getters.c
index da56db4..28bc1f9 100644
--- a/test/pattern-getters.c
+++ b/test/pattern-getters.c
@@ -151,7 +151,7 @@ draw (cairo_t *cr, int width, int height)
 	}
 
 	if (!double_buf_equal (ctx, new_buf, expected_values,
-			       sizeof(expected_values)/sizeof(double)) != 0)
+			       ARRAY_LENGTH (expected_values)) != 0)
 	{
 	    cairo_pattern_destroy (pat);
 	    return CAIRO_TEST_FAILURE;
diff --git a/test/reflected-stroke.c b/test/reflected-stroke.c
index 0981f75..b11f5a9 100644
--- a/test/reflected-stroke.c
+++ b/test/reflected-stroke.c
@@ -40,7 +40,7 @@ draw_symbol (cairo_t *cr)
     cairo_stroke (cr);
 
     cairo_save (cr);
-    cairo_set_dash (cr, dash, sizeof (dash) / sizeof (dash[0]), 0.);
+    cairo_set_dash (cr, dash, ARRAY_LENGTH (dash), 0.);
     cairo_move_to (cr, 0, 0);
     cairo_arc (cr, 0, 0, 12.5, 0, 3 * M_PI / 2);
     cairo_close_path (cr);
commit 75fea162d985bea622afa59771fb2d07f5241d1b
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Wed Mar 16 16:48:18 2011 +0100

    test: Cleanup macros
    
    The ARRAY_LENGTH macro is used by many tests, although sometimes it is
    named ARRAY_SIZE. Define it just once in cairo-test.h and reuse it.
    
    In a similar way, MAX() and MIN() are currently defined in some
    specific tests, while they could be reused.

diff --git a/test/aliasing.c b/test/aliasing.c
index 78a6d03..73c1f1a 100644
--- a/test/aliasing.c
+++ b/test/aliasing.c
@@ -46,10 +46,8 @@ static const  struct color {
     { 1, 0, 1 },
     { .5, .5, .5 },
 };
-#define NUM_COLORS (sizeof (color) / sizeof (color[0]))
-#ifndef MAX
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
+
+#define NUM_COLORS ARRAY_LENGTH (color)
 
 static void
 object (cairo_t *cr, const struct color *fg, const struct color *bg)
diff --git a/test/api-special-cases.c b/test/api-special-cases.c
index 6e51fe6..dbe9eb2 100644
--- a/test/api-special-cases.c
+++ b/test/api-special-cases.c
@@ -97,7 +97,6 @@
 #undef Cursor
 #endif
 
-#define ARRAY_LENGTH(array) (sizeof (array) / sizeof ((array)[0]))
 #define surface_has_type(surface,type) (cairo_surface_get_type (surface) == (type))
 
 typedef cairo_test_status_t (* surface_test_func_t) (cairo_surface_t *surface);
diff --git a/test/cairo-test.h b/test/cairo-test.h
index c7abd3d..c4f38c5 100644
--- a/test/cairo-test.h
+++ b/test/cairo-test.h
@@ -79,6 +79,18 @@ cairo_test_NaN (void)
 #endif
 }
 
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+#ifndef ARRAY_LENGTH
+#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
+#endif
+
 #define CAIRO_TEST_OUTPUT_DIR "output"
 
 #define CAIRO_TEST_LOG_SUFFIX ".log"
diff --git a/test/clear-source.c b/test/clear-source.c
index 4583bfb..a4c3db2 100644
--- a/test/clear-source.c
+++ b/test/clear-source.c
@@ -26,7 +26,6 @@
 
 #include "cairo-test.h"
 
-#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
 typedef enum {
   CLEAR,
   CLEARED,
diff --git a/test/clip-group-shapes.c b/test/clip-group-shapes.c
index aefaa55..88bb9b3 100644
--- a/test/clip-group-shapes.c
+++ b/test/clip-group-shapes.c
@@ -37,8 +37,6 @@
  *  for a specific bug).
  */
 
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-
 #define GENERATE_REF 0
 
 /* For determining whether we establish the clip path before or after
diff --git a/test/clip-operator.c b/test/clip-operator.c
index ec437e0..aaa3445 100644
--- a/test/clip-operator.c
+++ b/test/clip-operator.c
@@ -122,9 +122,8 @@ static void (* const draw_funcs[])(cairo_t *cr, int x, int y) = {
 
 #define N_OPERATORS (1 + CAIRO_OPERATOR_SATURATE - CAIRO_OPERATOR_CLEAR)
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
 #define IMAGE_WIDTH (N_OPERATORS * (WIDTH + PAD) + PAD)
-#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
+#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * (HEIGHT + PAD) + PAD)
 
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
@@ -139,7 +138,7 @@ draw (cairo_t *cr, int width, int height)
 			    CAIRO_FONT_WEIGHT_NORMAL);
     cairo_set_font_size (cr, 0.9 * HEIGHT);
 
-    for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
+    for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
 	for (op = CAIRO_OPERATOR_CLEAR; op < N_OPERATORS; op++) {
 	    x = op * (WIDTH + PAD) + PAD;
 	    y = j * (HEIGHT + PAD) + PAD;
diff --git a/test/dash-offset.c b/test/dash-offset.c
index 3699cac..0e53687 100644
--- a/test/dash-offset.c
+++ b/test/dash-offset.c
@@ -27,8 +27,6 @@
 
 #include "cairo-test.h"
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
 /* Lengths of the dashes of the dash patterns */
 static const double dashes[] = { 2, 2, 4, 4 };
 /* Dash offset in userspace units
@@ -45,8 +43,8 @@ static const double int_offset[] = { -2, -1, 0, 1, 2 };
 
 #define PAD 6
 #define STROKE_LENGTH 32
-#define IMAGE_WIDTH (PAD + (STROKE_LENGTH + PAD) * ARRAY_SIZE(dashes))
-#define IMAGE_HEIGHT (PAD + PAD * ARRAY_SIZE(int_offset) + PAD * ARRAY_SIZE(frac_offset) * ARRAY_SIZE(int_offset))
+#define IMAGE_WIDTH (PAD + (STROKE_LENGTH + PAD) * ARRAY_LENGTH (dashes))
+#define IMAGE_HEIGHT (PAD + PAD * ARRAY_LENGTH (int_offset) + PAD * ARRAY_LENGTH (frac_offset) * ARRAY_LENGTH (int_offset))
 
 
 static cairo_test_status_t
@@ -62,13 +60,13 @@ draw (cairo_t *cr, int width, int height)
     cairo_set_line_width (cr, 2);
 
     total = 0.0;
-    for (k = 0; k < ARRAY_SIZE(dashes); ++k) {
+    for (k = 0; k < ARRAY_LENGTH (dashes); ++k) {
 	total += dashes[k];
-	for (i = 0; i < ARRAY_SIZE(frac_offset); ++i) {
-	    for (j = 0; j < ARRAY_SIZE(int_offset); ++j) {
+	for (i = 0; i < ARRAY_LENGTH (frac_offset); ++i) {
+	    for (j = 0; j < ARRAY_LENGTH (int_offset); ++j) {
 		cairo_set_dash (cr, dashes, k + 1, frac_offset[i] + total * int_offset[j]);
-		cairo_move_to (cr, (STROKE_LENGTH + PAD) * k + PAD, PAD * (i + j + ARRAY_SIZE(frac_offset) * j + 1));
-		cairo_line_to (cr, (STROKE_LENGTH + PAD) * (k + 1), PAD * (i + j + ARRAY_SIZE(frac_offset) * j + 1));
+		cairo_move_to (cr, (STROKE_LENGTH + PAD) * k + PAD, PAD * (i + j + ARRAY_LENGTH (frac_offset) * j + 1));
+		cairo_line_to (cr, (STROKE_LENGTH + PAD) * (k + 1), PAD * (i + j + ARRAY_LENGTH (frac_offset) * j + 1));
 		cairo_stroke (cr);
 	    }
 	}
diff --git a/test/degenerate-dash.c b/test/degenerate-dash.c
index 961eeb5..c13792f 100644
--- a/test/degenerate-dash.c
+++ b/test/degenerate-dash.c
@@ -27,10 +27,6 @@
 
 #include "cairo-test.h"
 
-#ifndef ARRAY_LENGTH
-#define ARRAY_LENGTH(A) (int) (sizeof (A) / sizeof ((A)[0]))
-#endif
-
 #define PAD 5
 
 static cairo_test_status_t
diff --git a/test/degenerate-path.c b/test/degenerate-path.c
index 97cf7b2..c690730 100644
--- a/test/degenerate-path.c
+++ b/test/degenerate-path.c
@@ -28,8 +28,6 @@
 #define PAD 3.0
 #define LINE_WIDTH 6.0
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
-
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
 {
@@ -40,7 +38,7 @@ draw (cairo_t *cr, int width, int height)
 
     cairo_set_source_rgb (cr, 1, 0, 0);
 
-    for (i=0; i<ARRAY_SIZE(cap); i++) {
+    for (i = 0; i < ARRAY_LENGTH (cap); i++) {
 	cairo_save (cr);
 
 	cairo_set_line_cap (cr, cap[i]);
diff --git a/test/line-width-scale.c b/test/line-width-scale.c
index 68e1f11..037b887 100644
--- a/test/line-width-scale.c
+++ b/test/line-width-scale.c
@@ -143,8 +143,6 @@ scale_path_not_line_width (cairo_t *cr)
     cairo_restore (cr);
 }
 
-#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
-
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
 {
diff --git a/test/mask.c b/test/mask.c
index 451054e..cc722d3 100644
--- a/test/mask.c
+++ b/test/mask.c
@@ -180,9 +180,8 @@ static void (* const clip_funcs[])(cairo_t *cr, int x, int y) = {
     clip_circle,
 };
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD)
-#define IMAGE_HEIGHT (ARRAY_SIZE (mask_funcs) * ARRAY_SIZE (clip_funcs) * (HEIGHT + PAD) + PAD)
+#define IMAGE_WIDTH (ARRAY_LENGTH (pattern_funcs) * (WIDTH + PAD) + PAD)
+#define IMAGE_HEIGHT (ARRAY_LENGTH (mask_funcs) * ARRAY_LENGTH (clip_funcs) * (HEIGHT + PAD) + PAD)
 
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
@@ -201,11 +200,11 @@ draw (cairo_t *cr, int width, int height)
     cr2 = cairo_create (tmp_surface);
     cairo_surface_destroy (tmp_surface);
 
-    for (k = 0; k < ARRAY_SIZE (clip_funcs); k++) {
-	for (j = 0; j < ARRAY_SIZE (mask_funcs); j++) {
-	    for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
+    for (k = 0; k < ARRAY_LENGTH (clip_funcs); k++) {
+	for (j = 0; j < ARRAY_LENGTH (mask_funcs); j++) {
+	    for (i = 0; i < ARRAY_LENGTH (pattern_funcs); i++) {
 		int x = i * (WIDTH + PAD) + PAD;
-		int y = (ARRAY_SIZE (mask_funcs) * k + j) * (HEIGHT + PAD) + PAD;
+		int y = (ARRAY_LENGTH (mask_funcs) * k + j) * (HEIGHT + PAD) + PAD;
 
 		/* Clear intermediate surface we are going to be drawing onto */
 		cairo_save (cr2);
diff --git a/test/operator-clear.c b/test/operator-clear.c
index a1cf981..aac39f3 100644
--- a/test/operator-clear.c
+++ b/test/operator-clear.c
@@ -138,9 +138,8 @@ static void (* const draw_funcs[])(cairo_t *cr, int x, int y) = {
     draw_rects
 };
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD)
-#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
+#define IMAGE_WIDTH (ARRAY_LENGTH (pattern_funcs) * (WIDTH + PAD) + PAD)
+#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * (HEIGHT + PAD) + PAD)
 
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
@@ -153,8 +152,8 @@ draw (cairo_t *cr, int width, int height)
 			    CAIRO_FONT_SLANT_NORMAL,
 			    CAIRO_FONT_WEIGHT_NORMAL);
 
-    for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
-	for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
+    for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
+	for (i = 0; i < ARRAY_LENGTH (pattern_funcs); i++) {
 	    x = i * (WIDTH + PAD) + PAD;
 	    y = j * (HEIGHT + PAD) + PAD;
 
diff --git a/test/operator-source.c b/test/operator-source.c
index c92b4ad..d734167 100644
--- a/test/operator-source.c
+++ b/test/operator-source.c
@@ -175,9 +175,8 @@ static void (* const draw_funcs[])(cairo_t *cr, int x, int y) = {
     draw_rects
 };
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD)
-#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
+#define IMAGE_WIDTH (ARRAY_LENGTH (pattern_funcs) * (WIDTH + PAD) + PAD)
+#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * (HEIGHT + PAD) + PAD)
 
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
@@ -190,8 +189,8 @@ draw (cairo_t *cr, int width, int height)
 			    CAIRO_FONT_SLANT_NORMAL,
 			    CAIRO_FONT_WEIGHT_NORMAL);
 
-    for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
-	for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
+    for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
+	for (i = 0; i < ARRAY_LENGTH (pattern_funcs); i++) {
 	    x = i * (WIDTH + PAD) + PAD;
 	    y = j * (HEIGHT + PAD) + PAD;
 
diff --git a/test/pdf-features.c b/test/pdf-features.c
index 31099c9..f8850c4 100644
--- a/test/pdf-features.c
+++ b/test/pdf-features.c
@@ -40,8 +40,6 @@
 #define MM_TO_POINTS(mm) ((mm) / 25.4 * 72.0)
 #define TEXT_SIZE 12
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
-
 static struct {
     const char *page_size;
     const char *page_size_alias;
@@ -110,7 +108,7 @@ preamble (cairo_test_context_t *ctx)
 			    CAIRO_FONT_WEIGHT_NORMAL);
     cairo_set_font_size (cr, TEXT_SIZE);
 
-    for (i = 0; i < ARRAY_SIZE (pages); i++) {
+    for (i = 0; i < ARRAY_LENGTH (pages); i++) {
 	cairo_pdf_surface_set_size (surface,
 				   pages[i].width_in_points,
 				   pages[i].height_in_points);
diff --git a/test/ps-features.c b/test/ps-features.c
index c1fb730..e3cf9b4 100644
--- a/test/ps-features.c
+++ b/test/ps-features.c
@@ -43,8 +43,6 @@
 #define MM_TO_POINTS(mm) ((mm) / 25.4 * 72.0)
 #define TEXT_SIZE 12
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
-
 static struct {
     const char *page_size;
     const char *page_size_alias;
@@ -123,7 +121,7 @@ preamble (cairo_test_context_t *ctx)
 			    CAIRO_FONT_WEIGHT_NORMAL);
     cairo_set_font_size (cr, TEXT_SIZE);
 
-    for (i = 0; i < ARRAY_SIZE (pages); i++) {
+    for (i = 0; i < ARRAY_LENGTH (pages); i++) {
 	cairo_ps_surface_set_size (surface,
 				   pages[i].width_in_points,
 				   pages[i].height_in_points);
diff --git a/test/radial-gradient.c b/test/radial-gradient.c
index 25ced70..026876b 100644
--- a/test/radial-gradient.c
+++ b/test/radial-gradient.c
@@ -99,8 +99,8 @@ create_pattern (int index)
     radius1 = radiuses[NUM_GRADIENTS - index - 1];
 
     /* center the gradient */
-    left = fmin (x0 - radius0, x1 - radius1);
-    right = fmax (x0 + radius0, x1 + radius1);
+    left = MIN (x0 - radius0, x1 - radius1);
+    right = MAX (x0 + radius0, x1 + radius1);
     center = (left + right) * 0.5;
     x0 -= center;
     x1 -= center;
diff --git a/test/subsurface-outside-target.c b/test/subsurface-outside-target.c
index c60ca8a..5e84a84 100644
--- a/test/subsurface-outside-target.c
+++ b/test/subsurface-outside-target.c
@@ -26,8 +26,6 @@
 
 #include "cairo-test.h"
 
-#define ARRAY_LENGTH(array) (sizeof (array) / sizeof ((array)[0]))
-
 #define TARGET_SIZE 10
 
 #define SUB_SIZE 15
diff --git a/test/trap-clip.c b/test/trap-clip.c
index 0999d97..acfcafc 100644
--- a/test/trap-clip.c
+++ b/test/trap-clip.c
@@ -167,9 +167,8 @@ static void (* const clip_funcs[])(cairo_t *cr, int x, int y) = {
     clip_circle,
 };
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD)
-#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * ARRAY_SIZE (clip_funcs) * (HEIGHT + PAD) + PAD)
+#define IMAGE_WIDTH (ARRAY_LENGTH (pattern_funcs) * (WIDTH + PAD) + PAD)
+#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * ARRAY_LENGTH (clip_funcs) * (HEIGHT + PAD) + PAD)
 
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
@@ -177,11 +176,11 @@ draw (cairo_t *cr, int width, int height)
     const cairo_test_context_t *ctx = cairo_test_get_context (cr);
     size_t i, j, k, x, y;
 
-    for (k = 0; k < ARRAY_SIZE (clip_funcs); k++) {
-	for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
-	    for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
+    for (k = 0; k < ARRAY_LENGTH (clip_funcs); k++) {
+	for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
+	    for (i = 0; i < ARRAY_LENGTH (pattern_funcs); i++) {
 		x = i * (WIDTH + PAD) + PAD;
-		y = (ARRAY_SIZE (draw_funcs) * k + j) * (HEIGHT + PAD) + PAD;
+		y = (ARRAY_LENGTH (draw_funcs) * k + j) * (HEIGHT + PAD) + PAD;
 
 		cairo_save (cr);
 
diff --git a/test/unbounded-operator.c b/test/unbounded-operator.c
index 065bff9..6e132fb 100644
--- a/test/unbounded-operator.c
+++ b/test/unbounded-operator.c
@@ -126,9 +126,8 @@ static cairo_operator_t operators[] = {
     CAIRO_OPERATOR_DEST_IN, CAIRO_OPERATOR_DEST_ATOP
 };
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-#define IMAGE_WIDTH (ARRAY_SIZE (operators) * (WIDTH + PAD) + PAD)
-#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
+#define IMAGE_WIDTH (ARRAY_LENGTH (operators) * (WIDTH + PAD) + PAD)
+#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * (HEIGHT + PAD) + PAD)
 
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
@@ -141,8 +140,8 @@ draw (cairo_t *cr, int width, int height)
 			    CAIRO_FONT_SLANT_NORMAL,
 			    CAIRO_FONT_WEIGHT_NORMAL);
 
-    for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
-	for (i = 0; i < ARRAY_SIZE (operators); i++) {
+    for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
+	for (i = 0; i < ARRAY_LENGTH (operators); i++) {
 	    x = i * (WIDTH + PAD) + PAD;
 	    y = j * (HEIGHT + PAD) + PAD;
 
diff --git a/test/zero-mask.c b/test/zero-mask.c
index 5ea0709..29edd0a 100644
--- a/test/zero-mask.c
+++ b/test/zero-mask.c
@@ -135,8 +135,6 @@ mask_with_extend_none (cairo_t *cr)
     cairo_surface_destroy (surface);
 }
 
-#define ARRAY_LENGTH(array) (sizeof (array) / sizeof ((array)[0]))
-
 typedef void (* mask_func_t) (cairo_t *);
 
 static mask_func_t mask_funcs[] = {


More information about the cairo-commit mailing list