4ca4566d52c378543fc8c33c8d4e76d6f9c99c86
[framework/graphics/cairo.git] / test / rotated-clip.c
1 /*
2  * Copyright © 2007 Adrian Johnson
3  * Copyright © 2009 Chris Wilson
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Author: Adrian Johnson <ajohnson@redneon.com>
26  *         Chris Wilson <chris@chris-wilson.co.uk>
27  */
28
29 #include "cairo-test.h"
30
31 #define PAT_WIDTH  120
32 #define PAT_HEIGHT 120
33 #define SIZE (PAT_WIDTH*2)
34 #define PAD 2
35 #define WIDTH (PAD + SIZE + PAD)
36 #define HEIGHT WIDTH
37
38 static cairo_test_status_t
39 draw (cairo_t *cr, int width, int height)
40 {
41     cairo_matrix_t m;
42
43     /* make the output opaque */
44     cairo_set_source_rgb (cr, 0, 0, 0);
45     cairo_paint (cr);
46
47     cairo_translate (cr, PAD, PAD);
48
49     cairo_matrix_init_scale (&m, 2, 1.5);
50     cairo_matrix_rotate (&m, 1);
51     cairo_matrix_translate (&m, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
52     cairo_matrix_invert (&m);
53     cairo_set_matrix (cr, &m);
54
55     cairo_rectangle (cr, 0, 0, PAT_WIDTH, PAT_HEIGHT);
56     cairo_clip (cr);
57
58     cairo_set_source_rgba (cr, 1, 0, 1, 0.5);
59     cairo_rectangle (cr, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
60     cairo_fill (cr);
61
62     cairo_set_source_rgba (cr, 0, 1, 1, 0.5);
63     cairo_rectangle (cr, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
64     cairo_fill (cr);
65
66     cairo_set_line_width (cr, 1);
67     cairo_move_to (cr, PAT_WIDTH/6.0, 0);
68     cairo_line_to (cr, 0, 0);
69     cairo_line_to (cr, 0, PAT_HEIGHT/6.0);
70     cairo_set_source_rgb (cr, 1, 0, 0);
71     cairo_stroke (cr);
72
73     cairo_move_to (cr, PAT_WIDTH/6.0, PAT_HEIGHT);
74     cairo_line_to (cr, 0, PAT_HEIGHT);
75     cairo_line_to (cr, 0, 5*PAT_HEIGHT/6.0);
76     cairo_set_source_rgb (cr, 0, 1, 0);
77     cairo_stroke (cr);
78
79     cairo_move_to (cr, 5*PAT_WIDTH/6.0, 0);
80     cairo_line_to (cr, PAT_WIDTH, 0);
81     cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/6.0);
82     cairo_set_source_rgb (cr, 0, 0, 1);
83     cairo_stroke (cr);
84
85     cairo_move_to (cr, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
86     cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT);
87     cairo_line_to (cr, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
88     cairo_set_source_rgb (cr, 1, 1, 0);
89     cairo_stroke (cr);
90
91     cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
92     cairo_set_line_width (cr, PAT_WIDTH/10.0);
93
94     cairo_move_to (cr, 0,         PAT_HEIGHT/4.0);
95     cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/4.0);
96     cairo_stroke (cr);
97
98     cairo_move_to (cr, PAT_WIDTH/4.0,         0);
99     cairo_line_to (cr, PAT_WIDTH/4.0, PAT_WIDTH);
100     cairo_stroke (cr);
101
102     return CAIRO_TEST_SUCCESS;
103 }
104
105 CAIRO_TEST (rotated_clip,
106             "Test clipping with non identity pattern matrix",
107             "clip", /* keywords */
108             NULL, /* requirements */
109             WIDTH, HEIGHT,
110             NULL, draw)