Coverage Report

Created: 2025-07-11 06:06

/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
47.0k
{
39
47.0k
  long long result = 0;
40
41
47.0k
  hb_face_t *face = hb_font_get_face (font);
42
47.0k
  hb_set_t *set;
43
47.0k
  hb_codepoint_t g = 0;
44
47.0k
  hb_position_t x = 0, y = 0;
45
47.0k
  char buf[5] = {0};
46
47.0k
  unsigned int len = 0;
47
47.0k
  hb_glyph_extents_t extents = {0, 0, 0, 0};
48
49
47.0k
  set = hb_set_create ();
50
47.0k
  hb_face_collect_unicodes (face, set);
51
47.0k
  hb_face_collect_variation_selectors (face, set);
52
47.0k
  hb_face_collect_variation_unicodes (face, cp, set);
53
54
47.0k
  hb_font_get_nominal_glyph (font, cp, &g);
55
47.0k
  hb_font_get_variation_glyph (font, cp, cp, &g);
56
47.0k
  hb_font_get_glyph_h_advance (font, cp);
57
47.0k
  hb_font_get_glyph_v_advance (font, cp);
58
47.0k
  hb_font_get_glyph_h_origin (font, cp, &x, &y);
59
47.0k
  hb_font_get_glyph_v_origin (font, cp, &x, &y);
60
47.0k
  hb_font_get_glyph_extents (font, cp, &extents);
61
47.0k
  hb_font_get_glyph_contour_point (font, cp, 0, &x, &y);
62
47.0k
  hb_font_get_glyph_name (font, cp, buf, sizeof (buf));
63
47.0k
  hb_font_get_glyph_from_name (font, buf, strlen (buf), &g);
64
65
47.0k
  hb_ot_color_has_palettes (face);
66
47.0k
  hb_ot_color_palette_get_count (face);
67
47.0k
  hb_ot_color_palette_get_name_id (face, cp);
68
47.0k
  hb_ot_color_palette_color_get_name_id (face, cp);
69
47.0k
  hb_ot_color_palette_get_flags (face, cp);
70
47.0k
  hb_ot_color_palette_get_colors (face, cp, 0, NULL, NULL);
71
47.0k
  hb_ot_color_has_layers (face);
72
47.0k
  hb_ot_color_glyph_get_layers (face, cp, 0, NULL, NULL);
73
47.0k
  hb_ot_color_has_svg (face);
74
47.0k
  hb_blob_destroy (hb_ot_color_glyph_reference_svg (face, cp));
75
47.0k
  hb_ot_color_has_png (face);
76
47.0k
  hb_blob_destroy (hb_ot_color_glyph_reference_png (font, cp));
77
78
47.0k
#ifndef HB_NO_AAT
79
47.0k
  {
80
47.0k
    hb_aat_layout_feature_type_t feature = HB_AAT_LAYOUT_FEATURE_TYPE_ALL_TYPOGRAPHIC;
81
47.0k
    unsigned count = 1;
82
47.0k
    hb_aat_layout_get_feature_types (face, 0, &count, &feature);
83
47.0k
    hb_aat_layout_feature_type_get_name_id (face, HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE);
84
47.0k
    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};
85
47.0k
    unsigned default_index;
86
47.0k
    count = 1;
87
47.0k
    hb_aat_layout_feature_type_get_selector_infos (face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, 0, &count, &setting, &default_index);
88
47.0k
    result += count + feature + setting.disable + setting.disable + setting.name_id + setting.reserved + default_index;
89
47.0k
  }
90
47.0k
#endif
91
92
47.0k
  hb_set_t *lookup_indexes = hb_set_create ();
93
47.0k
  hb_set_add (lookup_indexes, 0);
94
95
47.0k
  hb_map_t *lookup_mapping = hb_map_create ();
96
47.0k
  hb_map_set (lookup_mapping, 0, 0);
97
47.0k
  hb_set_t *feature_indices = hb_set_create ();
98
47.0k
  hb_set_destroy (lookup_indexes);
99
47.0k
  hb_set_destroy (feature_indices);
100
47.0k
  hb_map_destroy (lookup_mapping);
101
102
47.0k
  hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_TAG_HANGING, HB_DIRECTION_RTL, HB_SCRIPT_HANGUL, HB_TAG_NONE, NULL);
103
104
47.0k
  hb_ot_layout_has_glyph_classes (face);
105
47.0k
  hb_ot_layout_has_substitution (face);
106
47.0k
  hb_ot_layout_has_positioning (face);
107
108
47.0k
  hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR, cp, 0, NULL, NULL);
109
110
47.0k
  {
111
47.0k
    unsigned temp = 0, temp2 = 0;
112
47.0k
    hb_ot_name_id_t name = HB_OT_NAME_ID_FULL_NAME;
113
47.0k
    hb_ot_layout_get_size_params (face, &temp, &temp, &name, &temp, &temp);
114
47.0k
    hb_tag_t cv01 = HB_TAG ('c','v','0','1');
115
47.0k
    unsigned feature_index = 0;
116
47.0k
    hb_ot_layout_language_find_feature (face, HB_OT_TAG_GSUB, 0,
117
47.0k
          HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,
118
47.0k
          cv01, &feature_index);
119
47.0k
    hb_ot_layout_feature_get_name_ids (face, HB_OT_TAG_GSUB, feature_index,
120
47.0k
               &name, &name, &name, &temp, &name);
121
47.0k
    temp = 1;
122
47.0k
    hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index, 0, &temp, &g);
123
47.0k
    temp = 1;
