1
/*
2
 * Copyright © 2005 Mozilla Corporation
3
 *
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
 * Mozilla Corporation not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Mozilla Corporation makes no representations about the
12
 * suitability of this software for any purpose.  It is provided "as
13
 * is" without express or implied warranty.
14
 *
15
 * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION 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.
22
 *
23
 * Author: Vladimir Vukicevic <vladimir@pobox.com>
24
 */
25

            
26
#include "cairo-test.h"
27

            
28
#define UNIT_SIZE 100
29
#define PAD 5
30
#define INNER_PAD 10
31

            
32
#define WIDTH (UNIT_SIZE + PAD) + PAD
33
#define HEIGHT (UNIT_SIZE + PAD) + PAD
34

            
35
static cairo_test_status_t
36
3
draw (cairo_t *cr, int width, int height)
37
{
38
    cairo_pattern_t *gradient;
39
    int i, j;
40

            
41
3
    gradient = cairo_pattern_create_linear (UNIT_SIZE - (INNER_PAD*2), 0,
42
                                            UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
43
3
    cairo_pattern_add_color_stop_rgba (gradient, 0.0, 0.3, 0.3, 0.3, 1.0);
44
3
    cairo_pattern_add_color_stop_rgba (gradient, 1.0, 1.0, 1.0, 1.0, 1.0);
45

            
46
6
    for (j = 0; j < 1; j++) {
47
6
        for (i = 0; i < 1; i++) {
48
3
            double x = (i * UNIT_SIZE) + (i + 1) * PAD;
49
3
            double y = (j * UNIT_SIZE) + (j + 1) * PAD;
50

            
51
3
            cairo_save (cr);
52

            
53
3
            cairo_translate (cr, x, y);
54

            
55
            /* draw a gradient background */
56
3
            cairo_save (cr);
57
3
            cairo_translate (cr, INNER_PAD, INNER_PAD);
58
3
            cairo_new_path (cr);
59
3
            cairo_rectangle (cr, 0, 0,
60
                             UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
61
3
            cairo_set_source (cr, gradient);
62
3
            cairo_fill (cr);
63
3
            cairo_restore (cr);
64

            
65
            /* clip to the unit size */
66
3
            cairo_rectangle (cr, 0, 0,
67
                             UNIT_SIZE, UNIT_SIZE);
68
3
            cairo_clip (cr);
69

            
70
3
            cairo_rectangle (cr, 0, 0,
71
                             UNIT_SIZE, UNIT_SIZE);
72
3
            cairo_set_source_rgba (cr, 0, 0, 0, 1);
73
3
            cairo_set_line_width (cr, 2);
74
3
            cairo_stroke (cr);
75

            
76
            /* start a group */
77
3
            cairo_push_group (cr);
78

            
79
            /* draw diamond */
80
3
            cairo_move_to (cr, UNIT_SIZE / 2, 0);
81
3
            cairo_line_to (cr, UNIT_SIZE    , UNIT_SIZE / 2);
82
3
            cairo_line_to (cr, UNIT_SIZE / 2, UNIT_SIZE);
83
3
            cairo_line_to (cr, 0            , UNIT_SIZE / 2);
84
3
            cairo_close_path (cr);
85
3
            cairo_set_source_rgba (cr, 0, 0, 1, 1);
86
3
            cairo_fill (cr);
87

            
88
            /* draw circle */
89
3
            cairo_arc (cr,
90
                       UNIT_SIZE / 2, UNIT_SIZE / 2,
91
                       UNIT_SIZE / 3.5,
92
                       0, M_PI * 2);
93
3
            cairo_set_source_rgba (cr, 1, 0, 0, 1);
94
3
            cairo_fill (cr);
95

            
96
3
            cairo_pop_group_to_source (cr);
97
3
            cairo_paint_with_alpha (cr, 0.5);
98

            
99
3
            cairo_restore (cr);
100
        }
101
    }
102

            
103
3
    cairo_pattern_destroy (gradient);
104

            
105
3
    return CAIRO_TEST_SUCCESS;
106
}
107

            
108
1
CAIRO_TEST (push_group,
109
	    "Verify that cairo_push_group works.",
110
	    "group", /* keywords */
111
	    NULL, /* requirements */
112
	    WIDTH, HEIGHT,
113
	    NULL, draw)