1
/*
2
 * Copyright © 2008 Chris Wilson
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
 * Chris Wilson not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Chris Wilson 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
 * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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: Chris Wilson <chris@chris-wilson.co.uk>
24
 */
25

            
26
#include "cairo-test.h"
27

            
28
#define LINE_WIDTH	10.
29
#define SIZE		(5 * LINE_WIDTH)
30
#define PAD		(3 * LINE_WIDTH)
31

            
32
static void
33
18
make_path (cairo_t *cr)
34
{
35
18
    cairo_move_to (cr, 0, 0);
36
18
    cairo_rel_curve_to (cr,
37
			-SIZE/4, SIZE/3,
38
			-SIZE/4, SIZE/3,
39
			0, SIZE);
40
18
    cairo_rel_curve_to (cr,
41
			SIZE/3, -SIZE/4,
42
			SIZE/3, -SIZE/4,
43
			SIZE, 0);
44
18
    cairo_close_path (cr);
45

            
46
18
    cairo_move_to (cr, 5 * LINE_WIDTH, 3 * LINE_WIDTH);
47
18
    cairo_rel_curve_to (cr,
48
			0, -3 * LINE_WIDTH,
49
			0, -3 * LINE_WIDTH,
50
			-3 * LINE_WIDTH, -3 * LINE_WIDTH);
51
18
}
52

            
53
static void
54
6
draw_caps_joins (cairo_t *cr)
55
{
56
6
    cairo_save (cr);
57

            
58
6
    cairo_translate (cr, PAD, PAD);
59

            
60
6
    make_path (cr);
61
6
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
62
6
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
63
6
    cairo_stroke (cr);
64

            
65
6
    cairo_translate (cr, SIZE + PAD, 0.);
66

            
67
6
    make_path (cr);
68
6
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
69
6
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
70
6
    cairo_stroke (cr);
71

            
72
6
    cairo_translate (cr, SIZE + PAD, 0.);
73

            
74
6
    make_path (cr);
75
6
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
76
6
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
77
6
    cairo_stroke (cr);
78

            
79
6
    cairo_restore (cr);
80
6
}
81

            
82
static cairo_test_status_t
83
3
draw (cairo_t *cr, int width, int height)
84
{
85
    /* We draw in the default black, so paint white first. */
86
3
    cairo_save (cr);
87
3
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
88
3
    cairo_paint (cr);
89
3
    cairo_restore (cr);
90

            
91
3
    cairo_set_line_width (cr, LINE_WIDTH);
92

            
93
3
    draw_caps_joins (cr);
94

            
95
    /* and reflect to generate the opposite vertex ordering */
96
3
    cairo_translate (cr, 0, height);
97
3
    cairo_scale (cr, 1, -1);
98

            
99
3
    draw_caps_joins (cr);
100

            
101
3
    return CAIRO_TEST_SUCCESS;
102
}
103

            
104
1
CAIRO_TEST (caps_joins_curve,
105
	    "Test caps and joins on curves",
106
	    "stroke, cap, join", /* keywords */
107
	    NULL, /* requirements */
108
	    3 * (PAD + SIZE) + PAD,
109
	    2 * (PAD + SIZE) + PAD,
110
	    NULL, draw)
111