2 * Copyright © 2006 Red Hat, Inc.
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 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. 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 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Carl D. Worth <cworth@cworth.org>
26 #include "cairo-test.h"
32 * 2006-01-07 Jon Hellan <hellan@acm.org>
34 * Jon opened the following bug report:
36 * _XError from XRenderCompositeText8
37 * https://bugs.freedesktop.org/show_bug.cgi?id=5528
39 * 2006-03-02 Carl Worth <cworth@cworth.org>
41 * I wrote this test case to demonstrate the bug.
45 * Draw 65535 glyphs white-on-white all on top of each other.
49 * The number 65535 comes from the original bug report.
51 * I would use cairo_show_text with a long string of 'x's say,
52 * but then the surface would need to be enormous to contain
53 * them. A smaller surface could be used, but I fear that at some
54 * point the off-surface glyph drawing would be optimized away
55 * and not exercise the bug.
57 * So, to keep the surface size under control, I use
58 * cairo_show_glyphs which allows me to place the glyphs all on
59 * top of each other. But, since cairo doesn't provide any
60 * character-to-glyphs mapping, I can't get a reliable glyph
61 * index (for character 'x' for example). So I just "guess" a
62 * glyph index and use white-on-white drawing to ignore the
63 * result. (I don't care what's drawn---I just want to ensure
64 * that things don't crash.)
66 * Status: I replicated bug. The largest value of NUM_GLYPHS for
67 * which I saw success is 21842.
71 #define NUM_GLYPHS 65535
73 /* This is the index into the font for what glyph we'll draw. Since we
74 * don't guarantee we'll get any particular font, we can't relibably
75 * get any particular glyph. But we don't care what we draw anyway,
76 * (see discussion of white-on-white drawing above). For what it's
77 * worth, this appears to be giving me 'M' with Bitstream Vera
79 #define GLYPH_INDEX 48
81 static cairo_test_draw_function_t draw
;
85 "Test that cairo_show_glyps works when handed 'many' glyphs",
90 static cairo_test_status_t
91 draw (cairo_t
*cr
, int width
, int height
)
93 cairo_glyph_t glyphs
[NUM_GLYPHS
];
96 /* Initialize our giant array of glyphs. */
97 for (i
=0; i
< NUM_GLYPHS
; i
++) {
98 glyphs
[i
].index
= GLYPH_INDEX
;
100 glyphs
[i
].y
= height
- 1;
103 /* Paint white background. */
104 cairo_set_source_rgb (cr
, 1.0, 1.0, 1.0); /* white */
107 cairo_select_font_face (cr
, "Bitstream Vera Sans Mono",
108 CAIRO_FONT_SLANT_NORMAL
,
109 CAIRO_FONT_WEIGHT_NORMAL
);
110 cairo_set_font_size (cr
, TEXT_SIZE
);
112 cairo_show_glyphs (cr
, glyphs
, NUM_GLYPHS
);
114 return CAIRO_TEST_SUCCESS
;
120 return cairo_test (&test
);