1
/*
2
 * Copyright © 2015 Adrian Johnson
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
 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Red Hat, Inc. 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
 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Adrian Johnson <ajohnson@redneon.com>
24
 */
25

            
26
#include "cairo-test.h"
27

            
28
#define CELL_WIDTH 20
29
#define CELL_HEIGHT 20
30
#define PAD 2
31
#define IMAGE_WIDTH (CELL_WIDTH*3 + PAD*4)
32
#define IMAGE_HEIGHT (CELL_HEIGHT*4 + PAD*5)
33

            
34

            
35
static void
36
9
draw_lines(cairo_t *cr)
37
{
38
    /* horizontal line */
39
9
    cairo_translate (cr, PAD, PAD);
40
9
    cairo_move_to (cr, 0, CELL_HEIGHT/2);
41
9
    cairo_line_to (cr, CELL_WIDTH, CELL_HEIGHT/2);
42
9
    cairo_stroke (cr);
43

            
44
    /* vertical line */
45
9
    cairo_translate (cr, 0, CELL_HEIGHT + PAD);
46
9
    cairo_move_to (cr, CELL_WIDTH/2, 0);
47
9
    cairo_line_to (cr, CELL_WIDTH/2, CELL_HEIGHT);
48
9
    cairo_stroke (cr);
49

            
50
    /* diagonal line */
51
9
    cairo_translate (cr, 0, CELL_HEIGHT + PAD);
52
9
    cairo_move_to (cr, 0, CELL_HEIGHT);
53
9
    cairo_line_to (cr, CELL_WIDTH, 0);
54
9
    cairo_stroke (cr);
55

            
56
    /* curved line */
57
9
    cairo_translate (cr, 0, CELL_HEIGHT + PAD);
58
9
    cairo_move_to (cr, CELL_WIDTH, 0);
59
9
    cairo_curve_to (cr, 0, 0,
60
		    CELL_WIDTH, CELL_HEIGHT,
61
		    0, CELL_HEIGHT);
62
9
    cairo_stroke (cr);
63
9
}
64

            
65
#define FIXED_POINT_MIN (1.0/256)
66

            
67
static cairo_test_status_t
68
3
draw (cairo_t *cr, int width, int height)
69
{
70
3
    cairo_save (cr);
71
3
    cairo_set_line_width (cr, FIXED_POINT_MIN*10.0);
72
3
    draw_lines (cr);
73
3
    cairo_restore (cr);
74

            
75
3
    cairo_translate (cr, CELL_WIDTH + PAD, 0);
76
3
    cairo_save (cr);
77
3
    cairo_set_line_width (cr, FIXED_POINT_MIN);
78
3
    draw_lines (cr);
79
3
    cairo_restore (cr);
80

            
81
3
    cairo_translate (cr, CELL_WIDTH + PAD, 0);
82
3
    cairo_save (cr);
83
3
    cairo_set_line_width (cr, FIXED_POINT_MIN/10.0);
84
3
    draw_lines (cr);
85
3
    cairo_restore (cr);
86

            
87
3
    return CAIRO_TEST_SUCCESS;
88
}
89

            
90
1
CAIRO_TEST (thin_lines,
91
	    "Tests that very thin lines are output to vector surfaces",
92
	    "stroke", /* keywords */
93
	    NULL, /* requirements */
94
	    IMAGE_WIDTH, IMAGE_HEIGHT,
95
	    NULL, draw)