1 /* -*- Mode: c; c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t; -*- */
2 /* cairo - a vector graphics library with display and print output
4 * Copyright © 2006 Brian Ewins.
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without
8 * fee, provided that the above copyright notice appear in all copies
9 * and that both that copyright notice and this permission notice
10 * appear in supporting documentation, and that the name of
11 * Brian Ewins not be used in advertising or publicity pertaining to
12 * distribution of the software without specific, written prior
13 * permission. Brian Ewins makes no representations about the
14 * suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
17 * BRIAN EWINS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL BRIAN EWINS BE LIABLE FOR ANY SPECIAL,
20 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
22 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
23 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * Author: Brian Ewins <Brian.Ewins@gmail.com>
28 /* Related to bug 9530
30 * cairo_glyph_t can contain any unsigned long in its 'index', the intention
31 * being that it is large enough to hold a pointer. However, this means that
32 * it can specify many glyph indexes which don't exist in the font, and may
33 * exceed the range of legal glyph indexes for the font backend. It may
34 * also contain special values that are not usable as indexes - e.g. 0xffff is
35 * kATSDeletedGlyphcode in ATSUI, a glyph that should not be drawn.
36 * The font backends should handle all legal and out-of-range values
39 * This test expects that operations on out-of-range and missing glyphs should
40 * act as if they were zero-width.
43 #include "cairo-test.h"
50 static cairo_test_status_t
51 draw (cairo_t *cr, int width, int height)
53 cairo_text_extents_t extents;
55 /* Glyphs with no paths followed by 'cairo', the additional
56 * text is to make the space obvious.
59 0, /* 'no matching glyph' */
60 0xffff, /* kATSDeletedGlyphCode */
61 0x1ffff, /* out of range */
62 -1L, /* out of range */
63 70, 68, 76, 85, 82 /* 'cairo' */
66 /* We draw in the default black, so paint white first. */
68 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
72 cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
73 CAIRO_FONT_SLANT_NORMAL,
74 CAIRO_FONT_WEIGHT_NORMAL);
75 cairo_set_font_size (cr, 16);
77 for (i = 0; i < 9; i++) {
78 /* since we're just drawing glyphs directly we need to position them. */
79 cairo_glyph_t glyph = {
83 /* test cairo_glyph_extents. Every glyph index should
84 * have extents, invalid glyphs should be zero-width.
86 cairo_move_to (cr, glyph.x, glyph.y);
87 cairo_set_line_width (cr, 1.0);
88 cairo_glyph_extents (cr, &glyph, 1, &extents);
90 glyph.x + extents.x_bearing - 0.5,
91 glyph.y + extents.y_bearing - 0.5,
94 cairo_set_source_rgb (cr, 1, 0, 0); /* red */
97 /* test cairo_show_glyphs. Every glyph index should be
98 * drawable, invalid glyph indexes should draw nothing.
100 cairo_set_source_rgb (cr, 0, 0, 0); /* black */
101 cairo_show_glyphs (cr, &glyph, 1);
102 cairo_move_to (cr, glyph.x, glyph.y);
104 /* test cairo_glyph_path. Every glyph index should produce
105 * a path, invalid glyph indexes should have empty paths.
107 /* Change the glyph position
108 * so that the paths are visible.
111 cairo_move_to (cr, glyph.x, glyph.y);
112 cairo_glyph_path (cr, &glyph, 1);
116 return CAIRO_TEST_SUCCESS;
119 CAIRO_TEST (text_glyph_range,
120 "Tests show_glyphs, glyph_path, glyph_extents with out of range glyph ids."
121 "\nft and atsui font backends fail, misreporting errors from FT_Load_Glyph and ATSUGlyphGetCubicPaths",
122 "text, stress", /* keywords */
123 NULL, /* requirements */