1
/*
2
 * Copyright © 2006 Red Hat, Inc.
3
 * Copyright © 2008 Chris Wilson
4
 *
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:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
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
23
 * SOFTWARE.
24
 *
25
 * Author: Carl D. Worth <cworth@cworth.org>
26
 *         Chris Wilson <chris@chris-wilson.co.uk>
27
 *
28
 * Based on the original test/rectilinear-stroke.c by Carl D. Worth.
29
 */
30

            
31
#include "cairo-test.h"
32

            
33
#define SIZE 50
34

            
35
static void
36
12
draw_dashes (cairo_t *cr)
37
{
38
12
    const double dash_square[4] = {4, 2, 2, 2};
39
12
    const double dash_butt[4] = {5, 1, 3, 1};
40

            
41
12
    cairo_save (cr);
42

            
43
12
    cairo_set_dash (cr, dash_square, 4, 0);
44

            
45
12
    cairo_set_line_width (cr, 1.0);
46
12
    cairo_translate (cr, 1, 1);
47

            
48
    /* Draw everything first with square caps. */
49
12
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
50

            
51
    /* Draw horizontal and vertical segments, each in both
52
     * directions. */
53
12
    cairo_move_to     (cr,  4.5,  0.5);
54
12
    cairo_rel_line_to (cr,  2.0,  0.0);
55

            
56
12
    cairo_move_to     (cr, 10.5,  4.5);
57
12
    cairo_rel_line_to (cr,  0.0,  2.0);
58

            
59
12
    cairo_move_to     (cr,  6.5, 10.5);
60
12
    cairo_rel_line_to (cr, -2.0,  0.0);
61

            
62
12
    cairo_move_to     (cr,  0.5,  6.5);
63
12
    cairo_rel_line_to (cr,  0.0, -2.0);
64

            
65
    /* Draw right angle turns in four directions. */
66
12
    cairo_move_to     (cr,  0.5,  2.5);
67
12
    cairo_rel_line_to (cr,  0.0, -2.0);
68
12
    cairo_rel_line_to (cr,  2.0,  0.0);
69

            
70
12
    cairo_move_to     (cr,  8.5,  0.5);
71
12
    cairo_rel_line_to (cr,  2.0,  0.0);
72
12
    cairo_rel_line_to (cr,  0.0,  2.0);
73

            
74
12
    cairo_move_to     (cr, 10.5,  8.5);
75
12
    cairo_rel_line_to (cr,  0.0,  2.0);
76
12
    cairo_rel_line_to (cr, -2.0,  0.0);
77

            
78
12
    cairo_move_to     (cr,  2.5, 10.5);
79
12
    cairo_rel_line_to (cr, -2.0,  0.0);
80
12
    cairo_rel_line_to (cr,  0.0, -2.0);
81

            
82
12
    cairo_stroke (cr);
83

            
84
    /* Draw a closed-path rectangle */
85
12
    cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0);
86
12
    cairo_set_dash (cr, dash_square, 4, 2);
87
12
    cairo_stroke (cr);
88

            
89
12
    cairo_translate (cr, 12, 0);
90

            
91
    /* Now draw the same results, but with butt caps. */
92
12
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
93
12
    cairo_set_dash (cr, dash_butt, 4, 0.0);
94

            
95
    /* Draw horizontal and vertical segments, each in both
96
     * directions. */
97
12
    cairo_move_to     (cr,  4.0,  0.5);
98
12
    cairo_rel_line_to (cr,  3.0,  0.0);
99

            
100
12
    cairo_move_to     (cr, 10.5,  4.0);
101
12
    cairo_rel_line_to (cr,  0.0,  3.0);
102

            
103
12
    cairo_move_to     (cr,  7.0, 10.5);
104
12
    cairo_rel_line_to (cr, -3.0,  0.0);
105

            
106
12
    cairo_move_to     (cr,  0.5,  7.0);
107
12
    cairo_rel_line_to (cr,  0.0, -3.0);
108

            
109
    /* Draw right angle turns in four directions. */
110
12
    cairo_move_to     (cr,  0.5,  3.0);
111
12
    cairo_rel_line_to (cr,  0.0, -2.5);
112
12
    cairo_rel_line_to (cr,  2.5,  0.0);
113

            
114
12
    cairo_move_to     (cr,  8.0,  0.5);
115
12
    cairo_rel_line_to (cr,  2.5,  0.0);
116
12
    cairo_rel_line_to (cr,  0.0,  2.5);
117

            
118
12
    cairo_move_to     (cr, 10.5,  8.0);
119
12
    cairo_rel_line_to (cr,  0.0,  2.5);
120
12
    cairo_rel_line_to (cr, -2.5,  0.0);
121

            
122
12
    cairo_move_to     (cr,  3.0, 10.5);
123
12
    cairo_rel_line_to (cr, -2.5,  0.0);
124
12
    cairo_rel_line_to (cr,  0.0, -2.5);
125

            
126
12
    cairo_stroke (cr);
127

            
128
    /* Draw a closed-path rectangle */
129
12
    cairo_set_dash (cr, dash_butt, 4, 2.5);
130
12
    cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0);
131
12
    cairo_stroke (cr);
132

            
133
12
    cairo_restore (cr);
134
12
}
135

            
136
static cairo_test_status_t
137
3
draw (cairo_t *cr, int width, int height)
138
{
139
    /* Paint background white, then draw in black. */
140
3
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
141
3
    cairo_paint (cr);
142

            
143
3
    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
144
3
    draw_dashes (cr);
145

            
146
3
    cairo_save (cr);
147
3
    cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
148
3
    cairo_translate (cr, 0, height);
149
3
    cairo_scale (cr, 1, -1);
150
3
    draw_dashes (cr);
151
3
    cairo_restore (cr);
152

            
153
3
    cairo_save (cr);
154
3
    cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
155
3
    cairo_translate (cr, width, 0);
156
3
    cairo_scale (cr, -1, 1);
157
3
    draw_dashes (cr);
158
3
    cairo_restore (cr);
159

            
160
3
    cairo_save (cr);
161
3
    cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
162
3
    cairo_translate (cr, width, height);
163
3
    cairo_scale (cr, -1, -1);
164
3
    draw_dashes (cr);
165
3
    cairo_restore (cr);
166

            
167
3
    return CAIRO_TEST_SUCCESS;
168
}
169

            
170
1
CAIRO_TEST (rectilinear_dash,
171
	    "Test dashed rectilinear stroke operations (covering only whole pixels)",
172
	    "stroke, dash", /* keywords */
173
	    NULL, /* requirements */
174
	    SIZE, SIZE,
175
	    NULL, draw)
176