Coverage Report

Created: 2023-09-24 15:58

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