2 * Copyright © 2007 Adrian Johnson
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: Adrian Johnson <ajohnson@redneon.com>
27 #include "cairo-test.h"
30 #define PAT_HEIGHT 120
31 #define SIZE (PAT_WIDTH*2)
33 #define WIDTH (PAD + SIZE + PAD)
37 /* This test is designed to test painting a recording surface pattern with
38 * CAIRO_EXTEND_NONE and a non identity pattern matrix.
40 static cairo_pattern_t *create_pattern (cairo_t *target)
42 cairo_surface_t *surface;
43 cairo_pattern_t *pattern;
46 surface = cairo_surface_create_similar (cairo_get_group_target (target),
47 CAIRO_CONTENT_COLOR_ALPHA,
48 PAT_WIDTH, PAT_HEIGHT);
49 cr = cairo_create (surface);
50 cairo_surface_destroy (surface);
52 cairo_set_source_rgba (cr, 1, 0, 1, 0.5);
53 cairo_rectangle (cr, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
56 cairo_set_source_rgba (cr, 0, 1, 1, 0.5);
57 cairo_rectangle (cr, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
60 cairo_set_line_width (cr, 1);
61 cairo_move_to (cr, PAT_WIDTH/6.0, 0);
62 cairo_line_to (cr, 0, 0);
63 cairo_line_to (cr, 0, PAT_HEIGHT/6.0);
64 cairo_set_source_rgb (cr, 1, 0, 0);
66 cairo_move_to (cr, PAT_WIDTH/6.0, PAT_HEIGHT);
67 cairo_line_to (cr, 0, PAT_HEIGHT);
68 cairo_line_to (cr, 0, 5*PAT_HEIGHT/6.0);
69 cairo_set_source_rgb (cr, 0, 1, 0);
71 cairo_move_to (cr, 5*PAT_WIDTH/6.0, 0);
72 cairo_line_to (cr, PAT_WIDTH, 0);
73 cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/6.0);
74 cairo_set_source_rgb (cr, 0, 0, 1);
76 cairo_move_to (cr, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
77 cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT);
78 cairo_line_to (cr, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
79 cairo_set_source_rgb (cr, 1, 1, 0);
82 cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
83 cairo_set_line_width (cr, PAT_WIDTH/10.0);
85 cairo_move_to (cr, 0, PAT_HEIGHT/4.0);
86 cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/4.0);
89 cairo_move_to (cr, PAT_WIDTH/4.0, 0);
90 cairo_line_to (cr, PAT_WIDTH/4.0, PAT_WIDTH);
93 pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
99 static cairo_test_status_t
100 over (cairo_t *cr, int width, int height)
102 cairo_pattern_t *pattern;
105 cairo_translate (cr, PAD, PAD);
107 pattern = create_pattern (cr);
109 cairo_matrix_init_identity (&mat);
110 cairo_matrix_scale (&mat, 2, 1.5);
111 cairo_matrix_rotate (&mat, 1);
112 cairo_matrix_translate (&mat, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
113 cairo_pattern_set_matrix (pattern, &mat);
114 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
116 cairo_set_source (cr, pattern);
119 cairo_pattern_destroy (pattern);
121 return CAIRO_TEST_SUCCESS;
124 static cairo_test_status_t
125 source (cairo_t *cr, int width, int height)
127 cairo_pattern_t *pattern;
130 cairo_translate (cr, PAD, PAD);
132 pattern = create_pattern (cr);
134 cairo_matrix_init_identity (&mat);
135 cairo_matrix_scale (&mat, 2, 1.5);
136 cairo_matrix_rotate (&mat, 1);
137 cairo_matrix_translate (&mat, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
138 cairo_pattern_set_matrix (pattern, &mat);
139 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
141 cairo_set_source (cr, pattern);
142 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
145 cairo_pattern_destroy (pattern);
147 return CAIRO_TEST_SUCCESS;
150 CAIRO_TEST (recording_surface_over,
151 "Paint recording surface pattern with non identity pattern matrix",
152 "recording", /* keywords */
153 NULL, /* requirements */
157 CAIRO_TEST (recording_surface_source,
158 "Paint recording surface pattern with non identity pattern matrix",
159 "recording", /* keywords */
160 NULL, /* requirements */