1
/*
2
 * Copyright © 2006 Jeff Muizelaar
3
 *
4
 * Permission to use, copy, modify, distribute, and sell this software
5
 * and its documentation for any purpose is hereby granted without
6
 * fee, provided that the above copyright notice appear in all copies
7
 * and that both that copyright notice and this permission notice
8
 * appear in supporting documentation, and that the name of
9
 * Jeff Muizelaar not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Jeff Muizelaar makes no representations about the
12
 * suitability of this software for any purpose.  It is provided "as
13
 * is" without express or implied warranty.
14
 *
15
 * JEFF MUIZELAAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL JEFF MUIZELAAR BE LIABLE FOR ANY SPECIAL,
18
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 *
23
 * Author: Jeff Muizelaar <jeff@infidigm.net>
24
 */
25

            
26
#include "cairo-test.h"
27

            
28
#define PAD 3.0
29
#define LINE_WIDTH 6.0
30

            
31
static cairo_test_status_t
32
3
draw (cairo_t *cr, int width, int height)
33
{
34
3
    const cairo_line_cap_t cap[] = { CAIRO_LINE_CAP_ROUND, CAIRO_LINE_CAP_SQUARE, CAIRO_LINE_CAP_BUTT };
35
    size_t i;
36
3
    double dash[] = {2, 2};
37
3
    double dash_long[] = {6, 6};
38

            
39
3
    cairo_set_source_rgb (cr, 1, 0, 0);
40

            
41
12
    for (i = 0; i < ARRAY_LENGTH (cap); i++) {
42
9
	cairo_save (cr);
43

            
44
9
	cairo_set_line_cap (cr, cap[i]);
45

            
46
	/* simple degenerate paths */
47
9
	cairo_set_line_width (cr, LINE_WIDTH);
48
9
	cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
49
9
	cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
50
9
	cairo_stroke (cr);
51

            
52
9
	cairo_translate (cr, 0, 3*PAD);
53
9
	cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
54
9
	cairo_close_path (cr);
55
9
	cairo_stroke (cr);
56

            
57
	/* degenerate paths starting with dash on */
58
9
	cairo_set_dash (cr, dash, 2, 0.);
59

            
60
9
	cairo_translate (cr, 0, 3*PAD);
61
9
	cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
62
9
	cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
63
9
	cairo_stroke (cr);
64

            
65
9
	cairo_translate (cr, 0, 3*PAD);
66
9
	cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
67
9
	cairo_close_path (cr);
68
9
	cairo_stroke (cr);
69

            
70
	/* degenerate paths starting with dash off */
71
	/* these should not draw anything */
72
9
	cairo_set_dash (cr, dash, 2, 2.);
73

            
74
9
	cairo_translate (cr, 0, 3*PAD);
75
9
	cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
76
9
	cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
77
9
	cairo_stroke (cr);
78

            
79
9
	cairo_translate (cr, 0, 3*PAD);
80
9
	cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
81
9
	cairo_close_path (cr);
82
9
	cairo_stroke (cr);
83

            
84
	/* this should draw a single degenerate sub-path
85
	 * at the end of the path */
86
9
	cairo_set_dash (cr, dash_long, 2, 6.);
87

            
88
9
	cairo_translate (cr, 0, 3*PAD);
89
9
	cairo_move_to (cr, LINE_WIDTH + 6.0, LINE_WIDTH);
90
9
	cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
91
9
	cairo_stroke (cr);
92

            
93
	/* this should draw a single degenerate sub-path
94
	 * at the end of the path. The difference between this
95
	 * and the above is that this ends with a degenerate sub-path*/
96
9
	cairo_set_dash (cr, dash_long, 2, 6.);
97

            
98
9
	cairo_translate (cr, 0, 3*PAD);
99
9
	cairo_move_to (cr, LINE_WIDTH + 6.0, LINE_WIDTH);
100
9
	cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
101
9
	cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
102
9
	cairo_stroke (cr);
103

            
104
9
	cairo_restore (cr);
105

            
106
9
	cairo_translate (cr, PAD+LINE_WIDTH+PAD, 0);
107
    }
108
3
    return CAIRO_TEST_SUCCESS;
109
}
110

            
111
/*
112
 * XFAIL: undefined behaviour in PS, needs path editing to convert degenerate
113
 * segments into circles/rectangles as expected by cairo
114
 */
115
1
CAIRO_TEST (degenerate_path,
116
	    "Tests the behaviour of degenerate paths with different cap types",
117
	    "degenerate", /* keywords */
118
	    NULL, /* requirements */
119
	    3*(PAD+LINE_WIDTH+PAD), 8*(LINE_WIDTH+PAD) + PAD,
120
	    NULL, draw)