2 * Copyright © 2008 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Authors: Eugeniy Meshcheryakov <eugen@debian.org>
25 * Adrian Johnson <ajohnson@redneon.com>
26 * Carl Worth <cworth@cworth.org>
29 #include "cairo-test.h"
37 #define NUM_GLYPHS (GRID_ROWS * GRID_COLS)
38 #define WIDTH (PAD + GRID_COLS * GRID_SIZE + PAD)
39 #define HEIGHT (PAD + GRID_ROWS * GRID_SIZE + PAD)
41 /* This test was originally inspired by this bug report:
43 * Error when creating pdf charts for new FreeSerifItalic.ttf
44 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%23474136
46 * The original assertion failure was fairly boring, but the later
47 * glyph mispositiing was quite interesting. And it turns out that the
48 * _cairo_pdf_operators_show_glyphs code is fairly convoluted with a
49 * code path that wasn't being exercised at all by the test suite.
51 * So this is an attempt to exercise that code path. Apparently laying
52 * glyphs out vertically in a table like this, (so that there's a
53 * large change in Y position from one glyph to the next), exercises
57 static cairo_test_status_t
58 draw (cairo_t *cr, int width, int height)
60 cairo_font_options_t *font_options;
61 cairo_scaled_font_t *scaled_font;
66 cairo_glyph_t glyphs[NUM_GLYPHS];
68 /* paint white so we don't need separate ref images for
70 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
73 cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
74 CAIRO_FONT_SLANT_NORMAL,
75 CAIRO_FONT_WEIGHT_NORMAL);
76 cairo_set_font_size (cr, TEXT_SIZE);
78 font_options = cairo_font_options_create ();
79 cairo_get_font_options (cr, font_options);
80 cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
81 cairo_set_font_options (cr, font_options);
82 cairo_font_options_destroy (font_options);
84 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
86 scaled_font = cairo_get_scaled_font (cr);
87 face = cairo_ft_scaled_font_lock_face (scaled_font);
89 charcode = FT_Get_First_Char(face, &idx);
90 while (idx && (i < NUM_GLYPHS)) {
91 glyphs[i] = (cairo_glyph_t) {idx, PAD + GRID_SIZE * (i/GRID_ROWS), PAD + TEXT_SIZE + GRID_SIZE * (i%GRID_ROWS)};
93 charcode = FT_Get_Next_Char(face, charcode, &idx);
96 cairo_ft_scaled_font_unlock_face (scaled_font);
98 cairo_show_glyphs(cr, glyphs, i);
100 return CAIRO_TEST_SUCCESS;
103 CAIRO_TEST (ft_show_glyphs_table,
104 "Test cairo_show_glyphs with cairo-ft backend and glyphs laid out in a table",
105 "ft, text", /* keywords */
106 NULL, /* requirements */