Opensource Compliance Issue.
[platform/core/graphics/cairo.git] / test / unantialiased-shapes.c
1 /*
2  * Copyright © 2005 Billy Biggs
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  * Billy Biggs not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission. Billy Biggs 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  * BILLY BIGGS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL BILLY BIGGS 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: Billy Biggs <vektor@dumbterm.net>
24  */
25
26 #include "cairo-test.h"
27
28 /* The star shape from the SVG test suite, from the fill rule test */
29 static void
30 big_star_path (cairo_t *cr)
31 {
32     cairo_move_to (cr, 40, 0);
33     cairo_rel_line_to (cr, 25, 80);
34     cairo_rel_line_to (cr, -65, -50);
35     cairo_rel_line_to (cr, 80, 0);
36     cairo_rel_line_to (cr, -65, 50);
37     cairo_close_path (cr);
38 }
39
40 static cairo_test_status_t
41 draw (cairo_t *cr, int width, int height)
42 {
43     int i;
44
45     cairo_set_source_rgb (cr, 0, 0, 0);
46     cairo_paint (cr);
47
48     cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
49
50     /* Try a circle */
51     cairo_arc (cr, 40, 40, 20, 0, 2 * M_PI);
52     cairo_set_source_rgb (cr, 1, 0, 0);
53     cairo_fill (cr);
54
55     /* Try using clipping to draw a circle */
56     cairo_arc (cr, 100, 40, 20, 0, 2 * M_PI);
57     cairo_clip (cr);
58     cairo_rectangle (cr, 80, 20, 40, 40);
59     cairo_set_source_rgb (cr, 0, 0, 1);
60     cairo_fill (cr);
61
62     /* Reset the clipping */
63     cairo_reset_clip (cr);
64
65     /* Draw a bunch of lines */
66     cairo_set_line_width (cr, 1.0);
67     cairo_set_source_rgb (cr, 0, 1, 0);
68     for (i = 0; i < 10; i++) {
69         cairo_move_to (cr, 10, 70 + (i * 4));
70         cairo_line_to (cr, 120, 70 + (i * 18));
71         cairo_stroke (cr);
72     }
73
74     /* Try filling a poly */
75     cairo_translate (cr, 160, 120);
76     cairo_set_source_rgb (cr, 1, 1, 0);
77     big_star_path (cr);
78     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
79     cairo_fill (cr);
80     cairo_translate (cr, -160, -120);
81
82     /* How about some curves? */
83     cairo_set_source_rgb (cr, 1, 0, 1);
84     for (i = 0; i < 10; i++) {
85         cairo_move_to (cr, 150, 50 + (i * 5));
86         cairo_curve_to (cr, 250, 50, 200, (i * 10), 300, 50 + (i * 10));
87         cairo_stroke (cr);
88     }
89
90     return CAIRO_TEST_SUCCESS;
91 }
92
93 CAIRO_TEST (unantialiased_shapes,
94             "Test shape drawing without antialiasing",
95             "fill, stroke", /* keywords */
96             "target=raster", /* requirements */
97             320, 240,
98             NULL, draw)