[test] Test handling of out-of-range glyph indexes. (#9530) --- commit 04205f2043a76783c0da339f2320c03f7cd87ee8 tree 21a32041cccbbb43196718fdd44024485ae8f05d parent 1002d016834926a771aa0a6cc4bdf83cb009173a author Brian Ewins Sat, 13 Jan 2007 19:18:03 +0000 committer Brian Ewins Sat, 13 Jan 2007 19:18:03 +0000 test/Makefile.am | 3 + test/text-glyph-range-ref.png | Bin test/text-glyph-range-rgb24-ref.png | Bin test/text-glyph-range.c | 111 +++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 0 deletions(-) diff --git a/test/Makefile.am b/test/Makefile.am index efdb162..b8dba07 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -88,6 +88,7 @@ text-antialias-gray \ text-antialias-none \ text-antialias-subpixel \ text-cache-crash \ +text-glyph-range \ text-pattern \ text-rotate \ text-zero-len \ @@ -315,6 +316,7 @@ surface-pattern-ref.png \ text-antialias-gray-ref.png \ text-antialias-none-ref.png \ text-antialias-subpixel-ref.png \ +text-glyph-range-ref.png \ text-pattern-ref.png \ text-pattern-rgb24-ref.png \ text-pattern-svg-argb32-ref.png \ @@ -353,6 +355,7 @@ ft-text-vertical-layout-type1 \ leaky-dash \ long-lines \ self-intersecting \ +text-glyph-range \ text-rotate # Any test that doesn't generate a log file goes here diff --git a/test/text-glyph-range-ref.png b/test/text-glyph-range-ref.png new file mode 100644 index 0000000..086aa4a Binary files /dev/null and b/test/text-glyph-range-ref.png differ diff --git a/test/text-glyph-range-rgb24-ref.png b/test/text-glyph-range-rgb24-ref.png new file mode 100644 index 0000000..9e8232c Binary files /dev/null and b/test/text-glyph-range-rgb24-ref.png differ diff --git a/test/text-glyph-range.c b/test/text-glyph-range.c new file mode 100644 index 0000000..1e7cbaf --- /dev/null +++ b/test/text-glyph-range.c @@ -0,0 +1,111 @@ +/* + * Copyright © 2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Brian Ewins + */ + +/* Related to bug 9530 + * + * glyph_extents should always return extents, whether or not the glyphs are + * out of range. + */ + +#include "cairo-test.h" + +#define WIDTH 100 +#define HEIGHT 75 +#define NUM_TEXT 20 +#define TEXT_SIZE 12 + +static cairo_test_draw_function_t draw; + +cairo_test_t test = { + "text-glyph-range", + "Tests show_glyphs, glyph_path, glyph_extents with uncommon and out of range glyph ids.", + WIDTH, HEIGHT, + draw +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_text_extents_t extents; + /* Glyphs with no paths followed by 'cairo', the additional + * text is to make the space obvious. + */ + long int index[] = { + 0, /* 'no matching glyph' */ + 0xffff, /* kATSDeletedGlyphCode */ + 0x1ffff, /* out of range */ + -1L, /* out of range */ + 70, 68, 76, 85, 82 /* 'cairo' */ + }; + int i; + + /* We draw in the default black, so paint white first. */ + cairo_save (cr); + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ + cairo_paint (cr); + cairo_restore (cr); + + cairo_select_font_face (cr, "Bitstream Vera Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size (cr, 16); + + + /* since we're just drawing glyphs directly we need to position them. */ + for (i = 0; i < 9; i++) { + cairo_glyph_t glyph = { + index[i], 10 * i, 25 + }; + + cairo_move_to (cr, glyph.x, glyph.y); + cairo_set_line_width (cr, 1.0); + cairo_glyph_extents (cr, &glyph, 1, &extents); + + cairo_rectangle (cr, + glyph.x + extents.x_bearing - 0.5, + glyph.y + extents.y_bearing - 0.5, + extents.width + 1, + extents.height + 1); + cairo_set_source_rgb (cr, 1, 0, 0); /* red */ + cairo_stroke (cr); + + cairo_set_source_rgb (cr, 0, 0, 0); /* black */ + cairo_show_glyphs (cr, &glyph, 1); + cairo_move_to (cr, glyph.x, glyph.y); + + glyph.y = 55; + cairo_move_to (cr, glyph.x, glyph.y); + cairo_glyph_path (cr, &glyph, 1); + cairo_fill (cr); + } + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +}