Tizen 2.0 Release
[framework/graphics/cairo.git] / test / bug-spline.c
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 #define NUM_SPLINES (sizeof(splines)/sizeof(splines[0]))
60
61 static cairo_test_status_t
62 draw (cairo_t *cr, int width, int height)
63 {
64     unsigned n;
65
66     cairo_set_source_rgb (cr, 0, 0, 0);
67     cairo_paint (cr);
68
69     cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
70
71     for (n = 0; n < NUM_SPLINES; n++) {
72         cairo_set_line_width (cr, splines[n].line_width);
73         cairo_set_source_rgba (cr,
74                                splines[n].rgba[0],
75                                splines[n].rgba[1],
76                                splines[n].rgba[2],
77                                splines[n].rgba[3]);
78
79         cairo_move_to (cr, splines[n].pt[0].x, splines[n].pt[0].y);
80         cairo_curve_to (cr,
81                         splines[n].pt[1].x, splines[n].pt[1].y,
82                         splines[n].pt[2].x, splines[n].pt[2].y,
83                         splines[n].pt[3].x, splines[n].pt[3].y);
84
85         cairo_stroke (cr);
86     }
87
88     return CAIRO_TEST_SUCCESS;
89 }
90
91 CAIRO_TEST (bug_spline,
92             "Exercises a bug in the stroking of splines",
93             "spline, stroke", /* keywords */
94             NULL, /* requirements */
95             300, 300,
96             NULL, draw)