124
47.0k
    hb_ot_layout_language_get_feature_indexes (face, HB_OT_TAG_GSUB, 0, 0, 0, &temp, &temp2);
125
126
47.0k
    result += temp + name + feature_index + temp2;
127
47.0k
  }
128
129
47.0k
  hb_ot_math_has_data (face);
130
2.68M
  for (unsigned constant = HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN; constant <= HB_OT_MATH_CONSTANT_RADICAL_DEGREE_BOTTOM_RAISE_PERCENT; constant++) {
131
2.63M
    hb_ot_math_get_constant (font, (hb_ot_math_constant_t)constant);
132
2.63M
  }
133
134
47.0k
  hb_ot_math_get_glyph_italics_correction (font, cp);
135
47.0k
  hb_ot_math_get_glyph_top_accent_attachment (font, cp);
136
47.0k
  hb_ot_math_is_glyph_extended_shape (face, cp);
137
138
47.0k
  {
139
47.0k
    hb_ot_math_get_glyph_kerning (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0);
140
47.0k
    hb_ot_math_get_glyph_kernings (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, NULL, NULL);
141
47.0k
    hb_ot_math_kern_entry_t entries[5];
142
47.0k
    unsigned count = sizeof (entries) / sizeof (entries[0]);
143
47.0k
    hb_ot_math_get_glyph_kernings (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, &count, entries);
144
47.0k
  }
145
146
47.0k
  {
147
47.0k
    hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_LTR, 0, NULL, NULL);
148
47.0k
    hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_TTB, 0, NULL, NULL);
149
47.0k
    hb_ot_math_glyph_variant_t entries[5];
150
47.0k
    unsigned count = sizeof (entries) / sizeof (entries[0]);
151
47.0k
    hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_LTR, 0, &count, entries);
152
47.0k
  }
153
154
47.0k
  {
155
47.0k
    hb_ot_math_get_min_connector_overlap (font, HB_DIRECTION_LTR);
156
47.0k
    hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_LTR, 0, NULL, NULL, NULL);
157
47.0k
    hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_TTB, 0, NULL, NULL, NULL);
158
47.0k
    hb_ot_math_glyph_part_t entries[5];
159
47.0k
    unsigned count = sizeof (entries) / sizeof (entries[0]);
160
47.0k
    hb_position_t corr;
161
47.0k
    hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_LTR, 0, &count, entries, &corr);
162
47.0k
  }
163
164
47.0k
  hb_ot_meta_get_entry_tags (face, 0, NULL, NULL);
165
47.0k
  hb_blob_destroy (hb_ot_meta_reference_entry (face, HB_OT_META_TAG_DESIGN_LANGUAGES));
166
167
47.0k
  hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, NULL);
168
47.0k
  hb_ot_metrics_get_variation (font, HB_OT_METRICS_TAG_UNDERLINE_OFFSET);
169
47.0k
  hb_ot_metrics_get_x_variation (font, HB_OT_METRICS_TAG_STRIKEOUT_OFFSET);
170
47.0k
  hb_ot_metrics_get_y_variation (font, HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_OFFSET);
171
172
47.0k
  len = sizeof (buf);
173
47.0k
  hb_ot_name_list_names (face, NULL);
174
47.0k
  hb_ot_name_get_utf8 (face, cp, NULL, &len, buf);
175
47.0k
  hb_ot_name_get_utf16 (face, cp, NULL, NULL, NULL);
176
47.0k
  hb_ot_name_get_utf32 (face, cp, NULL, NULL, NULL);
177
178
#if 0
179
  hb_style_get_value (font, HB_STYLE_TAG_ITALIC);
180
  hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE);
181
  hb_style_get_value (font, HB_STYLE_TAG_SLANT);
182
  hb_style_get_value (font, HB_STYLE_TAG_WIDTH);
183
  hb_style_get_value (font, HB_STYLE_TAG_WEIGHT);
184
#endif
185
186
47.0k
  hb_ot_var_get_axis_count (face);
187
47.0k
  hb_ot_var_get_axis_infos (face, 0, NULL, NULL);
188
47.0k
  hb_ot_var_normalize_variations (face, NULL, 0, NULL, 0);
189
47.0k
  hb_ot_var_normalize_coords (face, 0, NULL, NULL);
190
191
47.0k
  hb_draw_funcs_t *funcs = hb_draw_funcs_create ();
192
47.0k
  hb_font_draw_glyph (font, cp, funcs, NULL);
193
47.0k
  hb_draw_funcs_destroy (funcs);
194
195
47.0k
  hb_set_destroy (set);
196
197
47.0k
  return result + g + x + y + buf[0] + buf[1] + buf[2] + buf[3] + buf[4] + len +
198
47.0k
   extents.height + extents.width + extents.x_bearing + extents.y_bearing;
199
47.0k
}
200
201
#ifndef TEST_OT_FACE_NO_MAIN
202
static void
203
test_ot_face_empty (void)
204
{
205
  test_font (hb_font_get_empty (), 0);
206
}
207
208
static void
209
test_ot_var_axis_on_zero_named_instance (void)
210
{
211
  hb_face_t *face = hb_test_open_font_file ("fonts/Zycon.ttf");
212
  g_assert_true (hb_ot_var_get_axis_count (face));
213
  hb_face_destroy (face);
214
}
215
216
int
217
main (int argc, char **argv)
218
{
219
  hb_test_init (&argc, &argv);
220
221
  hb_test_add (test_ot_face_empty);
222
  hb_test_add (test_ot_var_axis_on_zero_named_instance);
223
224
  return hb_test_run();
225
}
226
#endif