2 * Copyright 2010 Intel Corporation
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 * Author: Chris Wilson <chris@chris-wilson.co.uk>
27 #include "cairo-test.h"
29 /* Try to replicate the misbehaviour of show_glyphs() versus glyph_path()
30 * in the PDF backend reported by Ian Britten.
34 halo_around_path (cairo_t *cr, const char *str)
36 cairo_text_path (cr, str);
38 cairo_set_source_rgb (cr, 0, .5, 1);
39 cairo_stroke_preserve (cr);
40 cairo_set_source_rgb (cr, 1, .5, 0);
45 halo_around_text (cairo_t *cr, const char *str)
49 cairo_get_current_point (cr, &x, &y);
50 cairo_text_path (cr, str);
52 cairo_set_source_rgb (cr, 0, .5, 1);
55 cairo_set_source_rgb (cr, 1, .5, 0);
56 cairo_move_to (cr, x, y);
57 cairo_show_text (cr, str);
60 static cairo_test_status_t
61 draw (cairo_t *cr, int width, int height)
63 const char *string = "0123456789";
64 cairo_text_extents_t extents;
66 cairo_set_source_rgb (cr, 1, 1, 1);
69 cairo_text_extents (cr, string, &extents);
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);
76 cairo_move_to (cr, 109, 4 + extents.height);
77 halo_around_text (cr, string);
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");
84 cairo_move_to (cr, 119 + extents.width, 20 + extents.height);
85 halo_around_text (cr, "0");
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");
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");
99 return CAIRO_TEST_SUCCESS;
102 static cairo_test_status_t
103 draw_transform (cairo_t *cr, int width, int height)
105 const char *string = "0123456789";
106 cairo_text_extents_t extents;
108 cairo_translate (cr, 50, 50);
109 cairo_scale (cr, M_SQRT2, M_SQRT2);
111 cairo_set_source_rgb (cr, 1, 1, 1);
114 cairo_text_extents (cr, string, &extents);
116 cairo_set_line_width (cr, 3);
117 cairo_move_to (cr, 9, 4 + extents.height);
118 halo_around_path (cr, string);
120 cairo_move_to (cr, 109, 4 + extents.height);
121 halo_around_text (cr, string);
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");
128 cairo_move_to (cr, 119 + extents.width, 20 + extents.height);
129 halo_around_text (cr, "0");
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");
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");
143 return CAIRO_TEST_SUCCESS;
147 "Check the show_glyphs() vs glyph_path()",
148 "text", /* keywords */
149 NULL, /* requirements */
153 CAIRO_TEST (halo_transform,
154 "Check the show_glyphs() vs glyph_path()",
155 "text", /* keywords */
156 NULL, /* requirements */
158 NULL, draw_transform)