1
/*
2
 * Copyright © 2006 Red Hat, Inc.
3
 * Copyright © 2011 Andrea Canciani
4
 *
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:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
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
23
 * SOFTWARE.
24
 *
25
 * Author: Carl D. Worth <cworth@cworth.org>
26
 *         Andrea Canciani <ranma42@gmail.com>
27
 */
28

            
29
#include "cairo-test.h"
30

            
31
static cairo_test_status_t
32
12
get_glyph (const cairo_test_context_t *ctx,
33
	   cairo_scaled_font_t *scaled_font,
34
	   const char *utf8,
35
	   cairo_glyph_t *glyph)
36
{
37
    cairo_glyph_t *text_to_glyphs;
38
    cairo_status_t status;
39
    int i;
40

            
41
12
    text_to_glyphs = glyph;
42
12
    i = 1;
43
12
    status = cairo_scaled_font_text_to_glyphs (scaled_font,
44
					       0, 0,
45
					       utf8, -1,
46
					       &text_to_glyphs, &i,
47
					       NULL, NULL,
48
					       0);
49
12
    if (status != CAIRO_STATUS_SUCCESS)
50
	return cairo_test_status_from_status (ctx, status);
51

            
52
12
    if (text_to_glyphs != glyph) {
53
	*glyph = text_to_glyphs[0];
54
	cairo_glyph_free (text_to_glyphs);
55
    }
56

            
57
12
    return CAIRO_TEST_SUCCESS;
58
}
59

            
60
static const char *characters[] = { "A", "B", "C", "D" };
61

            
62
#define NUM_CHARS ARRAY_LENGTH (characters)
63

            
64
static cairo_test_status_t
65
3
draw (cairo_t *cr, int width, int height)
66
{
67
3
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
68
    cairo_scaled_font_t *scaled_font;
69
3
    cairo_glyph_t *glyphs = xmalloc (NUM_CHARS  * sizeof (cairo_glyph_t));
70
    int i;
71
    cairo_test_status_t status;
72

            
73
    /* Paint white background. */
74
3
    cairo_set_source_rgb (cr, 1, 1, 1);
75
3
    cairo_paint (cr);
76

            
77
3
    scaled_font = cairo_get_scaled_font (cr);
78

            
79
15
    for (i = 0; i < NUM_CHARS; i++) {
80
12
	status = get_glyph (ctx, scaled_font, characters[i], &glyphs[i]);
81
12
	if (status)
82
	    goto BAIL;
83

            
84
12
	glyphs[i].x = 10.0 + 10.0 * (i % 2);
85
12
	glyphs[i].y = 20.0 + 10.0 * (i / 2);
86
    }
87

            
88
3
    cairo_set_source_rgb (cr, 0, 0, 0);
89
3
    cairo_show_glyphs (cr, glyphs, 4);
90

            
91
3
    cairo_translate (cr, 40., 20.);
92
3
    cairo_rotate (cr, M_PI / 4.);
93

            
94
3
    cairo_show_glyphs (cr, glyphs, NUM_CHARS);
95

            
96
3
  BAIL:
97
3
    free(glyphs);
98

            
99
3
    return status;
100
}
101

            
102
1
CAIRO_TEST (show_glyphs_advance,
103
	    "Test that glyph advances work as expected along both axes",
104
	    "text, matrix", /* keywords */
105
	    NULL, /* requirements */
106
	    64, 64,
107
	    NULL, draw)