2 * Copyright © 2008 Adrian Johnson
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 * Author: Adrian Johnson <ajohnson@redneon.com>
27 #include "cairo-test.h"
32 static cairo_test_draw_function_t draw
;
35 "ft-show-glyphs-positioning",
36 "Test that the PS/PDF glyph positioning optimizations are correct",
37 235, (TEXT_SIZE
+ 4)*2,
42 cairo_glyph_t glyph_list
[100];
49 glyph_array_init (glyph_array_t
*glyphs
, double x
, double y
)
51 glyphs
->num_glyphs
= 0;
57 glyph_array_rel_move_to (glyph_array_t
*glyphs
, double x
, double y
)
64 glyph_array_show (glyph_array_t
*glyphs
, cairo_t
*cr
)
66 cairo_show_glyphs (cr
, glyphs
->glyph_list
, glyphs
->num_glyphs
);
69 #define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
72 glyph_array_add_text(glyph_array_t
*glyphs
, cairo_t
*cr
, const char *s
, double spacing
)
74 cairo_scaled_font_t
*scaled_font
;
76 unsigned long charcode
;
78 cairo_text_extents_t extents
;
84 scaled_font
= cairo_get_scaled_font (cr
);
85 face
= cairo_ft_scaled_font_lock_face (scaled_font
);
90 index
= FT_Get_Char_Index (face
, charcode
);
91 glyphs
->glyph_list
[glyphs
->num_glyphs
].index
= index
;
94 glyphs
->glyph_list
[glyphs
->num_glyphs
].x
= glyphs
->x
;
95 glyphs
->glyph_list
[glyphs
->num_glyphs
].y
= glyphs
->y
;
97 cairo_glyph_extents (cr
, &glyphs
->glyph_list
[glyphs
->num_glyphs
- 1], 1, &extents
);
99 glyphs
->glyph_list
[glyphs
->num_glyphs
- 1].index
,
100 glyphs
->glyph_list
[glyphs
->num_glyphs
].index
,
103 kern_x
= DOUBLE_FROM_26_6(kerning
.x
);
104 glyphs
->glyph_list
[glyphs
->num_glyphs
].x
=
105 glyphs
->glyph_list
[glyphs
->num_glyphs
- 1].x
+ extents
.x_advance
+ kern_x
+ spacing
;
106 glyphs
->glyph_list
[glyphs
->num_glyphs
].y
=
107 glyphs
->glyph_list
[glyphs
->num_glyphs
- 1].y
+ extents
.y_advance
;
110 cairo_glyph_extents (cr
, &glyphs
->glyph_list
[glyphs
->num_glyphs
], 1, &extents
);
111 glyphs
->x
= glyphs
->glyph_list
[glyphs
->num_glyphs
].x
+ extents
.x_advance
+ spacing
;
112 glyphs
->y
= glyphs
->glyph_list
[glyphs
->num_glyphs
].y
+ extents
.y_advance
;
114 glyphs
->num_glyphs
++;
117 cairo_ft_scaled_font_unlock_face (scaled_font
);
120 static cairo_test_status_t
121 draw (cairo_t
*cr
, int width
, int height
)
123 glyph_array_t glyphs
;
124 cairo_font_options_t
*font_options
;
126 /* paint white so we don't need separate ref images for
127 * RGB24 and ARGB32 */
128 cairo_set_source_rgb (cr
, 1.0, 1.0, 1.0);
131 cairo_select_font_face (cr
, "Bitstream Vera Sans",
132 CAIRO_FONT_SLANT_NORMAL
,
133 CAIRO_FONT_WEIGHT_NORMAL
);
134 cairo_set_font_size (cr
, TEXT_SIZE
);
136 font_options
= cairo_font_options_create ();
137 cairo_get_font_options (cr
, font_options
);
138 cairo_font_options_set_hint_metrics (font_options
, CAIRO_HINT_METRICS_OFF
);
139 cairo_set_font_options (cr
, font_options
);
140 cairo_font_options_destroy (font_options
);
142 cairo_set_source_rgb (cr
, 0.0, 0.0, 0.0);
144 glyph_array_init (&glyphs
, 1, TEXT_SIZE
);
145 glyph_array_add_text(&glyphs
, cr
, "AWAY again", 0.0);
146 glyph_array_rel_move_to (&glyphs
, TEXT_SIZE
*1, 0.0);
147 glyph_array_add_text(&glyphs
, cr
, "character space", TEXT_SIZE
*0.3);
148 glyph_array_show (&glyphs
, cr
);
150 glyph_array_init (&glyphs
, 1, TEXT_SIZE
*2 + 4);
151 glyph_array_add_text(&glyphs
, cr
, "Increasing", 0.0);
152 glyph_array_rel_move_to (&glyphs
, TEXT_SIZE
*0.5, 0.0);
153 glyph_array_add_text(&glyphs
, cr
, "space", 0.0);
154 glyph_array_rel_move_to (&glyphs
, TEXT_SIZE
*1.0, 0.0);
155 glyph_array_add_text(&glyphs
, cr
, "between", 0.0);
156 glyph_array_rel_move_to (&glyphs
, TEXT_SIZE
*1.5, 0.0);
157 glyph_array_add_text(&glyphs
, cr
, "words", 0.0);
158 glyph_array_show (&glyphs
, cr
);
160 return CAIRO_TEST_SUCCESS
;
166 return cairo_test (&test
);