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
3
draw (cairo_t *cr, int width, int height)
33
{
34
    /* Paint background white, then draw in black. */
35
3
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
36
3
    cairo_paint (cr);
37
3
    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
38

            
39
3
    cairo_set_line_width (cr, 1.0);
40
3
    cairo_translate (cr, 1, 1);
41

            
42
    /* Draw everything first with square caps. */
43
3
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
44

            
45
    /* Draw horizontal and vertical segments, each in both
46
     * directions. */
47
3
    cairo_move_to     (cr,  4.5,  0.5);
48
3
    cairo_rel_line_to (cr,  2.0,  0.0);
49

            
50
3
    cairo_move_to     (cr, 10.5,  4.5);
51
3
    cairo_rel_line_to (cr,  0.0,  2.0);
52

            
53
3
    cairo_move_to     (cr,  6.5, 10.5);
54
3
    cairo_rel_line_to (cr, -2.0,  0.0);
55

            
56
3
    cairo_move_to     (cr,  0.5,  6.5);
57
3
    cairo_rel_line_to (cr,  0.0, -2.0);
58

            
59
    /* Draw right angle turns in four directions. */
60
3
    cairo_move_to     (cr,  0.5,  2.5);
61
3
    cairo_rel_line_to (cr,  0.0, -2.0);
62
3
    cairo_rel_line_to (cr,  2.0,  0.0);
63

            
64
3
    cairo_move_to     (cr,  8.5,  0.5);
65
3
    cairo_rel_line_to (cr,  2.0,  0.0);
66
3
    cairo_rel_line_to (cr,  0.0,  2.0);
67

            
68
3
    cairo_move_to     (cr, 10.5,  8.5);
69
3
    cairo_rel_line_to (cr,  0.0,  2.0);
70
3
    cairo_rel_line_to (cr, -2.0,  0.0);
71

            
72
3
    cairo_move_to     (cr,  2.5, 10.5);
73
3
    cairo_rel_line_to (cr, -2.0,  0.0);
74
3
    cairo_rel_line_to (cr,  0.0, -2.0);
75

            
76
    /* Draw a closed-path rectangle */
77
3
    cairo_rectangle   (cr, 0.5, 12.5, 10.0, 10.0);
78

            
79
3
    cairo_stroke (cr);
80

            
81
3
    cairo_translate (cr, 12, 0);
82

            
83
    /* Now draw the same results, but with butt caps. */
84
3
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
85

            
86
    /* Draw horizontal and vertical segments, each in both
87
     * directions. */
88
3
    cairo_move_to     (cr,  4.0,  0.5);
89
3
    cairo_rel_line_to (cr,  3.0,  0.0);
90

            
91
3
    cairo_move_to     (cr, 10.5,  4.0);
92
3
    cairo_rel_line_to (cr,  0.0,  3.0);
93

            
94
3
    cairo_move_to     (cr,  7.0, 10.5);
95
3
    cairo_rel_line_to (cr, -3.0,  0.0);
96

            
97
3
    cairo_move_to     (cr,  0.5,  7.0);
98
3
    cairo_rel_line_to (cr,  0.0, -3.0);
99

            
100
    /* Draw right angle turns in four directions. */
101
3
    cairo_move_to     (cr,  0.5,  3.0);
102
3
    cairo_rel_line_to (cr,  0.0, -2.5);
103
3
    cairo_rel_line_to (cr,  2.5,  0.0);
104

            
105
3
    cairo_move_to     (cr,  8.0,  0.5);
106
3
    cairo_rel_line_to (cr,  2.5,  0.0);
107
3
    cairo_rel_line_to (cr,  0.0,  2.5);
108

            
109
3
    cairo_move_to     (cr, 10.5,  8.0);
110
3
    cairo_rel_line_to (cr,  0.0,  2.5);
111
3
    cairo_rel_line_to (cr, -2.5,  0.0);
112

            
113
3
    cairo_move_to     (cr,  3.0, 10.5);
114
3
    cairo_rel_line_to (cr, -2.5,  0.0);
115
3
    cairo_rel_line_to (cr,  0.0, -2.5);
116

            
117
    /* Draw a closed-path rectangle */
118
3
    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
3
    cairo_move_to     (cr,  3.0, 30.5);
125
3
    cairo_rel_line_to (cr, -2.5,  0.0);
126
3
    cairo_rel_line_to (cr, +2.5, +2.5);
127

            
128
3
    cairo_stroke (cr);
129

            
130
3
    return CAIRO_TEST_SUCCESS;
131
}
132

            
133
1
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