30064e51a8ec6af665c0f4f163afad5179ac19e4
[platform/core/graphics/cairo.git] / test / halo.c
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 halo_around_path (cairo_t *cr, const char *str)
35 {
36     cairo_text_path (cr, str);
37
38     cairo_set_source_rgb (cr, 0, .5, 1);
39     cairo_stroke_preserve (cr);
40     cairo_set_source_rgb (cr, 1, .5, 0);
41     cairo_fill (cr);
42 }
43
44 static void
45 halo_around_text (cairo_t *cr, const char *str)
46 {
47     double x, y;
48
49     cairo_get_current_point (cr, &x, &y);
50     cairo_text_path (cr, str);
51
52     cairo_set_source_rgb (cr, 0, .5, 1);
53     cairo_stroke(cr);
54
55     cairo_set_source_rgb (cr, 1, .5, 0);
56     cairo_move_to (cr, x, y);
57     cairo_show_text  (cr, str);
58 }
59
60 static cairo_test_status_t
61 draw (cairo_t *cr, int width, int height)
62 {
63     const char *string = "0123456789";
64     cairo_text_extents_t extents;
65
66     cairo_set_source_rgb (cr, 1, 1, 1);
67     cairo_paint (cr);
68
69     cairo_text_extents (cr, string, &extents);
70
71     cairo_set_font_size (cr, 12);
72     cairo_set_line_width (cr, 3);
73     cairo_move_to (cr, 9, 4 + extents.height);
74     halo_around_path (cr, string);
75
76     cairo_move_to (cr, 109, 4 + extents.height);
77     halo_around_text (cr, string);
78
79     cairo_set_font_size (cr, 6);
80     cairo_set_line_width (cr, 3);
81     cairo_move_to (cr, 19 + extents.width, 20 + extents.height);
82     halo_around_path (cr, "0");
83
84     cairo_move_to (cr, 119 + extents.width, 20 + extents.height);
85     halo_around_text (cr, "0");
86
87     cairo_set_font_size (cr, 64);
88     cairo_set_line_width (cr, 10);
89     cairo_move_to (cr, 8, 70);
90     halo_around_path (cr, "6");
91     cairo_move_to (cr, 32, 90);
92     halo_around_path (cr, "7");
93
94     cairo_move_to (cr, 108, 70);
95     halo_around_text (cr, "6");
96     cairo_move_to (cr, 132, 90);
97     halo_around_text (cr, "7");
98
99     return CAIRO_TEST_SUCCESS;
100 }
101
102 static cairo_test_status_t
103 draw_transform (cairo_t *cr, int width, int height)
104 {
105     const char *string = "0123456789";
106     cairo_text_extents_t extents;
107
108     cairo_translate (cr, 50, 50);
109     cairo_scale (cr, M_SQRT2, M_SQRT2);
110
111     cairo_set_source_rgb (cr, 1, 1, 1);
112     cairo_paint (cr);
113
114     cairo_text_extents (cr, string, &extents);
115
116     cairo_set_line_width (cr, 3);
117     cairo_move_to (cr, 9, 4 + extents.height);
118     halo_around_path (cr, string);
119
120     cairo_move_to (cr, 109, 4 + extents.height);
121     halo_around_text (cr, string);
122
123     cairo_set_font_size (cr, 6);
124     cairo_set_line_width (cr, 3);
125     cairo_move_to (cr, 19 + extents.width, 20 + extents.height);
126     halo_around_path (cr, "0");
127
128     cairo_move_to (cr, 119 + extents.width, 20 + extents.height);
129     halo_around_text (cr, "0");
130
131     cairo_set_font_size (cr, 64);
132     cairo_set_line_width (cr, 10);
133     cairo_move_to (cr, 8, 70);
134     halo_around_path (cr, "6");
135     cairo_move_to (cr, 32, 90);
136     halo_around_path (cr, "7");
137
138     cairo_move_to (cr, 108, 70);
139     halo_around_text (cr, "6");
140     cairo_move_to (cr, 132, 90);
141     halo_around_text (cr, "7");
142
143     return CAIRO_TEST_SUCCESS;
144 }
145
146 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 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)