e05ff8c2e0b37405164f724a55b38f127bfaebd1
[framework/graphics/cairo.git] / test / rectilinear-stroke.c
1 /*
2  * Copyright © 2006 Red Hat, Inc.
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: Carl D. Worth <cworth@cworth.org>
25  */
26
27 #include "cairo-test.h"
28
29 #define SIZE 25
30
31 static cairo_test_status_t
32 draw (cairo_t *cr, int width, int height)
33 {
34     /* Paint background white, then draw in black. */
35     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
36     cairo_paint (cr);
37     cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
38
39     cairo_set_line_width (cr, 1.0);
40     cairo_translate (cr, 1, 1);
41
42     /* Draw everything first with square caps. */
43     cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
44
45     /* Draw horizontal and vertical segments, each in both
46      * directions. */
47     cairo_move_to     (cr,  4.5,  0.5);
48     cairo_rel_line_to (cr,  2.0,  0.0);
49
50     cairo_move_to     (cr, 10.5,  4.5);
51     cairo_rel_line_to (cr,  0.0,  2.0);
52
53     cairo_move_to     (cr,  6.5, 10.5);
54     cairo_rel_line_to (cr, -2.0,  0.0);
55
56     cairo_move_to     (cr,  0.5,  6.5);
57     cairo_rel_line_to (cr,  0.0, -2.0);
58
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);
63
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);
67
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);
71
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);
75
76     /* Draw a closed-path rectangle */
77     cairo_rectangle   (cr, 0.5, 12.5, 10.0, 10.0);
78
79     cairo_stroke (cr);
80
81     cairo_translate (cr, 12, 0);
82
83     /* Now draw the same results, but with butt caps. */
84     cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
85
86     /* Draw horizontal and vertical segments, each in both
87      * directions. */
88     cairo_move_to     (cr,  4.0,  0.5);
89     cairo_rel_line_to (cr,  3.0,  0.0);
90
91     cairo_move_to     (cr, 10.5,  4.0);
92     cairo_rel_line_to (cr,  0.0,  3.0);
93
94     cairo_move_to     (cr,  7.0, 10.5);
95     cairo_rel_line_to (cr, -3.0,  0.0);
96
97     cairo_move_to     (cr,  0.5,  7.0);
98     cairo_rel_line_to (cr,  0.0, -3.0);
99
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);
104
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);
108
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);
112
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);
116
117     /* Draw a closed-path rectangle */
118     cairo_rectangle   (cr, 0.5, 12.5, 10.0, 10.0);
119
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
123      * completely */
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);
127
128     cairo_stroke (cr);
129
130     return CAIRO_TEST_SUCCESS;
131 }
132
133 CAIRO_TEST (rectilinear_stroke,
134             "Test rectilinear stroke operations (covering only whole pixels)",
135             "stroke", /* keywords */
136             NULL, /* requirements */
137             SIZE, SIZE,
138             NULL, draw)
139