2 * Copyright © 2006 Red Hat, Inc.
3 * Copyright © 2011 Andrea Canciani
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Author: Carl D. Worth <cworth@cworth.org>
26 * Andrea Canciani <ranma42@gmail.com>
29 #include "cairo-test.h"
31 static cairo_test_status_t
32 get_glyph (const cairo_test_context_t *ctx,
33 cairo_scaled_font_t *scaled_font,
37 cairo_glyph_t *text_to_glyphs;
38 cairo_status_t status;
41 text_to_glyphs = glyph;
43 status = cairo_scaled_font_text_to_glyphs (scaled_font,
49 if (status != CAIRO_STATUS_SUCCESS)
50 return cairo_test_status_from_status (ctx, status);
52 if (text_to_glyphs != glyph) {
53 *glyph = text_to_glyphs[0];
54 cairo_glyph_free (text_to_glyphs);
57 return CAIRO_TEST_SUCCESS;
60 static const char *characters[] = { "A", "B", "C", "D" };
62 #define NUM_CHARS ARRAY_LENGTH (characters)
64 static cairo_test_status_t
65 draw (cairo_t *cr, int width, int height)
67 const cairo_test_context_t *ctx = cairo_test_get_context (cr);
68 cairo_scaled_font_t *scaled_font;
69 cairo_glyph_t *glyphs = xmalloc (NUM_CHARS * sizeof (cairo_glyph_t));
71 cairo_status_t status;
73 /* Paint white background. */
74 cairo_set_source_rgb (cr, 1, 1, 1);
77 scaled_font = cairo_get_scaled_font (cr);
79 for (i = 0; i < NUM_CHARS; i++) {
80 status = get_glyph (ctx, scaled_font, characters[i], &glyphs[i]);
84 glyphs[i].x = 10.0 + 10.0 * (i % 2);
85 glyphs[i].y = 20.0 + 10.0 * (i / 2);
88 cairo_set_source_rgb (cr, 0, 0, 0);
89 cairo_show_glyphs (cr, glyphs, 4);
91 cairo_translate (cr, 40., 20.);
92 cairo_rotate (cr, M_PI / 4.);
94 cairo_show_glyphs (cr, glyphs, NUM_CHARS);
102 CAIRO_TEST (show_glyphs_advance,
103 "Test that glyph advances work as expected along both axes",
104 "text, matrix", /* keywords */
105 NULL, /* requirements */