2 * Copyright © 2010 M Joonas Pihlaja
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 * Author: M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
26 #include "cairo-test.h"
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:
32 * http://lists.cairographics.org/archives/cairo/2010-February/019492.html
35 static cairo_test_status_t
36 draw_with_extend (cairo_t *cr, int w, int h, cairo_extend_t extend)
38 cairo_pattern_t *pattern;
39 cairo_set_source_rgb (cr, 1,1,1);
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.
50 cairo_rectangle (cr, 0, 0, w, h);
53 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR); {
54 /* A two by two checkerboard with black, red and yellow
56 cairo_set_source_rgb (cr, 1,0,0);
57 cairo_rectangle (cr, w/2, 0, w-w/2, h/2);
59 cairo_set_source_rgb (cr, 1,1,0);
60 cairo_rectangle (cr, 0, h/2, w/2, h-h/2);
63 pattern = cairo_pop_group (cr);
64 cairo_pattern_set_extend(pattern, extend);
68 cairo_scale (cr, 0.5, 0.5);
69 cairo_set_source (cr, pattern);
72 cairo_pattern_destroy (pattern);
73 return CAIRO_TEST_SUCCESS;
76 static cairo_test_status_t
77 draw_repeat (cairo_t *cr, int w, int h)
79 return draw_with_extend (cr, w, h, CAIRO_EXTEND_REPEAT);
81 static cairo_test_status_t
82 draw_none (cairo_t *cr, int w, int h)
84 return draw_with_extend (cr, w, h, CAIRO_EXTEND_NONE);
86 static cairo_test_status_t
87 draw_reflect (cairo_t *cr, int w, int h)
89 return draw_with_extend (cr, w, h, CAIRO_EXTEND_REFLECT);
91 static cairo_test_status_t
92 draw_pad (cairo_t *cr, int w, int h)
94 return draw_with_extend (cr, w, h, CAIRO_EXTEND_PAD);
97 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 */
103 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 */
109 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 */
115 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 */