/src/harfbuzz/test/api/test-ot-face.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2011 Google, Inc. |
3 | | * |
4 | | * This is part of HarfBuzz, a text shaping library. |
5 | | * |
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. |
11 | | * |
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 |
16 | | * DAMAGE. |
17 | | * |
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. |
23 | | * |
24 | | * Google Author(s): Behdad Esfahbod |
25 | | */ |
26 | | |
27 | | #ifndef TEST_OT_FACE_NO_MAIN |
28 | | #include "hb-test.h" |
29 | | #endif |
30 | | #include <hb-aat.h> |
31 | | #include <hb-ot.h> |
32 | | |
33 | | /* Unit tests for hb-ot-*.h */ |
34 | | |
35 | | /* Return some dummy result so that compiler won't just optimize things */ |
36 | | static long long |
37 | | test_font (hb_font_t *font, hb_codepoint_t cp) |
38 | 48.9k | { |
39 | 48.9k | long long result = 0; |
40 | | |
41 | 48.9k | hb_face_t *face = hb_font_get_face (font); |
42 | 48.9k | hb_set_t *set; |
43 | 48.9k | hb_codepoint_t g = 0; |
44 | 48.9k | hb_position_t x = 0, y = 0; |
45 | 48.9k | char buf[5] = {0}; |
46 | 48.9k | unsigned int len = 0; |
47 | 48.9k | hb_glyph_extents_t extents = {0, 0, 0, 0}; |
48 | | |
49 | 48.9k | set = hb_set_create (); |
50 | 48.9k | hb_face_collect_unicodes (face, set); |
51 | 48.9k | hb_face_collect_variation_selectors (face, set); |
52 | 48.9k | hb_face_collect_variation_unicodes (face, cp, set); |
53 | | |
54 | 48.9k | hb_font_get_nominal_glyph (font, cp, &g); |
55 | 48.9k | hb_font_get_variation_glyph (font, cp, cp, &g); |
56 | 48.9k | hb_font_get_glyph_h_advance (font, cp); |
57 | 48.9k | hb_font_get_glyph_v_advance (font, cp); |
58 | 48.9k | hb_font_get_glyph_h_origin (font, cp, &x, &y); |
59 | 48.9k | hb_font_get_glyph_v_origin (font, cp, &x, &y); |
60 | 48.9k | hb_font_get_glyph_extents (font, cp, &extents); |
61 | 48.9k | hb_font_get_glyph_contour_point (font, cp, 0, &x, &y); |
62 | 48.9k | hb_font_get_glyph_name (font, cp, buf, sizeof (buf)); |
63 | 48.9k | hb_font_get_glyph_from_name (font, buf, strlen (buf), &g); |
64 | | |
65 | 48.9k | hb_ot_color_has_palettes (face); |
66 | 48.9k | hb_ot_color_palette_get_count (face); |
67 | 48.9k | hb_ot_color_palette_get_name_id (face, cp); |
68 | 48.9k | hb_ot_color_palette_color_get_name_id (face, cp); |
69 | 48.9k | hb_ot_color_palette_get_flags (face, cp); |
70 | 48.9k | hb_ot_color_palette_get_colors (face, cp, 0, NULL, NULL); |
71 | 48.9k | hb_ot_color_has_layers (face); |
72 | 48.9k | hb_ot_color_glyph_get_layers (face, cp, 0, NULL, NULL); |
73 | 48.9k | #ifndef HB_NO_SVG |
74 | 48.9k | hb_ot_color_has_svg (face); |
75 | 48.9k | hb_blob_destroy (hb_ot_color_glyph_reference_svg (face, cp)); |
76 | 48.9k | #endif |
77 | 48.9k | hb_ot_color_has_png (face); |
78 | 48.9k | hb_blob_destroy (hb_ot_color_glyph_reference_png (font, cp)); |
79 | | |
80 | 48.9k | #ifndef HB_NO_AAT |
81 | 48.9k | { |
82 | 48.9k | hb_aat_layout_feature_type_t feature = HB_AAT_LAYOUT_FEATURE_TYPE_ALL_TYPOGRAPHIC; |
83 | 48.9k | unsigned count = 1; |
84 | 48.9k | hb_aat_layout_get_feature_types (face, 0, &count, &feature); |
85 | 48.9k | hb_aat_layout_feature_type_get_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE); |
86 | 48.9k | hb_aat_layout_feature_selector_info_t setting = {0, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALL_TYPE_FEATURES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALL_TYPE_FEATURES_ON, 0}; |
87 | 48.9k | unsigned default_index; |
88 | 48.9k | count = 1; |
89 | 48.9k | hb_aat_layout_feature_type_get_selector_infos (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, 0, &count, &setting, &default_index); |
90 | 48.9k | result += count + feature + setting.disable + setting.disable + setting.name_id + setting.reserved + default_index; |
91 | 48.9k | } |
92 | 48.9k | #endif |
93 | | |
94 | 48.9k | hb_set_t *lookup_indexes = hb_set_create (); |
95 | 48.9k | hb_set_add (lookup_indexes, 0); |
96 | | |
97 | 48.9k | hb_map_t *lookup_mapping = hb_map_create (); |
98 | 48.9k | hb_map_set (lookup_mapping, 0, 0); |
99 | 48.9k | hb_set_t *feature_indices = hb_set_create (); |
100 | 48.9k | hb_set_destroy (lookup_indexes); |
101 | 48.9k | hb_set_destroy (feature_indices); |
102 | 48.9k | hb_map_destroy (lookup_mapping); |
103 | | |
104 | 48.9k | hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_TAG_HANGING, HB_DIRECTION_RTL, HB_SCRIPT_HANGUL, HB_TAG_NONE, NULL); |
105 | | |
106 | 48.9k | hb_ot_layout_has_glyph_classes (face); |
107 | 48.9k | hb_ot_layout_has_substitution (face); |
108 | 48.9k | hb_ot_layout_has_positioning (face); |
109 | | |
110 | 48.9k | hb_ot_layout_table_get_script_tags (face, HB_OT_TAG_GSUB, 0, NULL, NULL); |
111 | 48.9k | hb_ot_layout_table_get_feature_tags (face, HB_OT_TAG_GSUB, 0, 0, NULL); |
112 | 48.9k | hb_ot_layout_table_find_script (face, HB_OT_TAG_GSUB, HB_SCRIPT_HANGUL, NULL); |
113 | 48.9k | hb_ot_layout_script_get_language_tags (face, HB_OT_TAG_GSUB, 0, 0, NULL, NULL); |
114 | 48.9k | hb_ot_layout_language_get_feature_tags (face, HB_OT_TAG_GSUB, 0, 0, 0, NULL, NULL); |
115 | 48.9k | hb_ot_layout_get_extender_glyphs (face, HB_SCRIPT_ARABIC, 0, 0, NULL, NULL); |
116 | 48.9k | { |
117 | 48.9k | hb_codepoint_t buffer[1]; |
118 | 48.9k | unsigned glyphs_count = 1; |
119 | 48.9k | hb_ot_layout_get_extender_glyphs (face, HB_SCRIPT_ARABIC, HB_LANGUAGE_INVALID, 0, &glyphs_count, buffer); |
120 | 48.9k | if (glyphs_count) result += buffer[0]; |
121 | 48.9k | } |
122 | | |
123 | 48.9k | hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR, cp, 0, NULL, NULL); |
124 | | |
125 | 48.9k | { |
126 | 48.9k | unsigned temp = 0, temp2 = 0; |
127 | 48.9k | hb_ot_name_id_t name = HB_OT_NAME_ID_FULL_NAME; |
128 | 48.9k | hb_ot_layout_get_size_params (face, &temp, &temp, &name, &temp, &temp); |
129 | 48.9k | hb_tag_t cv01 = HB_TAG ('c','v','0','1'); |
130 | 48.9k | unsigned feature_index = 0; |
131 | 48.9k | hb_ot_layout_language_find_feature (face, HB_OT_TAG_GSUB, 0, |
132 | 48.9k | HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX, |
133 | 48.9k | cv01, &feature_index); |
134 | 48.9k | hb_ot_layout_feature_get_name_ids (face, HB_OT_TAG_GSUB, feature_index, |
135 | 48.9k | &name, &name, &name, &temp, &name); |
136 | 48.9k | temp = 1; |
137 | 48.9k | hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index, 0, &temp, &g); |
138 | 48.9k | temp = 1; |
139 | 48.9k | hb_ot_layout_language_get_feature_indexes (face, HB_OT_TAG_GSUB, 0, 0, 0, &temp, &temp2); |
140 | | |
141 | 48.9k | result += temp + name + feature_index + temp2; |
142 | 48.9k | } |
143 | | |
144 | 48.9k | hb_ot_math_has_data (face); |
145 | 2.79M | for (unsigned constant = HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN; constant <= HB_OT_MATH_CONSTANT_RADICAL_DEGREE_BOTTOM_RAISE_PERCENT; constant++) { |
146 | 2.74M | hb_ot_math_get_constant (font, (hb_ot_math_constant_t)constant); |
147 | 2.74M | } |
148 | | |
149 | 48.9k | hb_ot_math_get_glyph_italics_correction (font, cp); |
150 | 48.9k | hb_ot_math_get_glyph_top_accent_attachment (font, cp); |
151 | 48.9k | hb_ot_math_is_glyph_extended_shape (face, cp); |
152 | | |
153 | 48.9k | { |
154 | 48.9k | hb_ot_math_get_glyph_kerning (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0); |
155 | 48.9k | hb_ot_math_get_glyph_kernings (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, NULL, NULL); |
156 | 48.9k | hb_ot_math_kern_entry_t entries[5]; |
157 | 48.9k | unsigned count = sizeof (entries) / sizeof (entries[0]); |
158 | 48.9k | hb_ot_math_get_glyph_kernings (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, &count, entries); |
159 | 48.9k | } |
160 | | |
161 | 48.9k | { |
162 | 48.9k | hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_LTR, 0, NULL, NULL); |
163 | 48.9k | hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_TTB, 0, NULL, NULL); |
164 | 48.9k | hb_ot_math_glyph_variant_t entries[5]; |
165 | 48.9k | unsigned count = sizeof (entries) / sizeof (entries[0]); |
166 | 48.9k | hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_LTR, 0, &count, entries); |
167 | 48.9k | } |
168 | | |
169 | 48.9k | { |
170 | 48.9k | hb_ot_math_get_min_connector_overlap (font, HB_DIRECTION_LTR); |
171 | 48.9k | hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_LTR, 0, NULL, NULL, NULL); |
172 | 48.9k | hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_TTB, 0, NULL, NULL, NULL); |
173 | 48.9k | hb_ot_math_glyph_part_t entries[5]; |
174 | 48.9k | unsigned count = sizeof (entries) / sizeof (entries[0]); |
175 | 48.9k | hb_position_t corr; |
176 | 48.9k | hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_LTR, 0, &count, entries, &corr); |
177 | 48.9k | } |
178 | | |
179 | 48.9k | hb_ot_meta_get_entry_tags (face, 0, NULL, NULL); |
180 | 48.9k | hb_blob_destroy (hb_ot_meta_reference_entry (face, HB_OT_META_TAG_DESIGN_LANGUAGES)); |
181 | | |
182 | 48.9k | hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, NULL); |
183 | 48.9k | hb_ot_metrics_get_variation (font, HB_OT_METRICS_TAG_UNDERLINE_OFFSET); |
184 | 48.9k | hb_ot_metrics_get_x_variation (font, HB_OT_METRICS_TAG_STRIKEOUT_OFFSET); |
185 | 48.9k | hb_ot_metrics_get_y_variation (font, HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_OFFSET); |
186 | | |
187 | 48.9k | len = sizeof (buf); |
188 | 48.9k | hb_ot_name_list_names (face, NULL); |
189 | 48.9k | hb_ot_name_get_utf8 (face, cp, NULL, &len, buf); |
190 | 48.9k | hb_ot_name_get_utf16 (face, cp, NULL, NULL, NULL); |
191 | 48.9k | hb_ot_name_get_utf32 (face, cp, NULL, NULL, NULL); |
192 | | |
193 | | #if 0 |
194 | | hb_style_get_value (font, HB_STYLE_TAG_ITALIC); |
195 | | hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE); |
196 | | hb_style_get_value (font, HB_STYLE_TAG_SLANT); |
197 | | hb_style_get_value (font, HB_STYLE_TAG_WIDTH); |
198 | | hb_style_get_value (font, HB_STYLE_TAG_WEIGHT); |
199 | | #endif |
200 | | |
201 | 48.9k | hb_ot_var_get_axis_count (face); |
202 | 48.9k | hb_ot_var_get_axis_infos (face, 0, NULL, NULL); |
203 | 48.9k | hb_ot_var_normalize_variations (face, NULL, 0, NULL, 0); |
204 | 48.9k | hb_ot_var_normalize_coords (face, 0, NULL, NULL); |
205 | | |
206 | 48.9k | hb_draw_funcs_t *funcs = hb_draw_funcs_create (); |
207 | 48.9k | hb_font_draw_glyph (font, cp, funcs, NULL); |
208 | 48.9k | hb_draw_funcs_destroy (funcs); |
209 | | |
210 | 48.9k | hb_set_destroy (set); |
211 | | |
212 | 48.9k | return result + g + x + y + buf[0] + buf[1] + buf[2] + buf[3] + buf[4] + len + |
213 | 48.9k | extents.height + extents.width + extents.x_bearing + extents.y_bearing; |
214 | 48.9k | } |
215 | | |
216 | | #ifndef TEST_OT_FACE_NO_MAIN |
217 | | static void |
218 | | test_ot_face_empty (void) |
219 | | { |
220 | | test_font (hb_font_get_empty (), 0); |
221 | | } |
222 | | |
223 | | static void |
224 | | test_ot_var_axis_on_zero_named_instance (void) |
225 | | { |
226 | | hb_face_t *face = hb_test_open_font_file ("fonts/Zycon.ttf"); |
227 | | g_assert_true (hb_ot_var_get_axis_count (face)); |
228 | | hb_face_destroy (face); |
229 | | } |
230 | | |
231 | | #ifndef HB_NO_VERTICAL |
232 | | static void |
233 | | test_ot_font_v_origin_extents_overflow (void) |
234 | | { |
235 | | /* A COLRv1 glyph with a clip box from y=-32768 to y=32767. At the |
236 | | * scale below, its height clamps to INT_MIN, exercising the overflow |
237 | | * guard without relying on bounds manufactured from an empty outline. */ |
238 | | static const char data[] = { |
239 | | 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, |
240 | | 0x43, 0x4f, 0x4c, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, |
241 | | 0x00, 0x00, 0x00, 0x46, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
242 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, |
243 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
244 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, |
245 | | 0x02, (char) 0xff, (char) 0xff, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
246 | | 0x00, 0x00, 0x00, 0x00, 0x0c, 0x01, 0x00, 0x00, (char) 0x80, 0x00, 0x00, 0x01, |
247 | | 0x7f, (char) 0xff |
248 | | }; |
249 | | hb_blob_t *blob = hb_blob_create (data, sizeof (data), HB_MEMORY_MODE_READONLY, |
250 | | NULL, NULL); |
251 | | hb_face_t *face = hb_face_create (blob, 0); |
252 | | hb_face_set_upem (face, 1); |
253 | | hb_font_t *font = hb_font_create (face); |
254 | | hb_position_t x, y; |
255 | | |
256 | | hb_font_set_scale (font, 65536, 65536); |
257 | | hb_glyph_extents_t extents; |
258 | | g_assert_true (hb_font_get_glyph_extents (font, 0, &extents)); |
259 | | g_assert_cmpint (extents.height, ==, G_MININT); |
260 | | g_assert_true (hb_font_get_glyph_v_origin (font, 0, &x, &y)); |
261 | | g_assert_cmpint (y, ==, 1073709056); |
262 | | |
263 | | hb_font_destroy (font); |
264 | | hb_face_destroy (face); |
265 | | hb_blob_destroy (blob); |
266 | | } |
267 | | |
268 | | static void |
269 | | test_ot_font_v_origin_cache_invalidated_by_scale (void) |
270 | | { |
271 | | hb_face_t *face = hb_test_open_font_file ("fonts/Mplus1p-Regular.660E.ttf"); |
272 | | hb_font_t *font = hb_font_create (face); |
273 | | hb_codepoint_t glyph; |
274 | | hb_position_t x, y1, y2; |
275 | | |
276 | | g_assert_true (hb_font_get_nominal_glyph (font, 0x660E, &glyph)); |
277 | | |
278 | | hb_font_set_scale (font, 1000, 1000); |
279 | | g_assert_true (hb_font_get_glyph_v_origin (font, glyph, &x, &y1)); |
280 | | |
281 | | hb_font_set_scale (font, 1000, 2000); |
282 | | g_assert_true (hb_font_get_glyph_v_origin (font, glyph, &x, &y2)); |
283 | | |
284 | | g_assert_cmpint (y2, ==, y1 * 2); |
285 | | |
286 | | hb_font_destroy (font); |
287 | | hb_face_destroy (face); |
288 | | } |
289 | | #endif |
290 | | |
291 | | int |
292 | | main (int argc, char **argv) |
293 | | { |
294 | | hb_test_init (&argc, &argv); |
295 | | |
296 | | hb_test_add (test_ot_face_empty); |
297 | | hb_test_add (test_ot_var_axis_on_zero_named_instance); |
298 | | #ifndef HB_NO_VERTICAL |
299 | | hb_test_add (test_ot_font_v_origin_extents_overflow); |
300 | | hb_test_add (test_ot_font_v_origin_cache_invalidated_by_scale); |
301 | | #endif |
302 | | |
303 | | return hb_test_run(); |
304 | | } |
305 | | #endif |