Blame test/unantialiased-shapes.c

Packit 324a5c
/*
Packit 324a5c
 * Copyright © 2005 Billy Biggs
Packit 324a5c
 *
Packit 324a5c
 * Permission to use, copy, modify, distribute, and sell this software
Packit 324a5c
 * and its documentation for any purpose is hereby granted without
Packit 324a5c
 * fee, provided that the above copyright notice appear in all copies
Packit 324a5c
 * and that both that copyright notice and this permission notice
Packit 324a5c
 * appear in supporting documentation, and that the name of
Packit 324a5c
 * Billy Biggs not be used in advertising or publicity pertaining to
Packit 324a5c
 * distribution of the software without specific, written prior
Packit 324a5c
 * permission. Billy Biggs makes no representations about the
Packit 324a5c
 * suitability of this software for any purpose.  It is provided "as
Packit 324a5c
 * is" without express or implied warranty.
Packit 324a5c
 *
Packit 324a5c
 * BILLY BIGGS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
Packit 324a5c
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
Packit 324a5c
 * FITNESS, IN NO EVENT SHALL BILLY BIGGS BE LIABLE FOR ANY SPECIAL,
Packit 324a5c
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
Packit 324a5c
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
Packit 324a5c
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
Packit 324a5c
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Packit 324a5c
 *
Packit 324a5c
 * Author: Billy Biggs <vektor@dumbterm.net>
Packit 324a5c
 */
Packit 324a5c
Packit 324a5c
#include "cairo-test.h"
Packit 324a5c
Packit 324a5c
/* The star shape from the SVG test suite, from the fill rule test */
Packit 324a5c
static void
Packit 324a5c
big_star_path (cairo_t *cr)
Packit 324a5c
{
Packit 324a5c
    cairo_move_to (cr, 40, 0);
Packit 324a5c
    cairo_rel_line_to (cr, 25, 80);
Packit 324a5c
    cairo_rel_line_to (cr, -65, -50);
Packit 324a5c
    cairo_rel_line_to (cr, 80, 0);
Packit 324a5c
    cairo_rel_line_to (cr, -65, 50);
Packit 324a5c
    cairo_close_path (cr);
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw (cairo_t *cr, int width, int height)
Packit 324a5c
{
Packit 324a5c
    int i;
Packit 324a5c
Packit 324a5c
    cairo_set_source_rgb (cr, 0, 0, 0);
Packit 324a5c
    cairo_paint (cr);
Packit 324a5c
Packit 324a5c
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
Packit 324a5c
Packit 324a5c
    /* Try a circle */
Packit 324a5c
    cairo_arc (cr, 40, 40, 20, 0, 2 * M_PI);
Packit 324a5c
    cairo_set_source_rgb (cr, 1, 0, 0);
Packit 324a5c
    cairo_fill (cr);
Packit 324a5c
Packit 324a5c
    /* Try using clipping to draw a circle */
Packit 324a5c
    cairo_arc (cr, 100, 40, 20, 0, 2 * M_PI);
Packit 324a5c
    cairo_clip (cr);
Packit 324a5c
    cairo_rectangle (cr, 80, 20, 40, 40);
Packit 324a5c
    cairo_set_source_rgb (cr, 0, 0, 1);
Packit 324a5c
    cairo_fill (cr);
Packit 324a5c
Packit 324a5c
    /* Reset the clipping */
Packit 324a5c
    cairo_reset_clip (cr);
Packit 324a5c
Packit 324a5c
    /* Draw a bunch of lines */
Packit 324a5c
    cairo_set_line_width (cr, 1.0);
Packit 324a5c
    cairo_set_source_rgb (cr, 0, 1, 0);
Packit 324a5c
    for (i = 0; i < 10; i++) {
Packit 324a5c
        cairo_move_to (cr, 10, 70 + (i * 4));
Packit 324a5c
        cairo_line_to (cr, 120, 70 + (i * 18));
Packit 324a5c
        cairo_stroke (cr);
Packit 324a5c
    }
Packit 324a5c
Packit 324a5c
    /* Try filling a poly */
Packit 324a5c
    cairo_translate (cr, 160, 120);
Packit 324a5c
    cairo_set_source_rgb (cr, 1, 1, 0);
Packit 324a5c
    big_star_path (cr);
Packit 324a5c
    cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
Packit 324a5c
    cairo_fill (cr);
Packit 324a5c
    cairo_translate (cr, -160, -120);
Packit 324a5c
Packit 324a5c
    /* How about some curves? */
Packit 324a5c
    cairo_set_source_rgb (cr, 1, 0, 1);
Packit 324a5c
    for (i = 0; i < 10; i++) {
Packit 324a5c
        cairo_move_to (cr, 150, 50 + (i * 5));
Packit 324a5c
        cairo_curve_to (cr, 250, 50, 200, (i * 10), 300, 50 + (i * 10));
Packit 324a5c
        cairo_stroke (cr);
Packit 324a5c
    }
Packit 324a5c
Packit 324a5c
    return CAIRO_TEST_SUCCESS;
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
CAIRO_TEST (unantialiased_shapes,
Packit 324a5c
	    "Test shape drawing without antialiasing",
Packit 324a5c
	    "fill, stroke", /* keywords */
Packit 324a5c
	    "target=raster", /* requirements */
Packit 324a5c
	    320, 240,
Packit 324a5c
	    NULL, draw)