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
3
draw (cairo_t *cr, int width, int height)
40
{
41
    cairo_matrix_t m;
42

            
43
    /* make the output opaque */
44
3
    cairo_set_source_rgb (cr, 0, 0, 0);
45
3
    cairo_paint (cr);
46

            
47
3
    cairo_translate (cr, PAD, PAD);
48

            
49
3
    cairo_matrix_init_scale (&m, 2, 1.5);
50
3
    cairo_matrix_rotate (&m, 1);
51
3
    cairo_matrix_translate (&m, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
52
3
    cairo_matrix_invert (&m);
53
3
    cairo_set_matrix (cr, &m);
54

            
55
3
    cairo_rectangle (cr, 0, 0, PAT_WIDTH, PAT_HEIGHT);
56
3
    cairo_clip (cr);
57

            
58
3
    cairo_set_source_rgba (cr, 1, 0, 1, 0.5);
59
3
    cairo_rectangle (cr, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
60
3
    cairo_fill (cr);
61

            
62
3
    cairo_set_source_rgba (cr, 0, 1, 1, 0.5);
63
3
    cairo_rectangle (cr, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
64
3
    cairo_fill (cr);
65

            
66
3
    cairo_set_line_width (cr, 1);
67
3
    cairo_move_to (cr, PAT_WIDTH/6.0, 0);
68
3
    cairo_line_to (cr, 0, 0);
69
3
    cairo_line_to (cr, 0, PAT_HEIGHT/6.0);
70
3
    cairo_set_source_rgb (cr, 1, 0, 0);
71
3
    cairo_stroke (cr);
72

            
73
3
    cairo_move_to (cr, PAT_WIDTH/6.0, PAT_HEIGHT);
74
3
    cairo_line_to (cr, 0, PAT_HEIGHT);
75
3
    cairo_line_to (cr, 0, 5*PAT_HEIGHT/6.0);
76
3
    cairo_set_source_rgb (cr, 0, 1, 0);
77
3
    cairo_stroke (cr);
78

            
79
3
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, 0);
80
3
    cairo_line_to (cr, PAT_WIDTH, 0);
81
3
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/6.0);
82
3
    cairo_set_source_rgb (cr, 0, 0, 1);
83
3
    cairo_stroke (cr);
84

            
85
3
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
86
3
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT);
87
3
    cairo_line_to (cr, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
88
3
    cairo_set_source_rgb (cr, 1, 1, 0);
89
3
    cairo_stroke (cr);
90

            
91
3
    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
92
3
    cairo_set_line_width (cr, PAT_WIDTH/10.0);
93

            
94
3
    cairo_move_to (cr, 0,         PAT_HEIGHT/4.0);
95
3
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/4.0);
96
3
    cairo_stroke (cr);
97

            
98
3
    cairo_move_to (cr, PAT_WIDTH/4.0,         0);
99
3
    cairo_line_to (cr, PAT_WIDTH/4.0, PAT_WIDTH);
100
3
    cairo_stroke (cr);
101

            
102
3
    return CAIRO_TEST_SUCCESS;
103
}
104

            
105
1
CAIRO_TEST (rotated_clip,
106
	    "Test clipping with non identity pattern matrix",
107
	    "clip", /* keywords */
108
	    NULL, /* requirements */
109
	    WIDTH, HEIGHT,
110
	    NULL, draw)