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
3
big_star_path (cairo_t *cr)
31
{
32
3
    cairo_move_to (cr, 40, 0);
33
3
    cairo_rel_line_to (cr, 25, 80);
34
3
    cairo_rel_line_to (cr, -65, -50);
35
3
    cairo_rel_line_to (cr, 80, 0);
36
3
    cairo_rel_line_to (cr, -65, 50);
37
3
    cairo_close_path (cr);
38
3
}
39

            
40
static cairo_test_status_t
41
3
draw (cairo_t *cr, int width, int height)
42
{
43
    int i;
44

            
45
3
    cairo_set_source_rgb (cr, 0, 0, 0);
46
3
    cairo_paint (cr);
47

            
48
3
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
49

            
50
    /* Try a circle */
51
3
    cairo_arc (cr, 40, 40, 20, 0, 2 * M_PI);
52
3
    cairo_set_source_rgb (cr, 1, 0, 0);
53
3
    cairo_fill (cr);
54

            
55
    /* Try using clipping to draw a circle */
56
3
    cairo_arc (cr, 100, 40, 20, 0, 2 * M_PI);
57
3
    cairo_clip (cr);
58
3
    cairo_rectangle (cr, 80, 20, 40, 40);
59
3
    cairo_set_source_rgb (cr, 0, 0, 1);
60
3
    cairo_fill (cr);
61

            
62
    /* Reset the clipping */
63
3
    cairo_reset_clip (cr);
64

            
65
    /* Draw a bunch of lines */
66
3
    cairo_set_line_width (cr, 1.0);
67
3
    cairo_set_source_rgb (cr, 0, 1, 0);
68
33
    for (i = 0; i < 10; i++) {
69
30
        cairo_move_to (cr, 10, 70 + (i * 4));
70
30
        cairo_line_to (cr, 120, 70 + (i * 18));
71
30
        cairo_stroke (cr);
72
    }
73

            
74
    /* Try filling a poly */
75
3
    cairo_translate (cr, 160, 120);
76
3
    cairo_set_source_rgb (cr, 1, 1, 0);
77
3
    big_star_path (cr);
78
3
    cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
79
3
    cairo_fill (cr);
80
3
    cairo_translate (cr, -160, -120);
81

            
82
    /* How about some curves? */
83
3
    cairo_set_source_rgb (cr, 1, 0, 1);
84
33
    for (i = 0; i < 10; i++) {
85
30
        cairo_move_to (cr, 150, 50 + (i * 5));
86
30
        cairo_curve_to (cr, 250, 50, 200, (i * 10), 300, 50 + (i * 10));
87
30
        cairo_stroke (cr);
88
    }
89

            
90
3
    return CAIRO_TEST_SUCCESS;
91
}
92

            
93
1
CAIRO_TEST (unantialiased_shapes,
94
	    "Test shape drawing without antialiasing",
95
	    "fill, stroke", /* keywords */
96
	    "target=raster", /* requirements */
97
	    320, 240,
98
	    NULL, draw)