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
3
 *
4
 * Copyright © 2006 Brian Ewins.
5
 *
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.
16
 *
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.
24
 *
25
 * Author: Brian Ewins <Brian.Ewins@gmail.com>
26
 */
27

            
28
/* Related to bug 9530
29
 *
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
37
 * consistently.
38
 *
39
 * This test expects that operations on out-of-range and missing glyphs should
40
 * act as if they were zero-width.
41
 */
42

            
43
#include "cairo-test.h"
44

            
45
#define WIDTH  100
46
#define HEIGHT 75
47
#define NUM_TEXT 20
48
#define TEXT_SIZE 12
49

            
50
static cairo_test_status_t
51
3
draw (cairo_t *cr, int width, int height)
52
{
53
    cairo_text_extents_t extents;
54
    int i;
55
    /* Glyphs with no paths followed by 'cairo', the additional
56
     * text is to make the space obvious.
57
     */
58
3
    long int index[] = {
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' */
64
    };
65

            
66
    /* We draw in the default black, so paint white first. */
67
3
    cairo_save (cr);
68
3
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
69
3
    cairo_paint (cr);
70
3
    cairo_restore (cr);
71

            
72
3
    cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
73
			    CAIRO_FONT_SLANT_NORMAL,
74
			    CAIRO_FONT_WEIGHT_NORMAL);
75
3
    cairo_set_font_size (cr, 16);
76

            
77
30
    for (i = 0; i < 9; i++) {
78
	/* since we're just drawing glyphs directly we need to position them. */
79
27
	cairo_glyph_t glyph = {
80
27
	    index[i], 10 * i, 25
81
	};
82

            
83
	/* test cairo_glyph_extents. Every glyph index should
84
	 * have extents, invalid glyphs should be zero-width.
85
	 */
86
27
	cairo_move_to (cr, glyph.x, glyph.y);
87
27
	cairo_set_line_width (cr, 1.0);
88
27
	cairo_glyph_extents (cr, &glyph, 1, &extents);
89
27
	cairo_rectangle (cr,
90
27
			 glyph.x + extents.x_bearing - 0.5,
91
27
			 glyph.y + extents.y_bearing - 0.5,
92
27
			 extents.width + 1,
93
27
			 extents.height + 1);
94
27
	cairo_set_source_rgb (cr, 1, 0, 0); /* red */
95
27
	cairo_stroke (cr);
96

            
97
	/* test cairo_show_glyphs. Every glyph index should be
98
	 * drawable, invalid glyph indexes should draw nothing.
99
	 */
100
27
	cairo_set_source_rgb (cr, 0, 0, 0); /* black */
101
27
	cairo_show_glyphs (cr, &glyph, 1);
102
27
	cairo_move_to (cr, glyph.x, glyph.y);
103

            
104
	/* test cairo_glyph_path. Every glyph index should produce
105
	 * a path, invalid glyph indexes should have empty paths.
106
	 */
107
	/* Change the glyph position
108
	 * so that the paths are visible.
109
	 */
110
27
	glyph.y = 55;
111
27
	cairo_move_to (cr, glyph.x, glyph.y);
112
27
	cairo_glyph_path (cr, &glyph, 1);
113
27
	cairo_fill (cr);
114
    }
115

            
116
3
    return CAIRO_TEST_SUCCESS;
117
}
118

            
119
1
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 */
124
	    WIDTH, HEIGHT,
125
	    NULL, draw)