1*2d1272b8SAndroid Build Coastguard Worker /*
2*2d1272b8SAndroid Build Coastguard Worker * Copyright © 2011 Google, Inc.
3*2d1272b8SAndroid Build Coastguard Worker *
4*2d1272b8SAndroid Build Coastguard Worker * This is part of HarfBuzz, a text shaping library.
5*2d1272b8SAndroid Build Coastguard Worker *
6*2d1272b8SAndroid Build Coastguard Worker * Permission is hereby granted, without written agreement and without
7*2d1272b8SAndroid Build Coastguard Worker * license or royalty fees, to use, copy, modify, and distribute this
8*2d1272b8SAndroid Build Coastguard Worker * software and its documentation for any purpose, provided that the
9*2d1272b8SAndroid Build Coastguard Worker * above copyright notice and the following two paragraphs appear in
10*2d1272b8SAndroid Build Coastguard Worker * all copies of this software.
11*2d1272b8SAndroid Build Coastguard Worker *
12*2d1272b8SAndroid Build Coastguard Worker * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13*2d1272b8SAndroid Build Coastguard Worker * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14*2d1272b8SAndroid Build Coastguard Worker * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15*2d1272b8SAndroid Build Coastguard Worker * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16*2d1272b8SAndroid Build Coastguard Worker * DAMAGE.
17*2d1272b8SAndroid Build Coastguard Worker *
18*2d1272b8SAndroid Build Coastguard Worker * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19*2d1272b8SAndroid Build Coastguard Worker * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20*2d1272b8SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21*2d1272b8SAndroid Build Coastguard Worker * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22*2d1272b8SAndroid Build Coastguard Worker * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23*2d1272b8SAndroid Build Coastguard Worker *
24*2d1272b8SAndroid Build Coastguard Worker * Google Author(s): Behdad Esfahbod
25*2d1272b8SAndroid Build Coastguard Worker */
26*2d1272b8SAndroid Build Coastguard Worker
27*2d1272b8SAndroid Build Coastguard Worker #ifndef TEST_OT_FACE_NO_MAIN
28*2d1272b8SAndroid Build Coastguard Worker #include "hb-test.h"
29*2d1272b8SAndroid Build Coastguard Worker #endif
30*2d1272b8SAndroid Build Coastguard Worker #include <hb-aat.h>
31*2d1272b8SAndroid Build Coastguard Worker #include <hb-ot.h>
32*2d1272b8SAndroid Build Coastguard Worker
33*2d1272b8SAndroid Build Coastguard Worker /* Unit tests for hb-ot-*.h */
34*2d1272b8SAndroid Build Coastguard Worker
35*2d1272b8SAndroid Build Coastguard Worker /* Return some dummy result so that compiler won't just optimize things */
36*2d1272b8SAndroid Build Coastguard Worker static long long
test_font(hb_font_t * font,hb_codepoint_t cp)37*2d1272b8SAndroid Build Coastguard Worker test_font (hb_font_t *font, hb_codepoint_t cp)
38*2d1272b8SAndroid Build Coastguard Worker {
39*2d1272b8SAndroid Build Coastguard Worker long long result = 0;
40*2d1272b8SAndroid Build Coastguard Worker
41*2d1272b8SAndroid Build Coastguard Worker hb_face_t *face = hb_font_get_face (font);
42*2d1272b8SAndroid Build Coastguard Worker hb_set_t *set;
43*2d1272b8SAndroid Build Coastguard Worker hb_codepoint_t g = 0;
44*2d1272b8SAndroid Build Coastguard Worker hb_position_t x = 0, y = 0;
45*2d1272b8SAndroid Build Coastguard Worker char buf[5] = {0};
46*2d1272b8SAndroid Build Coastguard Worker unsigned int len = 0;
47*2d1272b8SAndroid Build Coastguard Worker hb_glyph_extents_t extents = {0, 0, 0, 0};
48*2d1272b8SAndroid Build Coastguard Worker hb_ot_font_set_funcs (font);
49*2d1272b8SAndroid Build Coastguard Worker
50*2d1272b8SAndroid Build Coastguard Worker set = hb_set_create ();
51*2d1272b8SAndroid Build Coastguard Worker hb_face_collect_unicodes (face, set);
52*2d1272b8SAndroid Build Coastguard Worker hb_face_collect_variation_selectors (face, set);
53*2d1272b8SAndroid Build Coastguard Worker hb_face_collect_variation_unicodes (face, cp, set);
54*2d1272b8SAndroid Build Coastguard Worker
55*2d1272b8SAndroid Build Coastguard Worker hb_font_get_nominal_glyph (font, cp, &g);
56*2d1272b8SAndroid Build Coastguard Worker hb_font_get_variation_glyph (font, cp, cp, &g);
57*2d1272b8SAndroid Build Coastguard Worker hb_font_get_glyph_h_advance (font, cp);
58*2d1272b8SAndroid Build Coastguard Worker hb_font_get_glyph_v_advance (font, cp);
59*2d1272b8SAndroid Build Coastguard Worker hb_font_get_glyph_h_origin (font, cp, &x, &y);
60*2d1272b8SAndroid Build Coastguard Worker hb_font_get_glyph_v_origin (font, cp, &x, &y);
61*2d1272b8SAndroid Build Coastguard Worker hb_font_get_glyph_extents (font, cp, &extents);
62*2d1272b8SAndroid Build Coastguard Worker hb_font_get_glyph_contour_point (font, cp, 0, &x, &y);
63*2d1272b8SAndroid Build Coastguard Worker hb_font_get_glyph_name (font, cp, buf, sizeof (buf));
64*2d1272b8SAndroid Build Coastguard Worker hb_font_get_glyph_from_name (font, buf, strlen (buf), &g);
65*2d1272b8SAndroid Build Coastguard Worker
66*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_has_palettes (face);
67*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_palette_get_count (face);
68*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_palette_get_name_id (face, cp);
69*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_palette_color_get_name_id (face, cp);
70*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_palette_get_flags (face, cp);
71*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_palette_get_colors (face, cp, 0, NULL, NULL);
72*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_has_layers (face);
73*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_glyph_get_layers (face, cp, 0, NULL, NULL);
74*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_has_svg (face);
75*2d1272b8SAndroid Build Coastguard Worker hb_blob_destroy (hb_ot_color_glyph_reference_svg (face, cp));
76*2d1272b8SAndroid Build Coastguard Worker hb_ot_color_has_png (face);
77*2d1272b8SAndroid Build Coastguard Worker hb_blob_destroy (hb_ot_color_glyph_reference_png (font, cp));
78*2d1272b8SAndroid Build Coastguard Worker
79*2d1272b8SAndroid Build Coastguard Worker #ifndef HB_NO_AAT
80*2d1272b8SAndroid Build Coastguard Worker {
81*2d1272b8SAndroid Build Coastguard Worker hb_aat_layout_feature_type_t feature = HB_AAT_LAYOUT_FEATURE_TYPE_ALL_TYPOGRAPHIC;
82*2d1272b8SAndroid Build Coastguard Worker unsigned count = 1;
83*2d1272b8SAndroid Build Coastguard Worker hb_aat_layout_get_feature_types (face, 0, &count, &feature);
84*2d1272b8SAndroid Build Coastguard Worker hb_aat_layout_feature_type_get_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE);
85*2d1272b8SAndroid Build Coastguard Worker 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};
86*2d1272b8SAndroid Build Coastguard Worker unsigned default_index;
87*2d1272b8SAndroid Build Coastguard Worker count = 1;
88*2d1272b8SAndroid Build Coastguard Worker hb_aat_layout_feature_type_get_selector_infos (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, 0, &count, &setting, &default_index);
89*2d1272b8SAndroid Build Coastguard Worker result += count + feature + setting.disable + setting.disable + setting.name_id + setting.reserved + default_index;
90*2d1272b8SAndroid Build Coastguard Worker }
91*2d1272b8SAndroid Build Coastguard Worker #endif
92*2d1272b8SAndroid Build Coastguard Worker
93*2d1272b8SAndroid Build Coastguard Worker hb_set_t *lookup_indexes = hb_set_create ();
94*2d1272b8SAndroid Build Coastguard Worker hb_set_add (lookup_indexes, 0);
95*2d1272b8SAndroid Build Coastguard Worker
96*2d1272b8SAndroid Build Coastguard Worker hb_map_t *lookup_mapping = hb_map_create ();
97*2d1272b8SAndroid Build Coastguard Worker hb_map_set (lookup_mapping, 0, 0);
98*2d1272b8SAndroid Build Coastguard Worker hb_set_t *feature_indices = hb_set_create ();
99*2d1272b8SAndroid Build Coastguard Worker hb_set_destroy (lookup_indexes);
100*2d1272b8SAndroid Build Coastguard Worker hb_set_destroy (feature_indices);
101*2d1272b8SAndroid Build Coastguard Worker hb_map_destroy (lookup_mapping);
102*2d1272b8SAndroid Build Coastguard Worker
103*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_TAG_HANGING, HB_DIRECTION_RTL, HB_SCRIPT_HANGUL, HB_TAG_NONE, NULL);
104*2d1272b8SAndroid Build Coastguard Worker
105*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_has_glyph_classes (face);
106*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_has_substitution (face);
107*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_has_positioning (face);
108*2d1272b8SAndroid Build Coastguard Worker
109*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR, cp, 0, NULL, NULL);
110*2d1272b8SAndroid Build Coastguard Worker
111*2d1272b8SAndroid Build Coastguard Worker {
112*2d1272b8SAndroid Build Coastguard Worker unsigned temp = 0, temp2 = 0;
113*2d1272b8SAndroid Build Coastguard Worker hb_ot_name_id_t name = HB_OT_NAME_ID_FULL_NAME;
114*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_size_params (face, &temp, &temp, &name, &temp, &temp);
115*2d1272b8SAndroid Build Coastguard Worker hb_tag_t cv01 = HB_TAG ('c','v','0','1');
116*2d1272b8SAndroid Build Coastguard Worker unsigned feature_index = 0;
117*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_language_find_feature (face, HB_OT_TAG_GSUB, 0,
118*2d1272b8SAndroid Build Coastguard Worker HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,
119*2d1272b8SAndroid Build Coastguard Worker cv01, &feature_index);
120*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_feature_get_name_ids (face, HB_OT_TAG_GSUB, feature_index,
121*2d1272b8SAndroid Build Coastguard Worker &name, &name, &name, &temp, &name);
122*2d1272b8SAndroid Build Coastguard Worker temp = 1;
123*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index, 0, &temp, &g);
124*2d1272b8SAndroid Build Coastguard Worker temp = 1;
125*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_language_get_feature_indexes (face, HB_OT_TAG_GSUB, 0, 0, 0, &temp, &temp2);
126*2d1272b8SAndroid Build Coastguard Worker
127*2d1272b8SAndroid Build Coastguard Worker result += temp + name + feature_index + temp2;
128*2d1272b8SAndroid Build Coastguard Worker }
129*2d1272b8SAndroid Build Coastguard Worker
130*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_has_data (face);
131*2d1272b8SAndroid Build Coastguard Worker for (unsigned constant = HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN; constant <= HB_OT_MATH_CONSTANT_RADICAL_DEGREE_BOTTOM_RAISE_PERCENT; constant++) {
132*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_constant (font, (hb_ot_math_constant_t)constant);
133*2d1272b8SAndroid Build Coastguard Worker }
134*2d1272b8SAndroid Build Coastguard Worker
135*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_italics_correction (font, cp);
136*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_top_accent_attachment (font, cp);
137*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_is_glyph_extended_shape (face, cp);
138*2d1272b8SAndroid Build Coastguard Worker
139*2d1272b8SAndroid Build Coastguard Worker {
140*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_kerning (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0);
141*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_kernings (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, NULL, NULL);
142*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_kern_entry_t entries[5];
143*2d1272b8SAndroid Build Coastguard Worker unsigned count = sizeof (entries) / sizeof (entries[0]);
144*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_kernings (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, &count, entries);
145*2d1272b8SAndroid Build Coastguard Worker }
146*2d1272b8SAndroid Build Coastguard Worker
147*2d1272b8SAndroid Build Coastguard Worker {
148*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_LTR, 0, NULL, NULL);
149*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_TTB, 0, NULL, NULL);
150*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_glyph_variant_t entries[5];
151*2d1272b8SAndroid Build Coastguard Worker unsigned count = sizeof (entries) / sizeof (entries[0]);
152*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_LTR, 0, &count, entries);
153*2d1272b8SAndroid Build Coastguard Worker }
154*2d1272b8SAndroid Build Coastguard Worker
155*2d1272b8SAndroid Build Coastguard Worker {
156*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_min_connector_overlap (font, HB_DIRECTION_LTR);
157*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_LTR, 0, NULL, NULL, NULL);
158*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_TTB, 0, NULL, NULL, NULL);
159*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_glyph_part_t entries[5];
160*2d1272b8SAndroid Build Coastguard Worker unsigned count = sizeof (entries) / sizeof (entries[0]);
161*2d1272b8SAndroid Build Coastguard Worker hb_position_t corr;
162*2d1272b8SAndroid Build Coastguard Worker hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_LTR, 0, &count, entries, &corr);
163*2d1272b8SAndroid Build Coastguard Worker }
164*2d1272b8SAndroid Build Coastguard Worker
165*2d1272b8SAndroid Build Coastguard Worker hb_ot_meta_get_entry_tags (face, 0, NULL, NULL);
166*2d1272b8SAndroid Build Coastguard Worker hb_blob_destroy (hb_ot_meta_reference_entry (face, HB_OT_META_TAG_DESIGN_LANGUAGES));
167*2d1272b8SAndroid Build Coastguard Worker
168*2d1272b8SAndroid Build Coastguard Worker hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, NULL);
169*2d1272b8SAndroid Build Coastguard Worker hb_ot_metrics_get_variation (font, HB_OT_METRICS_TAG_UNDERLINE_OFFSET);
170*2d1272b8SAndroid Build Coastguard Worker hb_ot_metrics_get_x_variation (font, HB_OT_METRICS_TAG_STRIKEOUT_OFFSET);
171*2d1272b8SAndroid Build Coastguard Worker hb_ot_metrics_get_y_variation (font, HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_OFFSET);
172*2d1272b8SAndroid Build Coastguard Worker
173*2d1272b8SAndroid Build Coastguard Worker len = sizeof (buf);
174*2d1272b8SAndroid Build Coastguard Worker hb_ot_name_list_names (face, NULL);
175*2d1272b8SAndroid Build Coastguard Worker hb_ot_name_get_utf8 (face, cp, NULL, &len, buf);
176*2d1272b8SAndroid Build Coastguard Worker hb_ot_name_get_utf16 (face, cp, NULL, NULL, NULL);
177*2d1272b8SAndroid Build Coastguard Worker hb_ot_name_get_utf32 (face, cp, NULL, NULL, NULL);
178*2d1272b8SAndroid Build Coastguard Worker
179*2d1272b8SAndroid Build Coastguard Worker #if 0
180*2d1272b8SAndroid Build Coastguard Worker hb_style_get_value (font, HB_STYLE_TAG_ITALIC);
181*2d1272b8SAndroid Build Coastguard Worker hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE);
182*2d1272b8SAndroid Build Coastguard Worker hb_style_get_value (font, HB_STYLE_TAG_SLANT);
183*2d1272b8SAndroid Build Coastguard Worker hb_style_get_value (font, HB_STYLE_TAG_WIDTH);
184*2d1272b8SAndroid Build Coastguard Worker hb_style_get_value (font, HB_STYLE_TAG_WEIGHT);
185*2d1272b8SAndroid Build Coastguard Worker #endif
186*2d1272b8SAndroid Build Coastguard Worker
187*2d1272b8SAndroid Build Coastguard Worker hb_ot_var_get_axis_count (face);
188*2d1272b8SAndroid Build Coastguard Worker hb_ot_var_get_axis_infos (face, 0, NULL, NULL);
189*2d1272b8SAndroid Build Coastguard Worker hb_ot_var_normalize_variations (face, NULL, 0, NULL, 0);
190*2d1272b8SAndroid Build Coastguard Worker hb_ot_var_normalize_coords (face, 0, NULL, NULL);
191*2d1272b8SAndroid Build Coastguard Worker
192*2d1272b8SAndroid Build Coastguard Worker hb_draw_funcs_t *funcs = hb_draw_funcs_create ();
193*2d1272b8SAndroid Build Coastguard Worker hb_font_draw_glyph (font, cp, funcs, NULL);
194*2d1272b8SAndroid Build Coastguard Worker hb_draw_funcs_destroy (funcs);
195*2d1272b8SAndroid Build Coastguard Worker
196*2d1272b8SAndroid Build Coastguard Worker hb_set_destroy (set);
197*2d1272b8SAndroid Build Coastguard Worker
198*2d1272b8SAndroid Build Coastguard Worker return result + g + x + y + buf[0] + buf[1] + buf[2] + buf[3] + buf[4] + len +
199*2d1272b8SAndroid Build Coastguard Worker extents.height + extents.width + extents.x_bearing + extents.y_bearing;
200*2d1272b8SAndroid Build Coastguard Worker }
201*2d1272b8SAndroid Build Coastguard Worker
202*2d1272b8SAndroid Build Coastguard Worker #ifndef TEST_OT_FACE_NO_MAIN
203*2d1272b8SAndroid Build Coastguard Worker static void
test_ot_face_empty(void)204*2d1272b8SAndroid Build Coastguard Worker test_ot_face_empty (void)
205*2d1272b8SAndroid Build Coastguard Worker {
206*2d1272b8SAndroid Build Coastguard Worker test_font (hb_font_get_empty (), 0);
207*2d1272b8SAndroid Build Coastguard Worker }
208*2d1272b8SAndroid Build Coastguard Worker
209*2d1272b8SAndroid Build Coastguard Worker static void
test_ot_var_axis_on_zero_named_instance(void)210*2d1272b8SAndroid Build Coastguard Worker test_ot_var_axis_on_zero_named_instance (void)
211*2d1272b8SAndroid Build Coastguard Worker {
212*2d1272b8SAndroid Build Coastguard Worker hb_face_t *face = hb_test_open_font_file ("fonts/Zycon.ttf");
213*2d1272b8SAndroid Build Coastguard Worker g_assert (hb_ot_var_get_axis_count (face));
214*2d1272b8SAndroid Build Coastguard Worker hb_face_destroy (face);
215*2d1272b8SAndroid Build Coastguard Worker }
216*2d1272b8SAndroid Build Coastguard Worker
217*2d1272b8SAndroid Build Coastguard Worker int
main(int argc,char ** argv)218*2d1272b8SAndroid Build Coastguard Worker main (int argc, char **argv)
219*2d1272b8SAndroid Build Coastguard Worker {
220*2d1272b8SAndroid Build Coastguard Worker hb_test_init (&argc, &argv);
221*2d1272b8SAndroid Build Coastguard Worker
222*2d1272b8SAndroid Build Coastguard Worker hb_test_add (test_ot_face_empty);
223*2d1272b8SAndroid Build Coastguard Worker hb_test_add (test_ot_var_axis_on_zero_named_instance);
224*2d1272b8SAndroid Build Coastguard Worker
225*2d1272b8SAndroid Build Coastguard Worker return hb_test_run();
226*2d1272b8SAndroid Build Coastguard Worker }
227*2d1272b8SAndroid Build Coastguard Worker #endif
228