2 * Copyright © 2009 Chris Wilson
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 * Chris Wilson not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Chris Wilson makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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.
23 * Author: Chris Wilson <chris@chris-wilson.co.uk>
26 #include "cairo-test.h"
31 #define HEIGHT (TEXT_SIZE + 4)
36 static cairo_test_status_t
37 draw (cairo_t *cr, int width, int height)
39 cairo_glyph_t glyphs_stack[MAX_GLYPHS], *glyphs;
40 const char *cairo = "Cairo";
41 const char *giza = "Giza";
42 cairo_text_extents_t cairo_extents;
43 cairo_text_extents_t giza_extents;
44 int count, num_glyphs;
47 /* We draw in the default black, so paint white first. */
48 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
51 cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
52 CAIRO_FONT_SLANT_NORMAL,
53 CAIRO_FONT_WEIGHT_NORMAL);
54 cairo_set_font_size (cr, TEXT_SIZE);
56 /* We want to overlap two strings, so compute overlapping glyphs. */
58 cairo_text_extents (cr, cairo, &cairo_extents);
59 cairo_text_extents (cr, giza, &giza_extents);
61 x0 = WIDTH/2. - (cairo_extents.width/2. + cairo_extents.x_bearing);
62 y0 = HEIGHT/2. - (cairo_extents.height/2. + cairo_extents.y_bearing);
63 glyphs = glyphs_stack;
65 cairo_scaled_font_text_to_glyphs (cairo_get_scaled_font (cr),
67 cairo, strlen (cairo),
71 assert (glyphs == glyphs_stack);
74 x0 = WIDTH/2. - (giza_extents.width/2. + giza_extents.x_bearing);
75 y0 = HEIGHT/2. - (giza_extents.height/2. + giza_extents.y_bearing);
76 glyphs = glyphs_stack + count;
77 count = MAX_GLYPHS - count;
78 cairo_scaled_font_text_to_glyphs (cairo_get_scaled_font (cr),
84 assert (glyphs == glyphs_stack + num_glyphs);
85 glyphs = glyphs_stack;
88 cairo_set_source_rgba (cr, 0, 0, 0, .5); /* translucent black, gray! */
89 cairo_show_glyphs (cr, glyphs, num_glyphs);
91 /* and compare with filling */
92 cairo_translate (cr, 0, HEIGHT);
93 cairo_glyph_path (cr, glyphs, num_glyphs);
96 /* switch to using an unbounded operator for added complexity */
97 cairo_set_operator (cr, CAIRO_OPERATOR_IN);
99 cairo_translate (cr, WIDTH, -HEIGHT);
101 cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
103 cairo_show_glyphs (cr, glyphs, num_glyphs);
106 cairo_translate (cr, 0, HEIGHT);
108 cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
110 cairo_glyph_path (cr, glyphs, num_glyphs);
114 return CAIRO_TEST_SUCCESS;
117 CAIRO_TEST (overlapping_glyphs,
118 "Test handing of overlapping glyphs",
119 "text, glyphs", /* keywords */
120 NULL, /* requirements */
121 2 * WIDTH, 2 * HEIGHT,