1
/*
2
 * Copyright © 2011 Nis Martensen
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

            
25
#include "cairo-test.h"
26

            
27
#define OPERATORS_COUNT 29
28
#define WIDTH 160
29
#define HEIGHT 120
30

            
31
static void
32
87
example (cairo_t *cr, const char *name)
33
{
34
87
    cairo_save (cr);
35
87
    cairo_push_group_with_content (cr, cairo_surface_get_content (cairo_get_target (cr)));
36

            
37
87
    cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
38
87
    cairo_clip (cr);
39

            
40
87
    cairo_rectangle (cr, 0, 0, 120, 90);
41
87
    cairo_set_source_rgba (cr, 0.7, 0, 0, 0.8);
42
87
    cairo_fill (cr);
43

            
44
87
    if (strcmp (name, "clear") == 0)
45
3
	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
46

            
47
84
    else if (strcmp (name, "source") == 0)
48
3
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
49
81
    else if (strcmp (name, "over") == 0)
50
3
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
51
78
    else if (strcmp (name, "in") == 0)
52
3
	cairo_set_operator (cr, CAIRO_OPERATOR_IN);
53
75
    else if (strcmp (name, "out") == 0)
54
3
	cairo_set_operator (cr, CAIRO_OPERATOR_OUT);
55
72
    else if (strcmp (name, "atop") == 0)
56
3
	cairo_set_operator (cr, CAIRO_OPERATOR_ATOP);
57

            
58
69
    else if (strcmp (name, "dest") == 0)
59
3
	cairo_set_operator (cr, CAIRO_OPERATOR_DEST);
60
66
    else if (strcmp (name, "dest_over") == 0)
61
3
	cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
62
63
    else if (strcmp (name, "dest_in") == 0)
63
3
	cairo_set_operator (cr, CAIRO_OPERATOR_DEST_IN);
64
60
    else if (strcmp (name, "dest_out") == 0)
65
3
	cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OUT);
66
57
    else if (strcmp (name, "dest_atop") == 0)
67
3
	cairo_set_operator (cr, CAIRO_OPERATOR_DEST_ATOP);
68

            
69
54
    else if (strcmp (name, "xor") == 0)
70
3
	cairo_set_operator (cr, CAIRO_OPERATOR_XOR);
71
51
    else if (strcmp (name, "add") == 0)
72
3
	cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
73
48
    else if (strcmp (name, "saturate") == 0)
74
3
	cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
75
45
    else if (strcmp (name, "multiply") == 0)
76
3
	cairo_set_operator (cr, CAIRO_OPERATOR_MULTIPLY);
77
42
    else if (strcmp (name, "screen") == 0)
78
3
	cairo_set_operator (cr, CAIRO_OPERATOR_SCREEN);
79
39
    else if (strcmp (name, "overlay") == 0)
80
3
	cairo_set_operator (cr, CAIRO_OPERATOR_OVERLAY);
81
36
    else if (strcmp (name, "darken") == 0)
82
3
	cairo_set_operator (cr, CAIRO_OPERATOR_DARKEN);
83
33
    else if (strcmp (name, "lighten") == 0)
84
3
	cairo_set_operator (cr, CAIRO_OPERATOR_LIGHTEN);
85
30
    else if (strcmp (name, "color_dodge") == 0)
86
3
	cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
87
27
    else if (strcmp (name, "color_burn") == 0)
88
3
	cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_BURN);
89
24
    else if (strcmp (name, "hard_light") == 0)
90
3
	cairo_set_operator (cr, CAIRO_OPERATOR_HARD_LIGHT);
91
21
    else if (strcmp (name, "soft_light") == 0)
92
3
	cairo_set_operator (cr, CAIRO_OPERATOR_SOFT_LIGHT);
93
18
    else if (strcmp (name, "difference") == 0)
94
3
	cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
95
15
    else if (strcmp (name, "exclusion") == 0)
96
3
	cairo_set_operator (cr, CAIRO_OPERATOR_EXCLUSION);
97
12
    else if (strcmp (name, "hsl_hue") == 0)
98
3
	cairo_set_operator (cr, CAIRO_OPERATOR_HSL_HUE);
99
9
    else if (strcmp (name, "hsl_saturation") == 0)
100
3
	cairo_set_operator (cr, CAIRO_OPERATOR_HSL_SATURATION);
101
6
    else if (strcmp (name, "hsl_color") == 0)
102
3
	cairo_set_operator (cr, CAIRO_OPERATOR_HSL_COLOR);
103
3
    else if (strcmp (name, "hsl_luminosity") == 0)
104
3
	cairo_set_operator (cr, CAIRO_OPERATOR_HSL_LUMINOSITY);
105

            
106
87
    cairo_rectangle (cr, 40, 30, 120, 90);
107
87
    cairo_set_source_rgba (cr, 0, 0, 0.9, 0.4);
108
87
    cairo_fill (cr);
109

            
110
87
    cairo_pattern_t *pattern = cairo_pop_group (cr);
111
87
    cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
112
87
    cairo_clip (cr);
113
    // Make problems with CAIRO_CONTENT_COLOR visible
114
87
    if (cairo_surface_get_content (cairo_get_target (cr)) == CAIRO_CONTENT_COLOR) {
115
58
	cairo_set_source_rgb (cr, 1, 1, 1);
116
58
	cairo_paint (cr);
117
    }
118
87
    cairo_set_source (cr, pattern);
119
87
    cairo_pattern_destroy (pattern);
120
87
    cairo_paint (cr);
121
87
    cairo_restore (cr);
122

            
123
87
    cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
124
			    CAIRO_FONT_SLANT_NORMAL,
125
			    CAIRO_FONT_WEIGHT_NORMAL);
126
87
    cairo_set_font_size (cr, 17);
127
87
    cairo_move_to (cr, WIDTH + 20, 70);
128
87
    cairo_set_source_rgb (cr, 1, 1, 0);
129
87
    cairo_show_text (cr, name);
130

            
131
87
    cairo_translate (cr, 0, HEIGHT);
132
87
}
133

            
134
static cairo_test_status_t
135
3
draw (cairo_t *cr, int width, int height)
136
{
137
3
    example (cr, "clear");
138

            
139
3
    example (cr, "source");
140
3
    example (cr, "over");
141
3
    example (cr, "in");
142
3
    example (cr, "out");
143
3
    example (cr, "atop");
144

            
145
3
    example (cr, "dest");
146
3
    example (cr, "dest_over");
147
3
    example (cr, "dest_in");
148
3
    example (cr, "dest_out");
149
3
    example (cr, "dest_atop");
150

            
151
3
    example (cr, "xor");
152
3
    example (cr, "add");
153
3
    example (cr, "saturate");
154

            
155
3
    example (cr, "multiply");
156
3
    example (cr, "screen");
157
3
    example (cr, "overlay");
158
3
    example (cr, "darken");
159
3
    example (cr, "lighten");
160
3
    example (cr, "color_dodge");
161
3
    example (cr, "color_burn");
162
3
    example (cr, "hard_light");
163
3
    example (cr, "soft_light");
164
3
    example (cr, "difference");
165
3
    example (cr, "exclusion");
166
3
    example (cr, "hsl_hue");
167
3
    example (cr, "hsl_saturation");
168
3
    example (cr, "hsl_color");
169
3
    example (cr, "hsl_luminosity");
170

            
171
3
    return CAIRO_TEST_SUCCESS;
172
}
173

            
174
1
CAIRO_TEST (operator_www,
175
	    "Operator samples from https://cairographics.org/operators/",
176
	    "operator", /* keywords */
177
	    NULL, /* requirements */
178
	    WIDTH * 2, HEIGHT * OPERATORS_COUNT,
179
	    NULL, draw)