1
/* cc `pkg-config --cflags --libs cairo` cairo-spline-image.c -o cairo-spline-image */
2

            
3
/* Copyright © 2005 Carl Worth
4
 * Copyright © 2012 Intel Corporation
5
 *
6
 * Permission is hereby granted, free of charge, to any person
7
 * obtaining a copy of this software and associated documentation
8
 * files (the "Software"), to deal in the Software without
9
 * restriction, including without limitation the rights to use, copy,
10
 * modify, merge, publish, distribute, sublicense, and/or sell copies
11
 * of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be
15
 * included in all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
 * SOFTWARE.
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
#define WIDE_LINE_WIDTH 160
30
#define NARROW_LINE_WIDTH 2
31

            
32
/* A spline showing bugs in the "contour-based stroking" in cairo 1.12 */
33
static const struct spline {
34
    struct { double x, y; } pt[5];
35
    double line_width;
36
    double rgba[4];
37
} splines[] = {
38
    {
39
	{
40
	    { 172.25, 156.185 },
41
	    { 177.225, 164.06 },
42
	    { 176.5, 157.5 },
43
	    { 175.5, 159.5 },
44
	},
45
	WIDE_LINE_WIDTH,
46
	{ 1, 1, 1, 1 },
47
    },
48
    {
49
	{
50
	    { 571.25, 247.185 },
51
	    { 78.225, 224.06 },
52
	    { 129.5, 312.5 },
53
	    { 210.5, 224.5 },
54
	},
55
	NARROW_LINE_WIDTH,
56
	{ 1, 0, 0, 1 },
57
    }
58
};
59

            
60
static cairo_test_status_t
61
3
draw (cairo_t *cr, int width, int height)
62
{
63
    unsigned n;
64

            
65
3
    cairo_set_source_rgb (cr, 0, 0, 0);
66
3
    cairo_paint (cr);
67

            
68
3
    cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
69

            
70
9
    for (n = 0; n < ARRAY_LENGTH(splines); n++) {
71
6
	cairo_set_line_width (cr, splines[n].line_width);
72
6
	cairo_set_source_rgba (cr,
73
6
			       splines[n].rgba[0],
74
6
			       splines[n].rgba[1],
75
6
			       splines[n].rgba[2],
76
6
			       splines[n].rgba[3]);
77

            
78
6
	cairo_move_to (cr, splines[n].pt[0].x, splines[n].pt[0].y);
79
6
	cairo_curve_to (cr,
80
6
			splines[n].pt[1].x, splines[n].pt[1].y,
81
6
			splines[n].pt[2].x, splines[n].pt[2].y,
82
6
			splines[n].pt[3].x, splines[n].pt[3].y);
83

            
84
6
	cairo_stroke (cr);
85
    }
86

            
87
3
    return CAIRO_TEST_SUCCESS;
88
}
89

            
90
1
CAIRO_TEST (bug_spline,
91
	    "Exercises a bug in the stroking of splines",
92
	    "spline, stroke", /* keywords */
93
	    NULL, /* requirements */
94
	    300, 300,
95
	    NULL, draw)