1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
3 * Copyright 2009 Chris Wilson
4 * Copyright 2010 Andrea Canciani
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Author: Chris Wilson <chris@chris-wilson.co.uk>
29 #include "cairo-test.h"
37 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
38 cairo_set_source_rgb (cr, 1, 0, 0);
41 cairo_set_operator (cr, CAIRO_OPERATOR_IN);
42 cairo_set_source_rgb (cr, 0, 0.7, 0);
43 cairo_arc (cr, 10, 10, 7.5, 0, 2 * M_PI);
44 cairo_move_to (cr, 0, 20);
45 cairo_line_to (cr, 20, 0);
52 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
53 cairo_set_source_rgb (cr, 1, 0, 0);
56 cairo_set_operator (cr, CAIRO_OPERATOR_IN);
57 cairo_set_source_rgb (cr, 0, 0.7, 0);
58 cairo_new_sub_path (cr);
59 cairo_arc (cr, 10, 10, 8.5, 0, 2 * M_PI);
60 cairo_new_sub_path (cr);
61 cairo_arc_negative (cr, 10, 10, 6.5, 2 * M_PI, 0);
63 cairo_move_to (cr, -1, 19);
64 cairo_line_to (cr, 1, 21);
65 cairo_line_to (cr, 21, 1);
66 cairo_line_to (cr, 19, -1);
67 cairo_line_to (cr, -1, 19);
73 clip_simple (cairo_t *cr)
75 cairo_rectangle (cr, 0, 0, 20, 20);
80 clip_unaligned (cairo_t *cr)
82 cairo_rectangle (cr, 0.5, 0.5, 20, 20);
87 clip_aligned (cairo_t *cr)
89 cairo_fill_rule_t orig_rule;
91 orig_rule = cairo_get_fill_rule (cr);
92 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
93 cairo_rectangle (cr, 0, 0, 20, 20);
94 cairo_rectangle (cr, 3, 3, 10, 10);
95 cairo_rectangle (cr, 7, 7, 10, 10);
97 cairo_set_fill_rule (cr, orig_rule);
101 clip_mask (cairo_t *cr)
103 cairo_arc (cr, 10, 10, 10, 0, 2 * M_PI);
104 cairo_new_sub_path (cr);
105 cairo_arc_negative (cr, 10, 10, 5, 2 * M_PI, 0);
106 cairo_new_sub_path (cr);
107 cairo_arc (cr, 10, 10, 2, 0, 2 * M_PI);
111 static void (* const clip_funcs[])(cairo_t *cr) = {
118 static double translations[][2] = {
125 static cairo_test_status_t
126 draw (cairo_t *cr, void (*shapes)(cairo_t *))
129 cairo_set_source_rgb (cr, 1, 1, 1);
132 for (i = 0; i < ARRAY_LENGTH (clip_funcs); i++) {
133 cairo_translate (cr, translations[i][0], translations[i][1]);
136 cairo_scale (cr, 2, 2);
142 return CAIRO_TEST_SUCCESS;
145 static cairo_test_status_t
146 draw_stroke (cairo_t *cr, int width, int height)
148 return draw (cr, stroke);
151 static cairo_test_status_t
152 draw_fill_nz (cairo_t *cr, int width, int height)
154 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
155 return draw (cr, fill);
158 static cairo_test_status_t
159 draw_fill_eo (cairo_t *cr, int width, int height)
161 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
162 return draw (cr, fill);
165 CAIRO_TEST (clip_stroke_unbounded,
166 "Tests unbounded stroke through complex clips.",
167 "clip, stroke, unbounded", /* keywords */
168 NULL, /* requirements */
169 2 * WIDTH, 2 * HEIGHT,
172 CAIRO_TEST (clip_fill_nz_unbounded,
173 "Tests unbounded fill through complex clips (with winding fill rule).",
174 "clip, fill, unbounded", /* keywords */
175 NULL, /* requirements */
176 2 * WIDTH, 2 * HEIGHT,
179 CAIRO_TEST (clip_fill_eo_unbounded,
180 "Tests unbounded fill through complex clips (with even-odd fill rule).",
181 "clip, fill, unbounded", /* keywords */
182 NULL, /* requirements */
183 2 * WIDTH, 2 * HEIGHT,