Upload Tizen2.0 source
[framework/graphics/cairo.git] / test / fill-rule.c
1 /*
2  * Copyright © 2004 Red Hat, Inc.
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  * Red Hat, Inc. not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission. Red Hat, Inc. 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  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Carl D. Worth <cworth@cworth.org>
24  */
25
26 /* Bug history
27  *
28  * 2004-10-27  Carl Worth  <cworth@cworth.org>
29  *
30  *   There's currently a regression bug in the tessellation code. This
31  *   causes each of these simple star shapes to be filled incorrectly.
32  *
33  *   It looks like right now we can get this test to pass by doing:
34  *
35  *       cvs update -r 1.16 src/cairo_traps.c
36  *
37  *   But we don't want to revert that change permanently since it
38  *   really does correct some bugs. It must be that the old version of
39  *   the code is masking some other bugs in the tessellation code. My
40  *   current plan is to back this revision up for the next snapshot,
41  *   but not to list the test as an expected failure since I'm
42  *   planning on doing the new tessellator which should fix this
43  *   problem.
44  *
45  * 2005-01-11 Carl Worth <cworth@cworth.org>
46  *
47  *   Keith committed some fixes that fix the original size-20
48  *   star_path:
49  *
50  *      * src/cairo_wideint.c: (_cairo_int32x32_64_mul),
51  *      (_cairo_int64x64_128_mul):
52  *      * src/cairo_wideint.h:
53  *      int32x32_64_mul and int64x64_128_mul are different from their
54  *      unsigned compatriots
55  *
56  * 2005-01-12 Carl Worth <cworth@cworth.org>
57  *
58  *   Going back to the SVG test suite, however, the original star
59  *   shape is still broken. Adding both shapes now as little_star_path
60  *   and big_star_path.
61  *
62  */
63
64 #include "cairo-test.h"
65
66 #define LITTLE_STAR_SIZE 20
67 #define BIG_STAR_SIZE    80
68
69 /* The SVG start trimmed down, but still showing the bug (originally) */
70 static void
71 little_star_path (cairo_t *cr)
72 {
73     cairo_move_to (cr, 10, 0);
74     cairo_rel_line_to (cr, 6, 20);
75     cairo_rel_line_to (cr, -16, -12);
76     cairo_rel_line_to (cr, 20, 0);
77     cairo_rel_line_to (cr, -16, 12);
78 }
79
80 /* The star shape from the SVG test suite. This was is still buggy even after
81    we got little_star_path working. */
82 static void
83 big_star_path (cairo_t *cr)
84 {
85     cairo_move_to (cr, 40, 0);
86     cairo_rel_line_to (cr, 25, 80);
87     cairo_rel_line_to (cr, -65, -50);
88     cairo_rel_line_to (cr, 80, 0);
89     cairo_rel_line_to (cr, -65, 50);
90     cairo_close_path (cr);
91 }
92
93 /* Fill the same path twice, once with each fill rule */
94 static cairo_test_status_t
95 draw (cairo_t *cr, int width, int height)
96 {
97     cairo_set_source_rgb (cr, 1, 0, 0);
98
99     cairo_translate (cr, 1, 1);
100     little_star_path (cr);
101     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
102     cairo_fill (cr);
103
104     cairo_translate (cr, LITTLE_STAR_SIZE + 1, 0);
105     little_star_path (cr);
106     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
107     cairo_fill (cr);
108
109     cairo_translate (cr, -(LITTLE_STAR_SIZE + 1), LITTLE_STAR_SIZE + 1);
110     big_star_path (cr);
111     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
112     cairo_fill (cr);
113
114     cairo_translate (cr, BIG_STAR_SIZE + 1, 0);
115     big_star_path (cr);
116     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
117     cairo_fill (cr);
118
119     return CAIRO_TEST_SUCCESS;
120 }
121
122 CAIRO_TEST (fill_rule,
123             "Tests cairo_set_fill_rule with some star shapes",
124             "fill, path", /* keywords */
125             NULL, /* requirements */
126             BIG_STAR_SIZE * 2 + 3, BIG_STAR_SIZE + LITTLE_STAR_SIZE + 3,
127             NULL, draw)