2 * Copyright © 2011 Uli Schlachter
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Author: Uli Schlachter <psychon@znc.in>
27 #include "cairo-test.h"
29 static void path_none (cairo_t *cr, int size)
33 static void path_box (cairo_t *cr, int size)
35 cairo_rectangle (cr, 0, 0, size, size);
38 static void path_box_unaligned (cairo_t *cr, int size)
40 cairo_rectangle (cr, 0.5, 0.5, size - 1, size - 1);
43 static void path_triangle (cairo_t *cr, int size)
45 cairo_move_to (cr, 0, 0);
46 cairo_line_to (cr, size/2, size);
47 cairo_line_to (cr, size, 0);
48 cairo_close_path (cr);
51 static void path_circle (cairo_t *cr, int size)
53 cairo_arc (cr, size / 2.0, size / 2.0, size / 2.0, 0, 2 * M_PI);
56 static void (* const path_funcs[])(cairo_t *cr, int size) = {
67 /* All-clipped is boring, thus we skip path_none for clipping */
69 #define IMAGE_WIDTH ((ARRAY_LENGTH (path_funcs) - CLIP_OFFSET) * TYPES * (SIZE + PAD) - PAD)
70 #define IMAGE_HEIGHT (ARRAY_LENGTH (path_funcs) * (SIZE + PAD) - PAD)
73 draw_idx (cairo_t *cr, int i, int j, int type)
75 cairo_bool_t little_path;
76 cairo_bool_t empty_clip;
77 cairo_bool_t little_clip;
79 /* The lowest bit controls the path, the rest the clip */
80 little_path = type & 1;
82 /* We don't want the combination "empty_clip = TRUE, little_clip = FALSE"
105 /* Thanks to the fill rule, drawing something twice removes it again */
106 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
108 path_funcs[i] (cr, SIZE);
110 path_funcs[i] (cr, SIZE);
114 cairo_translate (cr, SIZE / 4, SIZE / 4);
115 path_funcs[i] (cr, SIZE / 2);
120 path_funcs[j] (cr, SIZE);
121 path_funcs[j] (cr, SIZE);
124 /* Draw the object again in the center of itself */
126 cairo_translate (cr, SIZE / 4, SIZE / 4);
127 path_funcs[j] (cr, SIZE / 2);
134 static cairo_test_status_t
135 draw (cairo_t *cr, int width, int height)
139 cairo_set_source_rgb (cr, 0, 1, 0);
142 /* Set an unbounded operator so that we can see how accurate the bounded
145 cairo_set_operator (cr, CAIRO_OPERATOR_IN);
146 cairo_set_source_rgb (cr, 1, 1, 1);
148 for (j = 0; j < ARRAY_LENGTH (path_funcs); j++) {
150 for (i = CLIP_OFFSET; i < ARRAY_LENGTH (path_funcs); i++) {
151 for (k = 0; k < TYPES; k++) {
153 cairo_rectangle (cr, 0, 0, SIZE, SIZE);
155 draw_idx (cr, i, j, k);
157 cairo_translate (cr, SIZE + PAD, 0);
161 cairo_translate (cr, 0, SIZE + PAD);
164 return CAIRO_TEST_SUCCESS;
167 CAIRO_TEST (tighten_bounds,
168 "Tests that we tighten the bounds after tessellation.",
169 "fill", /* keywords */
170 NULL, /* requirements */
171 IMAGE_WIDTH, IMAGE_HEIGHT,