1
/*
2
 * Copyright © 2007 Red Hat, Inc.
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
 * Author: Carl Worth <cworth@cworth.org>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
/* This test case is designed to exercise the following bug:
30
 *
31
 *	Skew transforms were broken by the cairo update in December
32
 *	https://bugzilla.mozilla.org/show_bug.cgi?id=373632
33
 *
34
 * What's happening is that the rectangle is being skewed into the
35
 * following shape:
36
 *
37
 * a__b
38
 *  \ \
39
 *   \ \
40
 *    \ \
41
 *     \ \
42
 *      \ \
43
 *      d\_\c
44
 *
45
 * and the bug is that _cairo_traps_tessellate_convex_quad is
46
 * comparing b.x as less then d.x and therefore determining that the bc
47
 * edge is left of the ad edge. The fix is simply to compare c.x to
48
 * d.x instead of b.x to d.x .
49
 */
50

            
51
#define PAD		2
52
#define LINE_WIDTH	10
53
#define LINE_LENGTH	(2 * LINE_WIDTH)
54
#define SKEW_FACTOR	5.0
55
#define WIDTH		(PAD + (LINE_LENGTH * SKEW_FACTOR) + LINE_WIDTH + PAD)
56
#define HEIGHT		(PAD + LINE_WIDTH + (LINE_LENGTH * SKEW_FACTOR) + LINE_WIDTH + PAD)
57

            
58
static cairo_test_status_t
59
3
draw (cairo_t *cr, int width, int height)
60
{
61
    /* We draw in the default black, so paint white first. */
62
3
    cairo_save (cr);
63
3
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
64
3
    cairo_paint (cr);
65
3
    cairo_restore (cr);
66

            
67
3
    cairo_translate (cr, PAD, PAD);
68

            
69
3
    cairo_set_line_width (cr, LINE_WIDTH);
70
3
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
71

            
72
3
    cairo_save (cr);
73
    {
74
3
	cairo_matrix_t skew_x = {
75
	    1.0, 0.0,
76
	    SKEW_FACTOR, 1.0,
77
	    0.0, 0.0
78
	};
79

            
80
3
	cairo_translate (cr, LINE_WIDTH / 2.0, 0.0);
81

            
82
3
	cairo_transform (cr, &skew_x);
83

            
84
3
	cairo_move_to (cr, 0.0, 0.0);
85
3
	cairo_line_to (cr, 0.0, LINE_LENGTH);
86
3
	cairo_stroke (cr);
87
    }
88
3
    cairo_restore (cr);
89

            
90
3
    cairo_translate (cr, 0.0, LINE_WIDTH);
91

            
92
3
    cairo_save (cr);
93
    {
94
3
	cairo_matrix_t skew_y = {
95
	    1.0, SKEW_FACTOR,
96
	    0.0, 1.0,
97
	    0.0, 0.0
98
	};
99

            
100
3
	cairo_translate (cr, 0.0, LINE_WIDTH / 2.0);
101

            
102
3
	cairo_transform (cr, &skew_y);
103

            
104
3
	cairo_move_to (cr, 0.0, 0.0);
105
3
	cairo_line_to (cr, LINE_LENGTH, 0.0);
106
3
	cairo_stroke (cr);
107
    }
108
3
    cairo_restore (cr);
109

            
110
3
    return CAIRO_TEST_SUCCESS;
111
}
112

            
113
1
CAIRO_TEST (skew_extreme,
114
	    "Test cases of extreme skew.",
115
	    "transform, stroke", /* keywords */
116
	    NULL, /* requirements */
117
	    WIDTH, HEIGHT,
118
	    NULL, draw)