1
/*
2
 * Copyright 2010 Intel Corporation
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: Chris Wilson <chris@chris-wilson.co.uk>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
/* Try to replicate the misbehaviour of show_glyphs() versus glyph_path()
30
 * in the PDF backend reported by Ian Britten.
31
 */
32

            
33
static void
34
24
halo_around_path (cairo_t *cr, const char *str)
35
{
36
24
    cairo_text_path (cr, str);
37

            
38
24
    cairo_set_source_rgb (cr, 0, .5, 1);
39
24
    cairo_stroke_preserve (cr);
40
24
    cairo_set_source_rgb (cr, 1, .5, 0);
41
24
    cairo_fill (cr);
42
24
}
43

            
44
static void
45
24
halo_around_text (cairo_t *cr, const char *str)
46
{
47
    double x, y;
48

            
49
24
    cairo_get_current_point (cr, &x, &y);
50
24
    cairo_text_path (cr, str);
51

            
52
24
    cairo_set_source_rgb (cr, 0, .5, 1);
53
24
    cairo_stroke(cr);
54

            
55
24
    cairo_set_source_rgb (cr, 1, .5, 0);
56
24
    cairo_move_to (cr, x, y);
57
24
    cairo_show_text  (cr, str);
58
24
}
59

            
60
static cairo_test_status_t
61
3
draw (cairo_t *cr, int width, int height)
62
{
63
3
    const char *string = "0123456789";
64
    cairo_text_extents_t extents;
65

            
66
3
    cairo_set_source_rgb (cr, 1, 1, 1);
67
3
    cairo_paint (cr);
68

            
69
3
    cairo_text_extents (cr, string, &extents);
70

            
71
3
    cairo_set_font_size (cr, 12);
72
3
    cairo_set_line_width (cr, 3);
73
3
    cairo_move_to (cr, 9, 4 + extents.height);
74
3
    halo_around_path (cr, string);
75

            
76
3
    cairo_move_to (cr, 109, 4 + extents.height);
77
3
    halo_around_text (cr, string);
78

            
79
3
    cairo_set_font_size (cr, 6);
80
3
    cairo_set_line_width (cr, 3);
81
3
    cairo_move_to (cr, 19 + extents.width, 20 + extents.height);
82
3
    halo_around_path (cr, "0");
83

            
84
3
    cairo_move_to (cr, 119 + extents.width, 20 + extents.height);
85
3
    halo_around_text (cr, "0");
86

            
87
3
    cairo_set_font_size (cr, 64);
88
3
    cairo_set_line_width (cr, 10);
89
3
    cairo_move_to (cr, 8, 70);
90
3
    halo_around_path (cr, "6");
91
3
    cairo_move_to (cr, 32, 90);
92
3
    halo_around_path (cr, "7");
93

            
94
3
    cairo_move_to (cr, 108, 70);
95
3
    halo_around_text (cr, "6");
96
3
    cairo_move_to (cr, 132, 90);
97
3
    halo_around_text (cr, "7");
98

            
99
3
    return CAIRO_TEST_SUCCESS;
100
}
101

            
102
static cairo_test_status_t
103
3
draw_transform (cairo_t *cr, int width, int height)
104
{
105
3
    const char *string = "0123456789";
106
    cairo_text_extents_t extents;
107

            
108
3
    cairo_translate (cr, 50, 50);
109
3
    cairo_scale (cr, M_SQRT2, M_SQRT2);
110

            
111
3
    cairo_set_source_rgb (cr, 1, 1, 1);
112
3
    cairo_paint (cr);
113

            
114
3
    cairo_text_extents (cr, string, &extents);
115

            
116
3
    cairo_set_line_width (cr, 3);
117
3
    cairo_move_to (cr, 9, 4 + extents.height);
118
3
    halo_around_path (cr, string);
119

            
120
3
    cairo_move_to (cr, 109, 4 + extents.height);
121
3
    halo_around_text (cr, string);
122

            
123
3
    cairo_set_font_size (cr, 6);
124
3
    cairo_set_line_width (cr, 3);
125
3
    cairo_move_to (cr, 19 + extents.width, 20 + extents.height);
126
3
    halo_around_path (cr, "0");
127

            
128
3
    cairo_move_to (cr, 119 + extents.width, 20 + extents.height);
129
3
    halo_around_text (cr, "0");
130

            
131
3
    cairo_set_font_size (cr, 64);
132
3
    cairo_set_line_width (cr, 10);
133
3
    cairo_move_to (cr, 8, 70);
134
3
    halo_around_path (cr, "6");
135
3
    cairo_move_to (cr, 32, 90);
136
3
    halo_around_path (cr, "7");
137

            
138
3
    cairo_move_to (cr, 108, 70);
139
3
    halo_around_text (cr, "6");
140
3
    cairo_move_to (cr, 132, 90);
141
3
    halo_around_text (cr, "7");
142

            
143
3
    return CAIRO_TEST_SUCCESS;
144
}
145

            
146
1
CAIRO_TEST (halo,
147
	    "Check the show_glyphs() vs glyph_path()",
148
	    "text", /* keywords */
149
	    NULL, /* requirements */
150
	    200, 100,
151
	    NULL, draw)
152

            
153
1
CAIRO_TEST (halo_transform,
154
	    "Check the show_glyphs() vs glyph_path()",
155
	    "text", /* keywords */
156
	    NULL, /* requirements */
157
	    400, 200,
158
	    NULL, draw_transform)