2 * Copyright © 2006 Red Hat, Inc.
3 * Copyright © 2008 Chris Wilson
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Author: Carl D. Worth <cworth@cworth.org>
26 * Chris Wilson <chris@chris-wilson.co.uk>
28 * Based on the original test/rectilinear-stroke.c by Carl D. Worth.
31 #include "cairo-test.h"
36 draw_dashes (cairo_t *cr)
38 const double dash_square[4] = {4, 2, 2, 2};
39 const double dash_butt[4] = {5, 1, 3, 1};
43 cairo_set_dash (cr, dash_square, 4, 0);
45 cairo_set_line_width (cr, 1.0);
46 cairo_translate (cr, 1, 1);
48 /* Draw everything first with square caps. */
49 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
51 /* Draw horizontal and vertical segments, each in both
53 cairo_move_to (cr, 4.5, 0.5);
54 cairo_rel_line_to (cr, 2.0, 0.0);
56 cairo_move_to (cr, 10.5, 4.5);
57 cairo_rel_line_to (cr, 0.0, 2.0);
59 cairo_move_to (cr, 6.5, 10.5);
60 cairo_rel_line_to (cr, -2.0, 0.0);
62 cairo_move_to (cr, 0.5, 6.5);
63 cairo_rel_line_to (cr, 0.0, -2.0);
65 /* Draw right angle turns in four directions. */
66 cairo_move_to (cr, 0.5, 2.5);
67 cairo_rel_line_to (cr, 0.0, -2.0);
68 cairo_rel_line_to (cr, 2.0, 0.0);
70 cairo_move_to (cr, 8.5, 0.5);
71 cairo_rel_line_to (cr, 2.0, 0.0);
72 cairo_rel_line_to (cr, 0.0, 2.0);
74 cairo_move_to (cr, 10.5, 8.5);
75 cairo_rel_line_to (cr, 0.0, 2.0);
76 cairo_rel_line_to (cr, -2.0, 0.0);
78 cairo_move_to (cr, 2.5, 10.5);
79 cairo_rel_line_to (cr, -2.0, 0.0);
80 cairo_rel_line_to (cr, 0.0, -2.0);
84 /* Draw a closed-path rectangle */
85 cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0);
86 cairo_set_dash (cr, dash_square, 4, 2);
89 cairo_translate (cr, 12, 0);
91 /* Now draw the same results, but with butt caps. */
92 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
93 cairo_set_dash (cr, dash_butt, 4, 0.0);
95 /* Draw horizontal and vertical segments, each in both
97 cairo_move_to (cr, 4.0, 0.5);
98 cairo_rel_line_to (cr, 3.0, 0.0);
100 cairo_move_to (cr, 10.5, 4.0);
101 cairo_rel_line_to (cr, 0.0, 3.0);
103 cairo_move_to (cr, 7.0, 10.5);
104 cairo_rel_line_to (cr, -3.0, 0.0);
106 cairo_move_to (cr, 0.5, 7.0);
107 cairo_rel_line_to (cr, 0.0, -3.0);
109 /* Draw right angle turns in four directions. */
110 cairo_move_to (cr, 0.5, 3.0);
111 cairo_rel_line_to (cr, 0.0, -2.5);
112 cairo_rel_line_to (cr, 2.5, 0.0);
114 cairo_move_to (cr, 8.0, 0.5);
115 cairo_rel_line_to (cr, 2.5, 0.0);
116 cairo_rel_line_to (cr, 0.0, 2.5);
118 cairo_move_to (cr, 10.5, 8.0);
119 cairo_rel_line_to (cr, 0.0, 2.5);
120 cairo_rel_line_to (cr, -2.5, 0.0);
122 cairo_move_to (cr, 3.0, 10.5);
123 cairo_rel_line_to (cr, -2.5, 0.0);
124 cairo_rel_line_to (cr, 0.0, -2.5);
128 /* Draw a closed-path rectangle */
129 cairo_set_dash (cr, dash_butt, 4, 2.5);
130 cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0);
136 static cairo_test_status_t
139 /* Paint background white, then draw in black. */
140 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
143 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
147 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
148 cairo_translate (cr, 0, SIZE);
149 cairo_scale (cr, 1, -1);
154 cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
155 cairo_translate (cr, SIZE, 0);
156 cairo_scale (cr, -1, 1);
161 cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
162 cairo_translate (cr, SIZE, SIZE);
163 cairo_scale (cr, -1, -1);
167 return CAIRO_TEST_SUCCESS;
170 static cairo_test_status_t
171 aligned (cairo_t *cr, int width, int height)
173 cairo_scale (cr, 4, 2);
177 static cairo_test_status_t
178 unaligned (cairo_t *cr, int width, int height)
180 cairo_scale (cr, 3.9, 1.9);
184 CAIRO_TEST (rectilinear_dash_scale,
185 "Test dashed rectilinear stroke operations (covering only whole pixels) after scaling",
186 "stroke dash", /* keywords */
187 NULL, /* requirements */
191 CAIRO_TEST (rectilinear_dash_scale_unaligned,
192 "Test dashed rectilinear stroke operations (covering partial pixels) after scaling",
193 "stroke dash", /* keywords */
194 NULL, /* requirements */