1
/*
2
 * Copyright © 2026 Kevin Ushey
3
 *
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use, copy,
8
 * modify, merge, publish, distribute, sublicense, and/or sell copies
9
 * of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24

            
25
#include "cairo-test.h"
26

            
27
/* Test case for:
28
 *
29
 *      https://gitlab.freedesktop.org/cairo/cairo/-/issues/976
30
 *
31
 * With ANTIALIAS_NONE, abutting rectangles built with cairo_rectangle()
32
 * could leave their shared pixel unpainted: the far edge was converted
33
 * to fixed point as fixed(x) + fixed(width), which can differ from the
34
 * abutting rectangle's fixed(x + width) by 1/256 and round to a
35
 * different pixel.
36
 *
37
 * The cell size below is chosen so that the first cell's far edge lands
38
 * exactly on a .5 fixed-point boundary (rounding down) while the next
39
 * cell's origin rounds up, which used to leave a one-pixel white cross
40
 * through the middle of the grid.
41
 */
42

            
43
static cairo_test_status_t
44
3
draw (cairo_t *cr, int width, int height)
45
{
46
3
    double x0 = 1.7;
47
3
    double size = 2.8024;
48
3
    double x1 = x0 + size;
49

            
50
3
    cairo_set_source_rgb (cr, 1, 1, 1);
51
3
    cairo_paint (cr);
52

            
53
3
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
54
3
    cairo_set_source_rgb (cr, 0, 0, 0);
55

            
56
    /* this should draw a seamless 2x2 grid of cells */
57
3
    cairo_rectangle (cr, x0, x0, size, size);
58
3
    cairo_rectangle (cr, x1, x0, size, size);
59
3
    cairo_rectangle (cr, x0, x1, size, size);
60
3
    cairo_rectangle (cr, x1, x1, size, size);
61
3
    cairo_fill (cr);
62

            
63
3
    return CAIRO_TEST_SUCCESS;
64
}
65

            
66
1
CAIRO_TEST (bug_976,
67
	    "Bug 976 (abutting rectangles can leave their shared pixel unpainted with ANTIALIAS_NONE)",
68
	    "fill, antialias", /* keywords */
69
	    "target=raster", /* requirements */
70
	    10, 10,
71
	    NULL, draw)