1
/*
2
 * Copyright © 2007 Adrian Johnson
3
 *
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:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
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
22
 * SOFTWARE.
23
 *
24
 * Author: Adrian Johnson <ajohnson@redneon.com>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
#define PAT_WIDTH  120
30
#define PAT_HEIGHT 120
31
#define SIZE (PAT_WIDTH*2)
32
#define PAD 2
33
#define WIDTH (PAD + SIZE + PAD)
34
#define HEIGHT WIDTH
35

            
36

            
37
/* This test is designed to test painting a recording surface pattern with
38
 * CAIRO_EXTEND_NONE and a non identity pattern matrix.
39
 */
40
6
static cairo_pattern_t *create_pattern (cairo_t *target)
41
{
42
    cairo_surface_t *surface;
43
    cairo_pattern_t *pattern;
44
    cairo_t *cr;
45

            
46
6
    surface = cairo_surface_create_similar (cairo_get_group_target (target),
47
					    CAIRO_CONTENT_COLOR_ALPHA,
48
					    PAT_WIDTH, PAT_HEIGHT);
49
6
    cr = cairo_create (surface);
50
6
    cairo_surface_destroy (surface);
51

            
52
6
    cairo_set_source_rgba (cr, 1, 0, 1, 0.5);
53
6
    cairo_rectangle (cr, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
54
6
    cairo_fill (cr);
55

            
56
6
    cairo_set_source_rgba (cr, 0, 1, 1, 0.5);
57
6
    cairo_rectangle (cr, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
58
6
    cairo_fill (cr);
59

            
60
6
    cairo_set_line_width (cr, 1);
61
6
    cairo_move_to (cr, PAT_WIDTH/6.0, 0);
62
6
    cairo_line_to (cr, 0, 0);
63
6
    cairo_line_to (cr, 0, PAT_HEIGHT/6.0);
64
6
    cairo_set_source_rgb (cr, 1, 0, 0);
65
6
    cairo_stroke (cr);
66
6
    cairo_move_to (cr, PAT_WIDTH/6.0, PAT_HEIGHT);
67
6
    cairo_line_to (cr, 0, PAT_HEIGHT);
68
6
    cairo_line_to (cr, 0, 5*PAT_HEIGHT/6.0);
69
6
    cairo_set_source_rgb (cr, 0, 1, 0);
70
6
    cairo_stroke (cr);
71
6
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, 0);
72
6
    cairo_line_to (cr, PAT_WIDTH, 0);
73
6
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/6.0);
74
6
    cairo_set_source_rgb (cr, 0, 0, 1);
75
6
    cairo_stroke (cr);
76
6
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
77
6
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT);
78
6
    cairo_line_to (cr, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
79
6
    cairo_set_source_rgb (cr, 1, 1, 0);
80
6
    cairo_stroke (cr);
81

            
82
6
    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
83
6
    cairo_set_line_width (cr, PAT_WIDTH/10.0);
84

            
85
6
    cairo_move_to (cr, 0,         PAT_HEIGHT/4.0);
86
6
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/4.0);
87
6
    cairo_stroke (cr);
88

            
89
6
    cairo_move_to (cr, PAT_WIDTH/4.0,         0);
90
6
    cairo_line_to (cr, PAT_WIDTH/4.0, PAT_WIDTH);
91
6
    cairo_stroke (cr);
92

            
93
6
    pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
94
6
    cairo_destroy (cr);
95

            
96
6
    return pattern;
97
}
98

            
99
static cairo_test_status_t
100
3
over (cairo_t *cr, int width, int height)
101
{
102
    cairo_pattern_t *pattern;
103
    cairo_matrix_t   mat;
104

            
105
3
    cairo_translate (cr, PAD, PAD);
106

            
107
3
    pattern = create_pattern (cr);
108

            
109
3
    cairo_matrix_init_identity (&mat);
110
3
    cairo_matrix_scale (&mat, 2, 1.5);
111
3
    cairo_matrix_rotate (&mat, 1);
112
3
    cairo_matrix_translate (&mat, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
113
3
    cairo_pattern_set_matrix (pattern, &mat);
114
3
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
115

            
116
3
    cairo_set_source (cr, pattern);
117
3
    cairo_paint (cr);
118

            
119
3
    cairo_pattern_destroy (pattern);
120

            
121
3
    return CAIRO_TEST_SUCCESS;
122
}
123

            
124
static cairo_test_status_t
125
3
source (cairo_t *cr, int width, int height)
126
{
127
    cairo_pattern_t *pattern;
128
    cairo_matrix_t   mat;
129

            
130
3
    cairo_translate (cr, PAD, PAD);
131

            
132
3
    pattern = create_pattern (cr);
133

            
134
3
    cairo_matrix_init_identity (&mat);
135
3
    cairo_matrix_scale (&mat, 2, 1.5);
136
3
    cairo_matrix_rotate (&mat, 1);
137
3
    cairo_matrix_translate (&mat, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
138
3
    cairo_pattern_set_matrix (pattern, &mat);
139
3
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
140

            
141
3
    cairo_set_source (cr, pattern);
142
3
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
143
3
    cairo_paint (cr);
144

            
145
3
    cairo_pattern_destroy (pattern);
146

            
147
3
    return CAIRO_TEST_SUCCESS;
148
}
149

            
150
1
CAIRO_TEST (recording_surface_over,
151
	    "Paint recording surface pattern with non identity pattern matrix",
152
	    "recording", /* keywords */
153
	    NULL, /* requirements */
154
	    WIDTH, HEIGHT,
155
	    NULL, over)
156

            
157
1
CAIRO_TEST (recording_surface_source,
158
	    "Paint recording surface pattern with non identity pattern matrix",
159
	    "recording", /* keywords */
160
	    NULL, /* requirements */
161
	    WIDTH, HEIGHT,
162
	    NULL, source)