1
/*
2
 * Copyright © 2019 Uli Schlachter
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
/* This is basically gears.shape.arrow */
28
static void
29
3
shape (cairo_t *cr, double width, double height)
30
{
31
3
    double shaft_length = height / 2;
32
3
    double shaft_width = width / 2;
33
3
    double head_width = width;
34
3
    double head_length = height - shaft_length;
35

            
36
3
    cairo_move_to (cr, width / 2, 0);
37
3
    cairo_rel_line_to (cr, head_width / 2, head_length);
38
3
    cairo_rel_line_to (cr, -(head_width - shaft_width) / 2, 0);
39
3
    cairo_rel_line_to (cr, 0, shaft_length);
40
3
    cairo_rel_line_to (cr, -shaft_width, 0);
41
3
    cairo_rel_line_to (cr, 0, -shaft_length);
42
3
    cairo_rel_line_to (cr, -(head_width - shaft_width) / 2, 0);
43
3
    cairo_close_path (cr);
44
3
}
45

            
46
/* This is basically the drawing routine of wibox.container.background */
47
static cairo_test_status_t
48
3
draw (cairo_t *cr, int width, int height)
49
{
50
3
    double bw = 1.5;
51

            
52
3
    cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
53

            
54
    /* Draw background */
55
3
    cairo_set_source_rgb (cr, 0, 0, 1);
56
3
    cairo_paint (cr);
57

            
58
    /* Create shape */
59
3
    cairo_translate (cr, bw, bw);
60
3
    shape (cr, width - 2 * bw, height - 2 * bw);
61
3
    cairo_translate (cr, -bw, -bw);
62

            
63
    /* Now do the border */
64

            
65
3
    cairo_push_group_with_content (cr, CAIRO_CONTENT_ALPHA);
66

            
67
    /* Mark everything as "is border" */
68
3
    cairo_set_source_rgba (cr, 0, 0, 0, 1);
69
3
    cairo_paint (cr);
70

            
71
    /* Remove inside of the shape */
72
3
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
73
3
    cairo_set_source_rgba (cr, 0, 0, 0, 0);
74
3
    cairo_fill_preserve (cr);
75

            
76
3
    cairo_pattern_t *mask = cairo_pop_group (cr);
77

            
78
    /* Now actually draw the border via the mask */
79
3
    cairo_set_source_rgb (cr, 1, 0, 0);
80
3
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
81
3
    cairo_mask (cr, mask);
82

            
83
3
    cairo_pattern_destroy (mask);
84

            
85
    /* We now have the right content in a temporary surface. Copy it to the
86
     * target surface. Needs another mask.
87
     */
88
3
    cairo_push_group_with_content (cr, CAIRO_CONTENT_ALPHA);
89

            
90
3
    cairo_set_line_width (cr, 2 * bw);
91
3
    cairo_set_source_rgba (cr, 0, 0, 0, 1);
92
3
    cairo_stroke_preserve (cr);
93
3
    cairo_fill (cr);
94

            
95
3
    mask = cairo_pop_group (cr);
96
3
    cairo_pop_group_to_source (cr);
97

            
98
3
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
99
3
    cairo_mask (cr, mask);
100

            
101
3
    cairo_pattern_destroy (mask);
102

            
103
3
    return CAIRO_TEST_SUCCESS;
104
}
105

            
106
1
CAIRO_TEST (bug_361,
107
	    "Bug 361 (Problem with SVG backend and masks)",
108
	    "mask, operator", /* keywords */
109
	    NULL, /* requirements */
110
	    100, 100,
111
	    NULL, draw)