1
/*
2
 * Copyright © 2008 Red Hat, Inc.
3
 *
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:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
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
22
 * SOFTWARE.
23
 *
24
 * Authors: Eugeniy Meshcheryakov <eugen@debian.org>
25
 *	    Adrian Johnson <ajohnson@redneon.com>
26
 *	    Carl Worth <cworth@cworth.org>
27
 */
28

            
29
#include "cairo-test.h"
30
#include <cairo-ft.h>
31

            
32
#define TEXT_SIZE	20
33
#define PAD		10
34
#define GRID_SIZE	30
35
#define GRID_ROWS	10
36
#define GRID_COLS	4
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)
40

            
41
/* This test was originally inspired by this bug report:
42
 *
43
 * Error when creating pdf charts for new FreeSerifItalic.ttf
44
 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%23474136
45
 *
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.
50
 *
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
54
 * the code well.
55
 */
56

            
57
static cairo_test_status_t
58
3
draw (cairo_t *cr, int width, int height)
59
{
60
    cairo_font_options_t *font_options;
61
    cairo_scaled_font_t *scaled_font;
62
    FT_Face face;
63
    FT_ULong charcode;
64
    FT_UInt idx;
65
3
    int i = 0;
66
    cairo_glyph_t glyphs[NUM_GLYPHS];
67

            
68
    /* paint white so we don't need separate ref images for
69
     * RGB24 and ARGB32 */
70
3
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
71
3
    cairo_paint (cr);
72

            
73
3
    cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
74
			    CAIRO_FONT_SLANT_NORMAL,
75
			    CAIRO_FONT_WEIGHT_NORMAL);
76
3
    cairo_set_font_size (cr, TEXT_SIZE);
77

            
78
3
    font_options = cairo_font_options_create ();
79
3
    cairo_get_font_options (cr, font_options);
80
3
    cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
81
3
    cairo_set_font_options (cr, font_options);
82
3
    cairo_font_options_destroy (font_options);
83

            
84
3
    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
85

            
86
3
    scaled_font = cairo_get_scaled_font (cr);
87
3
    face = cairo_ft_scaled_font_lock_face (scaled_font);
88
    {
89
3
	charcode = FT_Get_First_Char(face, &idx);
90
123
	while (idx && (i < NUM_GLYPHS)) {
91
120
	    glyphs[i] = (cairo_glyph_t) {idx, PAD + GRID_SIZE * (i/GRID_ROWS), PAD + TEXT_SIZE + GRID_SIZE * (i%GRID_ROWS)};
92
120
	    i++;
93
120
	    charcode = FT_Get_Next_Char(face, charcode, &idx);
94
	}
95
    }
96
3
    cairo_ft_scaled_font_unlock_face (scaled_font);
97

            
98
3
    cairo_show_glyphs(cr, glyphs, i);
99

            
100
3
    return CAIRO_TEST_SUCCESS;
101
}
102

            
103
1
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 */
107
	    WIDTH, HEIGHT,
108
	    NULL, draw)
109