2 * Copyright © 2005 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Kristian Høgsberg <krh@redhat.com>
27 #include "cairo-test.h"
35 draw_mask (cairo_t
*cr
, int x
, int y
)
37 cairo_surface_t
*mask_surface
;
40 double width
= (int)(0.9 * WIDTH
);
41 double height
= (int)(0.9 * HEIGHT
);
45 mask_surface
= cairo_surface_create_similar (cairo_get_group_target (cr
),
48 cr2
= cairo_create (mask_surface
);
49 cairo_surface_destroy (mask_surface
);
52 cairo_set_source_rgba (cr2
, 0, 0, 0, 0); /* transparent */
53 cairo_set_operator (cr2
, CAIRO_OPERATOR_SOURCE
);
57 cairo_set_source_rgb (cr2
, 1, 1, 1); /* white */
59 cairo_arc (cr2
, 0.5 * width
, 0.5 * height
, 0.45 * height
, 0, 2 * M_PI
);
62 cairo_mask_surface (cr
, cairo_get_target (cr2
), x
, y
);
67 draw_glyphs (cairo_t
*cr
, int x
, int y
)
69 cairo_text_extents_t extents
;
71 cairo_set_font_size (cr
, 0.8 * HEIGHT
);
73 cairo_text_extents (cr
, "FG", &extents
);
75 x
+ floor ((WIDTH
- extents
.width
) / 2 + 0.5) - extents
.x_bearing
,
76 y
+ floor ((HEIGHT
- extents
.height
) / 2 + 0.5) - extents
.y_bearing
);
77 cairo_show_text (cr
, "FG");
81 draw_polygon (cairo_t
*cr
, int x
, int y
)
83 double width
= (int)(0.9 * WIDTH
);
84 double height
= (int)(0.9 * HEIGHT
);
89 cairo_move_to (cr
, x
, y
);
90 cairo_line_to (cr
, x
, y
+ height
);
91 cairo_line_to (cr
, x
+ width
/ 2, y
+ 3 * height
/ 4);
92 cairo_line_to (cr
, x
+ width
, y
+ height
);
93 cairo_line_to (cr
, x
+ width
, y
);
94 cairo_line_to (cr
, x
+ width
/ 2, y
+ height
/ 4);
95 cairo_close_path (cr
);
100 draw_rects (cairo_t
*cr
, int x
, int y
)
102 double block_width
= (int)(0.33 * WIDTH
+ 0.5);
103 double block_height
= (int)(0.33 * HEIGHT
+ 0.5);
106 for (i
= 0; i
< 3; i
++)
107 for (j
= 0; j
< 3; j
++)
108 if ((i
+ j
) % 2 == 0)
110 x
+ block_width
* i
, y
+ block_height
* j
,
111 block_width
, block_height
);
116 static void (* const draw_funcs
[])(cairo_t
*cr
, int x
, int y
) = {
123 #define N_OPERATORS (1 + CAIRO_OPERATOR_SATURATE - CAIRO_OPERATOR_CLEAR)
125 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
126 #define IMAGE_WIDTH (N_OPERATORS * (WIDTH + PAD) + PAD)
127 #define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
129 static cairo_test_draw_function_t draw
;
131 static const cairo_test_t test
= {
133 "Surface clipping with different operators",
134 IMAGE_WIDTH
, IMAGE_HEIGHT
,
138 static cairo_test_status_t
139 draw (cairo_t
*cr
, int width
, int height
)
141 const cairo_test_context_t
*ctx
= cairo_test_get_context (cr
);
144 cairo_pattern_t
*pattern
;
146 cairo_select_font_face (cr
, "Bitstream Vera Sans",
147 CAIRO_FONT_SLANT_NORMAL
,
148 CAIRO_FONT_WEIGHT_NORMAL
);
149 cairo_set_font_size (cr
, 0.9 * HEIGHT
);
151 for (j
= 0; j
< ARRAY_SIZE (draw_funcs
); j
++) {
152 for (op
= CAIRO_OPERATOR_CLEAR
; op
< N_OPERATORS
; op
++) {
153 x
= op
* (WIDTH
+ PAD
) + PAD
;
154 y
= j
* (HEIGHT
+ PAD
) + PAD
;
158 pattern
= cairo_pattern_create_linear (x
+ WIDTH
, y
,
160 cairo_pattern_add_color_stop_rgba (pattern
, 0.2,
161 0.0, 0.0, 1.0, 1.0); /* Solid blue */
162 cairo_pattern_add_color_stop_rgba (pattern
, 0.8,
163 0.0, 0.0, 1.0, 0.0); /* Transparent blue */
164 cairo_set_source (cr
, pattern
);
165 cairo_pattern_destroy (pattern
);
167 cairo_rectangle (cr
, x
, y
, WIDTH
, HEIGHT
);
170 cairo_set_operator (cr
, op
);
171 cairo_set_source_rgb (cr
, 1.0, 0.0, 0.0);
173 cairo_move_to (cr
, x
, y
);
174 cairo_line_to (cr
, x
+ WIDTH
, y
);
175 cairo_line_to (cr
, x
, y
+ HEIGHT
);
178 draw_funcs
[j
] (cr
, x
, y
);
179 if (cairo_status (cr
))
180 cairo_test_log (ctx
, "%d %d HERE!\n", op
, (int)j
);
186 if (cairo_status (cr
) != CAIRO_STATUS_SUCCESS
)
187 cairo_test_log (ctx
, "%d %d .HERE!\n", op
, (int)j
);
189 return CAIRO_TEST_SUCCESS
;
195 return cairo_test (&test
);