2 * Copyright © 2011 Intel Corporation
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: Chris Wilson <chris@chris-wilson.co.uk>
27 #include "cairo-test.h"
32 /* This is an example from the wild, as silly as it is
33 n 52 0 429 709 rectangle
35 //ANTIALIAS_NONE set-antialias
36 n 8 0 m 952 0 l 956.417969 0 960 3.582031 960 8 c 960 1807 l 960 1811.417969 956.417969 1815 952 1815 c 8 1815 l 3.582031 1815 0 1811.417969 0 1807 c 0 8 l 0 3.582031 3.582031 0 8 0 c h
38 //EVEN_ODD set-fill-rule
39 n 0 0 m 480 0 l 480 708 l 0 708 l h 8 1 m 952 1 l 955.867188 1 959 4.132812 959 8 c 959 1807 l 959 1810.867188 955.867188 1814 952 1814 c 8 1814 l 4.132812 1814 1 1810.867188 1 1807 c 1 8 l 1 4.132812 4.132812 1 8 1 c h
41 //WINDING set-fill-rule
42 //ANTIALIAS_DEFAULT set-antialias
43 n 960 0 m 52.5 907.5 l 52.5 1815 l 960 1815 l h
45 //ANTIALIAS_NONE set-antialias
46 n 960 0 m 52.5 0 l 52.5 907.5 l 960 1815 l h
50 static void background (cairo_t *cr)
52 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
53 cairo_set_source_rgb (cr, 1,1,1);
55 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
58 static void clip_0 (cairo_t *cr)
60 cairo_rectangle (cr, 5, 5, 190, 190);
64 static void clip_1 (cairo_t *cr)
66 cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
68 cairo_arc (cr, 100, 100, 125, 0, 2*M_PI);
71 cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
75 rounded_rectangle (cairo_t *cr, int x, int y, int w, int h, int r)
77 cairo_new_sub_path (cr);
78 cairo_arc (cr, x + r, y + r, r, M_PI, 3 * M_PI / 2);
79 cairo_arc (cr, x + w - r, y + r, r, 3 *M_PI / 2, 2 * M_PI);
80 cairo_arc (cr, x + w - r, y + h - r, r, 0, M_PI / 2);
81 cairo_arc (cr, x + r, y + h - r, r, M_PI / 2, M_PI);
82 cairo_close_path (cr);
85 static void clip_2 (cairo_t *cr)
87 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
89 rounded_rectangle (cr, 50, 50, 100, 100, 15);
90 rounded_rectangle (cr, 60, 60, 80, 80, 5);
93 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
96 static void clip_3 (cairo_t *cr)
98 cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
100 cairo_rectangle (cr, 40.25, 60.25, 120, 80);
101 cairo_rectangle (cr, 60.25, 40.25, 80, 120);
104 cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
107 static cairo_test_status_t
108 draw (cairo_t *cr, int width, int height)
117 cairo_set_source_rgb (cr, 0, 0, 0);
120 return CAIRO_TEST_SUCCESS;
123 CAIRO_TEST (clip_mixed_antialias,
124 "Test drawing through through an mixture of clips",
125 "clip", /* keywords */
126 "target=raster", /* requirements */