1
/*
2
 * Copyright © 2010 M Joonas Pihlaja
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
 * Author: M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
25
 */
26
#include "cairo-test.h"
27

            
28
/* Test that we can simultaneously downscale and extend a surface
29
 * pattern.  Reported by Franz Schmid to the cairo mailing list as a
30
 * regression in 1.9.6:
31
 *
32
 * https://lists.cairographics.org/archives/cairo/2010-February/019492.html
33
 */
34

            
35
static cairo_test_status_t
36
12
draw_with_extend (cairo_t *cr, int w, int h, cairo_extend_t extend)
37
{
38
    cairo_pattern_t *pattern;
39
12
    cairo_set_source_rgb (cr, 1,1,1);
40
12
    cairo_paint (cr);
41

            
42
12
    cairo_save (cr);
43

            
44
    /* When the destination surface is created by cairo-test-suite to
45
     * test device-offset, it is bigger than w x h. This test expects
46
     * the group to have a size which is exactly w x h, so it must
47
     * clip to the this rectangle to guarantee that the group will
48
     * have the correct size.
49
     */
50
12
    cairo_rectangle (cr, 0, 0, w, h);
51
12
    cairo_clip (cr);
52

            
53
12
    cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR); {
54
        /* A two by two checkerboard with black, red and yellow
55
         * cells. */
56
12
        cairo_set_source_rgb (cr, 1,0,0);
57
12
        cairo_rectangle (cr, w/2, 0, w-w/2, h/2);
58
12
        cairo_fill (cr);
59
12
        cairo_set_source_rgb (cr, 1,1,0);
60
12
        cairo_rectangle (cr, 0, h/2, w/2, h-h/2);
61
12
        cairo_fill (cr);
62
    }
63
12
    pattern = cairo_pop_group (cr);
64
12
    cairo_pattern_set_extend(pattern, extend);
65

            
66
12
    cairo_restore (cr);
67

            
68
12
    cairo_scale (cr, 0.5, 0.5);
69
12
    cairo_set_source (cr, pattern);
70
12
    cairo_paint (cr);
71

            
72
12
    cairo_pattern_destroy (pattern);
73
12
    return CAIRO_TEST_SUCCESS;
74
}
75

            
76
static cairo_test_status_t
77
3
draw_repeat (cairo_t *cr, int w, int h)
78
{
79
3
    return draw_with_extend (cr, w, h, CAIRO_EXTEND_REPEAT);
80
}
81
static cairo_test_status_t
82
3
draw_none (cairo_t *cr, int w, int h)
83
{
84
3
    return draw_with_extend (cr, w, h, CAIRO_EXTEND_NONE);
85
}
86
static cairo_test_status_t
87
3
draw_reflect (cairo_t *cr, int w, int h)
88
{
89
3
    return draw_with_extend (cr, w, h, CAIRO_EXTEND_REFLECT);
90
}
91
static cairo_test_status_t
92
3
draw_pad (cairo_t *cr, int w, int h)
93
{
94
3
    return draw_with_extend (cr, w, h, CAIRO_EXTEND_PAD);
95
}
96

            
97
1
CAIRO_TEST (surface_pattern_scale_down_extend_repeat,
98
	    "Test interaction of downscaling a surface pattern and extend-repeat",
99
            "pattern, transform, extend", /* keywords */
100
	    NULL, /* requirements */
101
            100, 100,
102
	    NULL, draw_repeat)
103
1
CAIRO_TEST (surface_pattern_scale_down_extend_none,
104
	    "Test interaction of downscaling a surface pattern and extend-none",
105
            "pattern, transform, extend", /* keywords */
106
	    NULL, /* requirements */
107
            100, 100,
108
	    NULL, draw_none)
109
1
CAIRO_TEST (surface_pattern_scale_down_extend_reflect,
110
	    "Test interaction of downscaling a surface pattern and extend-reflect",
111
            "pattern, transform, extend", /* keywords */
112
	    NULL, /* requirements */
113
            100, 100,
114
	    NULL, draw_reflect)
115
1
CAIRO_TEST (surface_pattern_scale_down_extend_pad,
116
	    "Test interaction of downscaling a surface pattern and extend-pad",
117
            "pattern, transform, extend", /* keywords */
118
	    NULL, /* requirements */
119
            100, 100,
120
	    NULL, draw_pad)