2 * Copyright © 2005 Red Hat, Inc.
3 * Copyright © 2006 Red Hat, Inc.
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of
10 * Red Hat, Inc. not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. Red Hat, Inc. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as
14 * is" without express or implied warranty.
16 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
19 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: Carl D. Worth <cworth@cworth.org>
27 #include "cairo-test.h"
32 static cairo_test_draw_function_t draw
;
35 "fill-and-stroke-alpha",
36 "Use a group to fill/stroke a path then blend the result with alpha onto the destination",
37 2 * SIZE
+ 4 * PAD
, SIZE
+ 2 * PAD
,
41 typedef void (*path_func_t
) (cairo_t
*cr
);
44 rectangle (cairo_t
*cr
)
46 cairo_rectangle (cr
, PAD
, PAD
, SIZE
, SIZE
);
53 PAD
+ SIZE
/ 2, PAD
+ SIZE
/ 2,
58 /* Given a path-generating function and two opaque patterns, fill and
59 * stroke the path with the patterns (to an offscreen group), then
60 * blend the result into the destination with the given alpha
64 fill_and_stroke_alpha (cairo_t
*cr
,
65 path_func_t path_func
,
66 cairo_pattern_t
*fill_pattern
,
67 cairo_pattern_t
*stroke_pattern
,
70 cairo_push_group (cr
);
73 cairo_set_source (cr
, fill_pattern
);
74 cairo_fill_preserve (cr
);
75 cairo_set_source (cr
, stroke_pattern
);
78 cairo_pop_group_to_source (cr
);
79 cairo_paint_with_alpha (cr
, alpha
);
82 static cairo_test_status_t
83 draw (cairo_t
*cr
, int width
, int height
)
85 cairo_pattern_t
*blue
;
88 blue
= cairo_pattern_create_rgb (0.0, 0.0, 1.0);
89 red
= cairo_pattern_create_rgb (1.0, 0.0, 0.0);
91 cairo_test_paint_checkered (cr
);
93 fill_and_stroke_alpha (cr
, rectangle
, blue
, red
, 0.5);
95 cairo_translate (cr
, SIZE
+ 2 * PAD
, 0);
97 fill_and_stroke_alpha (cr
, circle
, red
, blue
, 0.5);
99 cairo_pattern_destroy (blue
);
100 cairo_pattern_destroy (red
);
102 return CAIRO_TEST_SUCCESS
;
108 return cairo_test (&test
);