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 consistently.
38 * This test expects that operations on out-of-range and missing glyphs should
39 * act as if they were zero-width.
42 #include "cairo-test.h"
49 static cairo_test_draw_function_t draw
;
53 "Tests show_glyphs, glyph_path, glyph_extents with out of range glyph ids."
54 "\nft and atsui font backends fail, misreporting errors from FT_Load_Glyph and ATSUGlyphGetCubicPaths",
59 static cairo_test_status_t
60 draw (cairo_t
*cr
, int width
, int height
)
62 cairo_text_extents_t extents
;
64 /* Glyphs with no paths followed by 'cairo', the additional
65 * text is to make the space obvious.
68 0, /* 'no matching glyph' */
69 0xffff, /* kATSDeletedGlyphCode */
70 0x1ffff, /* out of range */
71 -1L, /* out of range */
72 70, 68, 76, 85, 82 /* 'cairo' */
75 /* We draw in the default black, so paint white first. */
77 cairo_set_source_rgb (cr
, 1.0, 1.0, 1.0); /* white */
81 cairo_select_font_face (cr
, "Bitstream Vera Sans",
82 CAIRO_FONT_SLANT_NORMAL
,
83 CAIRO_FONT_WEIGHT_NORMAL
);
84 cairo_set_font_size (cr
, 16);
87 for (i
= 0; i
< 9; i
++) {
88 /* since we're just drawing glyphs directly we need to position them. */
89 cairo_glyph_t glyph
= {
93 /* test cairo_glyph_extents. Every glyph index should
94 * have extents, invalid glyphs should be zero-width.
96 cairo_move_to (cr
, glyph
.x
, glyph
.y
);
97 cairo_set_line_width (cr
, 1.0);
98 cairo_glyph_extents (cr
, &glyph
, 1, &extents
);
100 glyph
.x
+ extents
.x_bearing
- 0.5,
101 glyph
.y
+ extents
.y_bearing
- 0.5,
104 cairo_set_source_rgb (cr
, 1, 0, 0); /* red */
107 /* test cairo_show_glyphs. Every glyph index should be
108 * drawable, invalid glyph indexes should draw nothing.
110 cairo_set_source_rgb (cr
, 0, 0, 0); /* black */
111 cairo_show_glyphs (cr
, &glyph
, 1);
112 cairo_move_to (cr
, glyph
.x
, glyph
.y
);
114 /* test cairo_glyph_path. Every glyph index should produce
115 * a path, invalid glyph indexes should have empty paths.
117 /* Change the glyph position
118 * so that the paths are visible.
121 cairo_move_to (cr
, glyph
.x
, glyph
.y
);
122 cairo_glyph_path (cr
, &glyph
, 1);
126 return CAIRO_TEST_SUCCESS
;
132 return cairo_test (&test
);