2 * Copyright © 2019 Adobe Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Adobe Author(s): Michiharu Ariza
30 /* Unit tests for glyph advance widths and extents of TrueType variable fonts */
33 test_extents_tt_var (void)
35 hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansVariable-Roman-nohvar-41,C1.ttf");
37 hb_font_t *font = hb_font_create (face);
38 hb_face_destroy (face);
40 hb_ot_font_set_funcs (font);
42 hb_glyph_extents_t extents;
43 hb_bool_t result = hb_font_get_glyph_extents (font, 2, &extents);
46 g_assert_cmpint (extents.x_bearing, ==, 10);
47 g_assert_cmpint (extents.y_bearing, ==, 846);
48 g_assert_cmpint (extents.width, ==, 500);
49 g_assert_cmpint (extents.height, ==, -846);
51 float coords[1] = { 500.0f };
52 hb_font_set_var_coords_design (font, coords, 1);
53 result = hb_font_get_glyph_extents (font, 2, &extents);
56 g_assert_cmpint (extents.x_bearing, ==, 0);
57 g_assert_cmpint (extents.y_bearing, ==, 874);
58 g_assert_cmpint (extents.width, ==, 551);
59 g_assert_cmpint (extents.height, ==, -874);
61 hb_font_destroy (font);
65 test_advance_tt_var_nohvar (void)
67 hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansVariable-Roman-nohvar-41,C1.ttf");
69 hb_font_t *font = hb_font_create (face);
70 hb_face_destroy (face);
72 hb_ot_font_set_funcs (font);
75 hb_font_get_glyph_advance_for_direction(font, 2, HB_DIRECTION_LTR, &x, &y);
77 g_assert_cmpint (x, ==, 520);
78 g_assert_cmpint (y, ==, 0);
80 hb_font_get_glyph_advance_for_direction(font, 2, HB_DIRECTION_TTB, &x, &y);
82 g_assert_cmpint (x, ==, 0);
83 g_assert_cmpint (y, ==, -1000);
85 float coords[1] = { 500.0f };
86 hb_font_set_var_coords_design (font, coords, 1);
87 hb_font_get_glyph_advance_for_direction(font, 2, HB_DIRECTION_LTR, &x, &y);
89 g_assert_cmpint (x, ==, 551);
90 g_assert_cmpint (y, ==, 0);
92 hb_font_get_glyph_advance_for_direction(font, 2, HB_DIRECTION_TTB, &x, &y);
94 g_assert_cmpint (x, ==, 0);
95 g_assert_cmpint (y, ==, -1000);
97 hb_font_destroy (font);
101 test_advance_tt_var_hvarvvar (void)
103 hb_face_t *face = hb_test_open_font_file ("fonts/SourceSerifVariable-Roman-VVAR.abc.ttf");
105 hb_font_t *font = hb_font_create (face);
106 hb_face_destroy (face);
108 hb_ot_font_set_funcs (font);
111 hb_font_get_glyph_advance_for_direction(font, 1, HB_DIRECTION_LTR, &x, &y);
113 g_assert_cmpint (x, ==, 508);
114 g_assert_cmpint (y, ==, 0);
116 hb_font_get_glyph_advance_for_direction(font, 1, HB_DIRECTION_TTB, &x, &y);
118 g_assert_cmpint (x, ==, 0);
119 g_assert_cmpint (y, ==, -1000);
121 float coords[1] = { 700.0f };
122 hb_font_set_var_coords_design (font, coords, 1);
123 hb_font_get_glyph_advance_for_direction(font, 1, HB_DIRECTION_LTR, &x, &y);
125 g_assert_cmpint (x, ==, 531);
126 g_assert_cmpint (y, ==, 0);
128 hb_font_get_glyph_advance_for_direction(font, 1, HB_DIRECTION_TTB, &x, &y);
130 g_assert_cmpint (x, ==, 0);
131 g_assert_cmpint (y, ==, -1012);
133 hb_font_destroy (font);
137 test_advance_tt_var_anchor (void)
139 hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansVariable-Roman.anchor.ttf");
141 hb_font_t *font = hb_font_create (face);
142 hb_face_destroy (face);
144 hb_ot_font_set_funcs (font);
146 hb_glyph_extents_t extents;
147 hb_bool_t result = hb_font_get_glyph_extents (font, 2, &extents);
150 g_assert_cmpint (extents.x_bearing, ==, 56);
151 g_assert_cmpint (extents.y_bearing, ==, 672);
152 g_assert_cmpint (extents.width, ==, 556);
153 g_assert_cmpint (extents.height, ==, -684);
155 float coords[1] = { 500.0f };
156 hb_font_set_var_coords_design (font, coords, 1);
157 result = hb_font_get_glyph_extents (font, 2, &extents);
160 g_assert_cmpint (extents.x_bearing, ==, 50);
161 g_assert_cmpint (extents.y_bearing, ==, 667);
162 g_assert_cmpint (extents.width, ==, 593);
163 g_assert_cmpint (extents.height, ==, -679);
165 hb_font_destroy (font);
169 test_extents_tt_var_comp (void)
171 hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansVariable-Roman.modcomp.ttf");
173 hb_font_t *font = hb_font_create (face);
174 hb_face_destroy (face);
176 hb_ot_font_set_funcs (font);
178 hb_glyph_extents_t extents;
179 float coords[1] = { 800.0f };
180 hb_font_set_var_coords_design (font, coords, 1);
183 result = hb_font_get_glyph_extents (font, 2, &extents); /* Ccedilla, cedilla y-scaled by 0.8, with unscaled component offset */
186 g_assert_cmpint (extents.x_bearing, ==, 19);
187 g_assert_cmpint (extents.y_bearing, ==, 663);
188 g_assert_cmpint (extents.width, ==, 519);
189 g_assert_cmpint (extents.height, ==, -895);
191 result = hb_font_get_glyph_extents (font, 3, &extents); /* Cacute, acute y-scaled by 0.8, with unscaled component offset (default) */
194 g_assert_cmpint (extents.x_bearing, ==, 19);
195 g_assert_cmpint (extents.y_bearing, ==, 909);
196 g_assert_cmpint (extents.width, ==, 519);
197 g_assert_cmpint (extents.height, ==, -921);
199 result = hb_font_get_glyph_extents (font, 4, &extents); /* Ccaron, caron y-scaled by 0.8, with scaled component offset */
202 g_assert_cmpint (extents.x_bearing, ==, 19);
203 g_assert_cmpint (extents.y_bearing, ==, 866);
204 g_assert_cmpint (extents.width, ==, 519);
205 g_assert_cmpint (extents.height, ==, -878);
207 hb_font_destroy (font);
211 test_advance_tt_var_comp_v (void)
213 hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansVariable-Roman.modcomp.ttf");
215 hb_font_t *font = hb_font_create (face);
216 hb_face_destroy (face);
218 hb_ot_font_set_funcs (font);
220 float coords[1] = { 800.0f };
221 hb_font_set_var_coords_design (font, coords, 1);
224 hb_font_get_glyph_advance_for_direction(font, 2, HB_DIRECTION_TTB, &x, &y); /* No VVAR; 'C' in composite Ccedilla determines metrics */
226 g_assert_cmpint (x, ==, 0);
227 g_assert_cmpint (y, ==, -991);
229 hb_font_get_glyph_origin_for_direction(font, 2, HB_DIRECTION_TTB, &x, &y);
231 g_assert_cmpint (x, ==, 292);
232 g_assert_cmpint (y, ==, 1013);
234 hb_font_destroy (font);
238 test_advance_tt_var_gvar_infer (void)
240 hb_face_t *face = hb_test_open_font_file ("fonts/TestGVAREight.ttf");
241 hb_font_t *font = hb_font_create (face);
242 hb_ot_font_set_funcs (font);
243 hb_face_destroy (face);
245 int coords[6] = {100};
246 hb_font_set_var_coords_normalized (font, coords, 6);
248 hb_glyph_extents_t extents = {0};
249 g_assert (hb_font_get_glyph_extents (font, 4, &extents));
251 hb_font_destroy (font);
255 main (int argc, char **argv)
257 hb_test_init (&argc, &argv);
259 hb_test_add (test_extents_tt_var);
260 hb_test_add (test_advance_tt_var_nohvar);
261 hb_test_add (test_advance_tt_var_hvarvvar);
262 hb_test_add (test_advance_tt_var_anchor);
263 hb_test_add (test_extents_tt_var_comp);
264 hb_test_add (test_advance_tt_var_comp_v);
265 hb_test_add (test_advance_tt_var_gvar_infer);
267 return hb_test_run ();