[cairo-commit] test/Makefile.am test/text-glyph-range.c
test/text-glyph-range-ref.png test/text-glyph-range-rgb24-ref.png
Brian Ewins
brianewins at kemper.freedesktop.org
Mon Jan 15 17:26:57 PST 2007
test/Makefile.am | 4 +
test/text-glyph-range-ref.png |binary
test/text-glyph-range-rgb24-ref.png |binary
test/text-glyph-range.c | 133 ++++++++++++++++++++++++++++++++++++
4 files changed, 137 insertions(+)
New commits:
diff-tree 9e332eadad00e115fdcdbc816608a0537f5a9b9c (from 9cabf5b5f7dd840f91b5be29567cf11cf40fc998)
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date: Tue Jan 16 01:25:53 2007 +0000
[test] Test handling of out-of-range glyph indexes. (#9530)
Adds a test for missing and out-of-range glyph indexes. The expected
ATSUI renderings are added as references, please replace these with
FT renderings when they become available.
diff --git a/test/Makefile.am b/test/Makefile.am
index efdb162..f675a29 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,8 @@ 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-glyph-range-rgb24-ref.png \
text-pattern-ref.png \
text-pattern-rgb24-ref.png \
text-pattern-svg-argb32-ref.png \
@@ -353,6 +356,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..2af48a2
--- /dev/null
+++ b/test/text-glyph-range.c
@@ -0,0 +1,133 @@
+/* -*- Mode: c; c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t; -*- */
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2006 Brian Ewins.
+ *
+ * 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
+ * Brian Ewins not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Brian Ewins makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * BRIAN EWINS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL BRIAN EWINS 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 <Brian.Ewins at gmail.com>
+ */
+
+/* Related to bug 9530
+ *
+ * cairo_glyph_t can contain any unsigned long in its 'index', the intention
+ * being that it is large enough to hold a pointer. However, this means that
+ * it can specify many glyph indexes which don't exist in the font, and may
+ * exceed the range of legal glyph indexes for the font backend. It may
+ * also contain special values that are not usable as indexes - e.g. 0xffff is
+ * kATSDeletedGlyphcode in ATSUI, a glyph that should not be drawn.
+ * The font backends should handle all legal and out-of-range values consistently.
+ *
+ * This test expects that operations on out-of-range and missing glyphs should
+ * act as if they were zero-width.
+ */
+
+#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 out of range glyph ids."
+ "\nft and atsui font backends fail, misreporting errors from FT_Load_Glyph and ATSUGlyphGetCubicPaths",
+ WIDTH, HEIGHT,
+ draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ cairo_text_extents_t extents;
+ int i;
+ /* 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' */
+ };
+
+ /* 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);
+
+
+ for (i = 0; i < 9; i++) {
+ /* since we're just drawing glyphs directly we need to position them. */
+ cairo_glyph_t glyph = {
+ index[i], 10 * i, 25
+ };
+
+ /* test cairo_glyph_extents. Every glyph index should
+ * have extents, invalid glyphs should be zero-width.
+ */
+ 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);
+
+ /* test cairo_show_glyphs. Every glyph index should be
+ * drawable, invalid glyph indexes should draw nothing.
+ */
+ cairo_set_source_rgb (cr, 0, 0, 0); /* black */
+ cairo_show_glyphs (cr, &glyph, 1);
+ cairo_move_to (cr, glyph.x, glyph.y);
+
+ /* test cairo_glyph_path. Every glyph index should produce
+ * a path, invalid glyph indexes should have empty paths.
+ */
+ /* Change the glyph position
+ * so that the paths are visible.
+ */
+ 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);
+}
More information about the cairo-commit
mailing list