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
draw_lines(cairo_t * cr)36 draw_lines(cairo_t *cr)
37 {
38     /* horizontal line */
39     cairo_translate (cr, PAD, PAD);
40     cairo_move_to (cr, 0, CELL_HEIGHT/2);
41     cairo_line_to (cr, CELL_WIDTH, CELL_HEIGHT/2);
42     cairo_stroke (cr);
43 
44     /* vertical line */
45     cairo_translate (cr, 0, CELL_HEIGHT + PAD);
46     cairo_move_to (cr, CELL_WIDTH/2, 0);
47     cairo_line_to (cr, CELL_WIDTH/2, CELL_HEIGHT);
48     cairo_stroke (cr);
49 
50     /* diagonal line */
51     cairo_translate (cr, 0, CELL_HEIGHT + PAD);
52     cairo_move_to (cr, 0, CELL_HEIGHT);
53     cairo_line_to (cr, CELL_WIDTH, 0);
54     cairo_stroke (cr);
55 
56     /* curved line */
57     cairo_translate (cr, 0, CELL_HEIGHT + PAD);
58     cairo_move_to (cr, CELL_WIDTH, 0);
59     cairo_curve_to (cr, 0, 0,
60 		    CELL_WIDTH, CELL_HEIGHT,
61 		    0, CELL_HEIGHT);
62     cairo_stroke (cr);
63 }
64 
65 #define FIXED_POINT_MIN (1.0/256)
66 
67 static cairo_test_status_t
draw(cairo_t * cr,int width,int height)68 draw (cairo_t *cr, int width, int height)
69 {
70     cairo_save (cr);
71     cairo_set_line_width (cr, FIXED_POINT_MIN*10.0);
72     draw_lines (cr);
73     cairo_restore (cr);
74 
75     cairo_translate (cr, CELL_WIDTH + PAD, 0);
76     cairo_save (cr);
77     cairo_set_line_width (cr, FIXED_POINT_MIN);
78     draw_lines (cr);
79     cairo_restore (cr);
80 
81     cairo_translate (cr, CELL_WIDTH + PAD, 0);
82     cairo_save (cr);
83     cairo_set_line_width (cr, FIXED_POINT_MIN/10.0);
84     draw_lines (cr);
85     cairo_restore (cr);
86 
87     return CAIRO_TEST_SUCCESS;
88 }
89 
90 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)
96