2 * Copyright © 2006 Red Hat, Inc.
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: Carl D. Worth <cworth@cworth.org>
27 #include "cairo-test.h"
31 static cairo_test_status_t
32 draw (cairo_t *cr, int width, int height)
34 /* Paint background white, then draw in black. */
35 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
37 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
39 cairo_set_line_width (cr, 1.0);
40 cairo_translate (cr, 1, 1);
42 /* Draw everything first with square caps. */
43 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
45 /* Draw horizontal and vertical segments, each in both
47 cairo_move_to (cr, 4.5, 0.5);
48 cairo_rel_line_to (cr, 2.0, 0.0);
50 cairo_move_to (cr, 10.5, 4.5);
51 cairo_rel_line_to (cr, 0.0, 2.0);
53 cairo_move_to (cr, 6.5, 10.5);
54 cairo_rel_line_to (cr, -2.0, 0.0);
56 cairo_move_to (cr, 0.5, 6.5);
57 cairo_rel_line_to (cr, 0.0, -2.0);
59 /* Draw right angle turns in four directions. */
60 cairo_move_to (cr, 0.5, 2.5);
61 cairo_rel_line_to (cr, 0.0, -2.0);
62 cairo_rel_line_to (cr, 2.0, 0.0);
64 cairo_move_to (cr, 8.5, 0.5);
65 cairo_rel_line_to (cr, 2.0, 0.0);
66 cairo_rel_line_to (cr, 0.0, 2.0);
68 cairo_move_to (cr, 10.5, 8.5);
69 cairo_rel_line_to (cr, 0.0, 2.0);
70 cairo_rel_line_to (cr, -2.0, 0.0);
72 cairo_move_to (cr, 2.5, 10.5);
73 cairo_rel_line_to (cr, -2.0, 0.0);
74 cairo_rel_line_to (cr, 0.0, -2.0);
76 /* Draw a closed-path rectangle */
77 cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0);
81 cairo_translate (cr, 12, 0);
83 /* Now draw the same results, but with butt caps. */
84 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
86 /* Draw horizontal and vertical segments, each in both
88 cairo_move_to (cr, 4.0, 0.5);
89 cairo_rel_line_to (cr, 3.0, 0.0);
91 cairo_move_to (cr, 10.5, 4.0);
92 cairo_rel_line_to (cr, 0.0, 3.0);
94 cairo_move_to (cr, 7.0, 10.5);
95 cairo_rel_line_to (cr, -3.0, 0.0);
97 cairo_move_to (cr, 0.5, 7.0);
98 cairo_rel_line_to (cr, 0.0, -3.0);
100 /* Draw right angle turns in four directions. */
101 cairo_move_to (cr, 0.5, 3.0);
102 cairo_rel_line_to (cr, 0.0, -2.5);
103 cairo_rel_line_to (cr, 2.5, 0.0);
105 cairo_move_to (cr, 8.0, 0.5);
106 cairo_rel_line_to (cr, 2.5, 0.0);
107 cairo_rel_line_to (cr, 0.0, 2.5);
109 cairo_move_to (cr, 10.5, 8.0);
110 cairo_rel_line_to (cr, 0.0, 2.5);
111 cairo_rel_line_to (cr, -2.5, 0.0);
113 cairo_move_to (cr, 3.0, 10.5);
114 cairo_rel_line_to (cr, -2.5, 0.0);
115 cairo_rel_line_to (cr, 0.0, -2.5);
117 /* Draw a closed-path rectangle */
118 cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0);
120 /* Draw a path that is rectilinear initially, but not completely */
121 /* We draw this out of the target window. The bug that caused this
122 * addition was leaks if part of the path was rectilinear but not
124 cairo_move_to (cr, 3.0, 30.5);
125 cairo_rel_line_to (cr, -2.5, 0.0);
126 cairo_rel_line_to (cr, +2.5, +2.5);
130 return CAIRO_TEST_SUCCESS;
133 CAIRO_TEST (rectilinear_stroke,
134 "Test rectilinear stroke operations (covering only whole pixels)",
135 "stroke", /* keywords */
136 NULL, /* requirements */