Opensource Compliance Issue.
[platform/core/graphics/cairo.git] / test / rectilinear-grid.c
1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
2 /*
3  * Copyright 2010 Andrea Canciani
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Author: Andrea Canciani <ranma42@gmail.com>
26  */
27
28 #include "cairo-test.h"
29
30 #define SIZE 52
31 #define OFFSET 5
32 #define DISTANCE 10.25
33
34 /*
35   This test checks that boxes not aligned to pixels are drawn
36   correctly.
37
38   In particular the corners of the boxes are drawn incorrectly by
39   cairo-image in cairo 1.10.0, because overlapping boxes are passed to
40   a span converter which assumes disjoint boxes as input.
41
42   This results in corners to be drawn with the wrong shade.
43 */
44
45 static cairo_test_status_t
46 draw (cairo_t *cr, int width, int height)
47 {
48     int i;
49
50     cairo_set_source_rgb (cr, 1, 1, 1);
51     cairo_paint (cr);
52
53     cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
54     cairo_set_source_rgb (cr, 0, 0, 0);
55     cairo_set_line_width (cr, 4);
56     cairo_translate (cr, 2*OFFSET, 2*OFFSET);
57
58     for (i = 0; i < 4; i++) {
59         double x = i * DISTANCE;
60
61         cairo_move_to (cr, x, -OFFSET-0.75);
62         cairo_line_to (cr, x, SIZE-3*OFFSET-0.25);
63
64         cairo_move_to (cr, -OFFSET-0.75, x);
65         cairo_line_to (cr, SIZE-3*OFFSET-0.25, x);
66     }
67
68     cairo_stroke (cr);
69
70     return CAIRO_TEST_SUCCESS;
71 }
72
73 static cairo_test_status_t
74 aligned (cairo_t *cr, int width, int height)
75 {
76     cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
77     return draw (cr, width, height);
78 }
79
80 CAIRO_TEST (rectilinear_grid,
81             "Test rectilinear rasterizer (covering partial pixels)",
82             "rectilinear", /* keywords */
83             NULL, /* requirements */
84             SIZE, SIZE,
85             NULL, draw)
86
87 CAIRO_TEST (a1_rectilinear_grid,
88             "Test rectilinear rasterizer (covering whole pixels)",
89             "rectilinear", /* keywords */
90             "target=raster", /* requirements */
91             SIZE, SIZE,
92             NULL, aligned)