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 IMAGE_WIDTH 19
29
#define IMAGE_HEIGHT 61
30

            
31
/* A test of the two extremes of dashing: a solid line
32
 * and an invisible one. Also test that capping works
33
 * on invisible lines.
34
 */
35

            
36
static void
37
57
draw_dash (cairo_t *cr, double *dash, int num_dashes)
38
{
39
57
    cairo_set_dash (cr, dash, num_dashes, 0.0);
40
57
    cairo_move_to (cr,  1, 2);
41
57
    cairo_line_to (cr, 18, 2);
42
57
    cairo_stroke (cr);
43
57
    cairo_translate (cr, 0, 3);
44
57
}
45
static cairo_test_status_t
46
3
draw (cairo_t *cr, int width, int height)
47
{
48
    static double solid_line[] = { 4, 0 };
49
    static double invisible_line[] = { 0, 4 };
50
    static double dotted_line[] = { 0, 6 };
51
    static double zero_1_of_3[] = { 0, 2, 3 };
52
    static double zero_2_of_3[] = { 1, 0, 3 };
53
    static double zero_3_of_3[] = { 1, 2, 0 };
54
    static double zero_1_of_4[] = { 0, 2, 3, 4 };
55
    static double zero_2_of_4[] = { 1, 0, 3, 4 };
56
    static double zero_3_of_4[] = { 1, 2, 0, 4 };
57
    static double zero_4_of_4[] = { 1, 2, 3, 0 };
58
    static double zero_1_2_of_4[] = { 0, 0, 3, 4 };
59
    static double zero_1_3_of_4[] = { 0, 2, 0, 4 };
60
/* Clearly it would be nice to draw this one as well, but it seems to trigger a bug in ghostscript. */
61
#if BUG_FIXED_IN_GHOSTSCRIPT
62
    static double zero_1_4_of_4[] = { 0, 2, 3, 0 };
63
#endif
64
    static double zero_2_3_of_4[] = { 1, 0, 0, 4 };
65
    static double zero_2_4_of_4[] = { 1, 0, 3, 0 };
66
    static double zero_3_4_of_4[] = { 1, 2, 0, 0 };
67
    static double zero_1_2_3_of_4[] = { 0, 0, 0, 4 };
68
    static double zero_1_2_4_of_4[] = { 0, 0, 3, 0 };
69
    static double zero_1_3_4_of_4[] = { 0, 2, 0, 0 };
70
    static double zero_2_3_4_of_4[] = { 1, 0, 0, 0 };
71

            
72
3
    cairo_set_source_rgb (cr, 1, 0, 0);
73
3
    cairo_set_line_width (cr, 2);
74

            
75
3
    draw_dash (cr, solid_line, 2);
76
3
    draw_dash (cr, invisible_line, 2);
77

            
78
3
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
79
3
    draw_dash (cr, dotted_line, 2);
80
3
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
81

            
82
3
    draw_dash (cr, zero_1_of_3, 3);
83
3
    draw_dash (cr, zero_2_of_3, 3);
84
3
    draw_dash (cr, zero_3_of_3, 3);
85
3
    draw_dash (cr, zero_1_of_4, 4);
86
3
    draw_dash (cr, zero_2_of_4, 4);
87
3
    draw_dash (cr, zero_3_of_4, 4);
88
3
    draw_dash (cr, zero_4_of_4, 4);
89
3
    draw_dash (cr, zero_1_2_of_4, 4);
90
3
    draw_dash (cr, zero_1_3_of_4, 4);
91
#if BUG_FIXED_IN_GHOSTSCRIPT
92
    draw_dash (cr, zero_1_4_of_4, 4);
93
#endif
94
3
    draw_dash (cr, zero_2_3_of_4, 4);
95
3
    draw_dash (cr, zero_2_4_of_4, 4);
96
3
    draw_dash (cr, zero_3_4_of_4, 4);
97
3
    draw_dash (cr, zero_1_2_3_of_4, 4);
98
3
    draw_dash (cr, zero_1_2_4_of_4, 4);
99
3
    draw_dash (cr, zero_1_3_4_of_4, 4);
100
3
    draw_dash (cr, zero_2_3_4_of_4, 4);
101

            
102
3
    return CAIRO_TEST_SUCCESS;
103
}
104

            
105
1
CAIRO_TEST (dash_zero_length,
106
	    "Tests cairo_set_dash with zero length",
107
	    "dash, stroke", /* keywords */
108
	    NULL, /* requirements */
109
	    IMAGE_WIDTH, IMAGE_HEIGHT,
110
	    NULL, draw)