/src/harfbuzz/src/hb-ot-var-fvar-table.hh
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2017 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 HB_OT_VAR_FVAR_TABLE_HH |
28 | | #define HB_OT_VAR_FVAR_TABLE_HH |
29 | | |
30 | | #include "hb-open-type.hh" |
31 | | |
32 | | /* |
33 | | * fvar -- Font Variations |
34 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/fvar |
35 | | */ |
36 | | |
37 | | #define HB_OT_TAG_fvar HB_TAG('f','v','a','r') |
38 | | |
39 | | |
40 | | namespace OT { |
41 | | |
42 | | static bool axis_coord_pinned_or_within_axis_range (const hb_array_t<const F16DOT16> coords, |
43 | | unsigned axis_index, |
44 | | Triple axis_limit) |
45 | 16.0k | { |
46 | 16.0k | double axis_coord = static_cast<double>(coords[axis_index].to_float ()); |
47 | 16.0k | if (axis_limit.is_point ()) |
48 | 12.3k | { |
49 | 12.3k | if (axis_limit.minimum != axis_coord) |
50 | 11.1k | return false; |
51 | 12.3k | } |
52 | 3.68k | else |
53 | 3.68k | { |
54 | 3.68k | if (axis_coord < axis_limit.minimum || |
55 | 3.03k | axis_coord > axis_limit.maximum) |
56 | 2.39k | return false; |
57 | 3.68k | } |
58 | 2.46k | return true; |
59 | 16.0k | } Unexecuted instantiation: hb-font.cc:OT::axis_coord_pinned_or_within_axis_range(hb_array_t<OT::HBFixed<OT::NumType<true, int, 4u>, 16u> const>, unsigned int, Triple) Unexecuted instantiation: hb-ot-var.cc:OT::axis_coord_pinned_or_within_axis_range(hb_array_t<OT::HBFixed<OT::NumType<true, int, 4u>, 16u> const>, unsigned int, Triple) Unexecuted instantiation: hb-subset.cc:OT::axis_coord_pinned_or_within_axis_range(hb_array_t<OT::HBFixed<OT::NumType<true, int, 4u>, 16u> const>, unsigned int, Triple) hb-subset-plan.cc:OT::axis_coord_pinned_or_within_axis_range(hb_array_t<OT::HBFixed<OT::NumType<true, int, 4u>, 16u> const>, unsigned int, Triple) Line | Count | Source | 45 | 9.74k | { | 46 | 9.74k | double axis_coord = static_cast<double>(coords[axis_index].to_float ()); | 47 | 9.74k | if (axis_limit.is_point ()) | 48 | 7.02k | { | 49 | 7.02k | if (axis_limit.minimum != axis_coord) | 50 | 6.37k | return false; | 51 | 7.02k | } | 52 | 2.71k | else | 53 | 2.71k | { | 54 | 2.71k | if (axis_coord < axis_limit.minimum || | 55 | 2.22k | axis_coord > axis_limit.maximum) | 56 | 1.71k | return false; | 57 | 2.71k | } | 58 | 1.65k | return true; | 59 | 9.74k | } |
Unexecuted instantiation: hb-subset-plan-var.cc:OT::axis_coord_pinned_or_within_axis_range(hb_array_t<OT::HBFixed<OT::NumType<true, int, 4u>, 16u> const>, unsigned int, Triple) hb-subset-table-var.cc:OT::axis_coord_pinned_or_within_axis_range(hb_array_t<OT::HBFixed<OT::NumType<true, int, 4u>, 16u> const>, unsigned int, Triple) Line | Count | Source | 45 | 6.29k | { | 46 | 6.29k | double axis_coord = static_cast<double>(coords[axis_index].to_float ()); | 47 | 6.29k | if (axis_limit.is_point ()) | 48 | 5.33k | { | 49 | 5.33k | if (axis_limit.minimum != axis_coord) | 50 | 4.80k | return false; | 51 | 5.33k | } | 52 | 963 | else | 53 | 963 | { | 54 | 963 | if (axis_coord < axis_limit.minimum || | 55 | 807 | axis_coord > axis_limit.maximum) | 56 | 682 | return false; | 57 | 963 | } | 58 | 808 | return true; | 59 | 6.29k | } |
|
60 | | |
61 | | struct InstanceRecord |
62 | | { |
63 | | friend struct fvar; |
64 | | |
65 | | hb_array_t<const F16DOT16> get_coordinates (unsigned int axis_count) const |
66 | 19.6k | { return coordinatesZ.as_array (axis_count); } |
67 | | |
68 | | bool keep_instance (unsigned axis_count, |
69 | | const hb_map_t *axes_index_tag_map, |
70 | | const hb_hashmap_t<hb_tag_t, Triple> *axes_location) const |
71 | 42.7k | { |
72 | 42.7k | if (axes_location->is_empty ()) return true; |
73 | 8.67k | const hb_array_t<const F16DOT16> coords = get_coordinates (axis_count); |
74 | 16.7k | for (unsigned i = 0 ; i < axis_count; i++) |
75 | 16.1k | { |
76 | 16.1k | uint32_t *axis_tag; |
77 | 16.1k | if (!axes_index_tag_map->has (i, &axis_tag)) |
78 | 4 | return false; |
79 | 16.1k | if (!axes_location->has (*axis_tag)) |
80 | 6.43k | continue; |
81 | | |
82 | 9.74k | Triple axis_limit = axes_location->get (*axis_tag); |
83 | 9.74k | if (!axis_coord_pinned_or_within_axis_range (coords, i, axis_limit)) |
84 | 8.09k | return false; |
85 | 9.74k | } |
86 | 576 | return true; |
87 | 8.67k | } |
88 | | |
89 | | bool subset (hb_subset_context_t *c, |
90 | | unsigned axis_count, |
91 | | bool has_postscript_nameid) const |
92 | 5.86k | { |
93 | 5.86k | TRACE_SUBSET (this); |
94 | 5.86k | if (unlikely (!c->serializer->embed (subfamilyNameID))) return_trace (false); |
95 | 5.86k | if (unlikely (!c->serializer->embed (flags))) return_trace (false); |
96 | | |
97 | 5.86k | const hb_array_t<const F16DOT16> coords = get_coordinates (axis_count); |
98 | 5.86k | const hb_hashmap_t<hb_tag_t, Triple> *axes_location = &c->plan->user_axes_location; |
99 | 12.1k | for (unsigned i = 0 ; i < axis_count; i++) |
100 | 11.7k | { |
101 | 11.7k | uint32_t *axis_tag; |
102 | 11.7k | Triple *axis_limit; |
103 | | // only keep instances whose coordinates == pinned axis location |
104 | 11.7k | if (!c->plan->axes_old_index_tag_map.has (i, &axis_tag)) return_trace (false); |
105 | 11.7k | if (axes_location->has (*axis_tag, &axis_limit)) |
106 | 6.29k | { |
107 | 6.29k | if (!axis_coord_pinned_or_within_axis_range (coords, i, *axis_limit)) |
108 | 5.48k | return_trace (false); |
109 | | |
110 | | //skip pinned axis |
111 | 808 | if (axis_limit->is_point ()) |
112 | 527 | continue; |
113 | 808 | } |
114 | | |
115 | 5.72k | if (!c->serializer->embed (coords[i])) |
116 | 0 | return_trace (false); |
117 | 5.72k | } |
118 | | |
119 | 375 | if (has_postscript_nameid) |
120 | 147 | { |
121 | 147 | NameID name_id; |
122 | 147 | name_id = StructAfter<NameID> (coords); |
123 | 147 | if (!c->serializer->embed (name_id)) |
124 | 0 | return_trace (false); |
125 | 147 | } |
126 | | |
127 | 375 | return_trace (true); |
128 | 375 | } |
129 | | |
130 | | bool sanitize (hb_sanitize_context_t *c, unsigned int axis_count) const |
131 | 0 | { |
132 | 0 | TRACE_SANITIZE (this); |
133 | 0 | return_trace (c->check_struct (this) && |
134 | 0 | hb_barrier () && |
135 | 0 | c->check_array (coordinatesZ.arrayZ, axis_count)); |
136 | 0 | } |
137 | | |
138 | | protected: |
139 | | NameID subfamilyNameID;/* The name ID for entries in the 'name' table |
140 | | * that provide subfamily names for this instance. */ |
141 | | HBUINT16 flags; /* Reserved for future use — set to 0. */ |
142 | | UnsizedArrayOf<F16DOT16> |
143 | | coordinatesZ; /* The coordinates array for this instance. */ |
144 | | //NameID postScriptNameIDX;/*Optional. The name ID for entries in the 'name' |
145 | | // * table that provide PostScript names for this |
146 | | // * instance. */ |
147 | | |
148 | | public: |
149 | | DEFINE_SIZE_UNBOUNDED (4); |
150 | | }; |
151 | | |
152 | | struct AxisRecord |
153 | | { |
154 | 43.4k | int cmp (hb_tag_t key) const { return axisTag.cmp (key); } |
155 | | |
156 | | enum |
157 | | { |
158 | | AXIS_FLAG_HIDDEN = 0x0001, |
159 | | }; |
160 | | |
161 | | #ifndef HB_DISABLE_DEPRECATED |
162 | | void get_axis_deprecated (hb_ot_var_axis_t *info) const |
163 | 0 | { |
164 | 0 | info->tag = axisTag; |
165 | 0 | info->name_id = axisNameID; |
166 | 0 | get_coordinates (info->min_value, info->default_value, info->max_value); |
167 | 0 | } |
168 | | #endif |
169 | | |
170 | | void get_axis_info (unsigned axis_index, hb_ot_var_axis_info_t *info) const |
171 | 4.55k | { |
172 | 4.55k | info->axis_index = axis_index; |
173 | 4.55k | info->tag = axisTag; |
174 | 4.55k | info->name_id = axisNameID; |
175 | 4.55k | info->flags = (hb_ot_var_axis_flags_t) (unsigned int) flags; |
176 | 4.55k | get_coordinates (info->min_value, info->default_value, info->max_value); |
177 | 4.55k | info->reserved = 0; |
178 | 4.55k | } |
179 | | |
180 | 108k | hb_tag_t get_axis_tag () const { return axisTag; } |
181 | | |
182 | | float normalize_axis_value (float v) const |
183 | 38.5k | { |
184 | 38.5k | float min_value, default_value, max_value; |
185 | 38.5k | get_coordinates (min_value, default_value, max_value); |
186 | | |
187 | 38.5k | v = hb_clamp (v, min_value, max_value); |
188 | | |
189 | 38.5k | if (v == default_value) |
190 | 26.2k | return 0; |
191 | 12.2k | else if (v < default_value) |
192 | 5.84k | return (v - default_value) / (default_value - min_value); |
193 | 6.38k | else |
194 | 6.38k | return (v - default_value) / (max_value - default_value); |
195 | 38.5k | } |
196 | | |
197 | 71.9k | hb_ot_name_id_t get_name_id () const { return axisNameID; } |
198 | | |
199 | | bool sanitize (hb_sanitize_context_t *c) const |
200 | 0 | { |
201 | 0 | TRACE_SANITIZE (this); |
202 | 0 | return_trace (c->check_struct (this)); |
203 | 0 | } |
204 | | |
205 | | void get_coordinates (float &min, float &default_, float &max) const |
206 | 53.0k | { |
207 | 53.0k | default_ = defaultValue.to_float (); |
208 | | /* Ensure order, to simplify client math. */ |
209 | 53.0k | min = hb_min (default_, minValue.to_float ()); |
210 | 53.0k | max = hb_max (default_, maxValue.to_float ()); |
211 | 53.0k | } |
212 | | |
213 | | float get_default () const |
214 | 8.64k | { |
215 | 8.64k | return defaultValue.to_float (); |
216 | 8.64k | } |
217 | | |
218 | | TripleDistances get_triple_distances () const |
219 | 9.96k | { |
220 | 9.96k | float min, default_, max; |
221 | 9.96k | get_coordinates (min, default_, max); |
222 | 9.96k | return TripleDistances ( |
223 | 9.96k | static_cast<double>(min), |
224 | 9.96k | static_cast<double>(default_), |
225 | 9.96k | static_cast<double>(max)); |
226 | 9.96k | } |
227 | | |
228 | | bool subset (hb_subset_context_t *c) const |
229 | 3.66k | { |
230 | 3.66k | TRACE_SUBSET (this); |
231 | 3.66k | auto *out = c->serializer->embed (this); |
232 | 3.66k | if (unlikely (!out)) return_trace (false); |
233 | | |
234 | 3.66k | const hb_hashmap_t<hb_tag_t, Triple>& user_axes_location = c->plan->user_axes_location; |
235 | 3.66k | Triple *axis_limit; |
236 | 3.66k | if (user_axes_location.has (axisTag, &axis_limit)) |
237 | 159 | { |
238 | 159 | out->minValue.set_float (axis_limit->minimum); |
239 | 159 | out->defaultValue.set_float (axis_limit->middle); |
240 | 159 | out->maxValue.set_float (axis_limit->maximum); |
241 | 159 | } |
242 | 3.66k | return_trace (true); |
243 | 3.66k | } |
244 | | |
245 | | public: |
246 | | Tag axisTag; /* Tag identifying the design variation for the axis. */ |
247 | | protected: |
248 | | F16DOT16 minValue; /* The minimum coordinate value for the axis. */ |
249 | | F16DOT16 defaultValue; /* The default coordinate value for the axis. */ |
250 | | F16DOT16 maxValue; /* The maximum coordinate value for the axis. */ |
251 | | public: |
252 | | HBUINT16 flags; /* Axis flags. */ |
253 | | NameID axisNameID; /* The name ID for entries in the 'name' table that |
254 | | * provide a display name for this axis. */ |
255 | | |
256 | | public: |
257 | | DEFINE_SIZE_STATIC (20); |
258 | | }; |
259 | | |
260 | | struct fvar |
261 | | { |
262 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_fvar; |
263 | | |
264 | 38.8k | bool has_data () const { return version.to_int (); } |
265 | | |
266 | | bool sanitize (hb_sanitize_context_t *c) const |
267 | 6.32k | { |
268 | 6.32k | TRACE_SANITIZE (this); |
269 | 6.32k | return_trace (version.sanitize (c) && |
270 | 6.32k | hb_barrier () && |
271 | 6.32k | likely (version.major == 1) && |
272 | 6.32k | c->check_struct (this) && |
273 | 6.32k | hb_barrier () && |
274 | 6.32k | axisSize == 20 && /* Assumed in our code. */ |
275 | 6.32k | instanceSize >= axisCount * 4 + 4 && |
276 | 6.32k | get_axes ().sanitize (c) && |
277 | 6.32k | c->check_range (&StructAfter<InstanceRecord> (get_axes ()), |
278 | 6.32k | instanceCount, instanceSize)); |
279 | 6.32k | } |
280 | | |
281 | 25 | unsigned int get_axis_count () const { return axisCount; } |
282 | | |
283 | | #ifndef HB_DISABLE_DEPRECATED |
284 | | unsigned int get_axes_deprecated (unsigned int start_offset, |
285 | | unsigned int *axes_count /* IN/OUT */, |
286 | | hb_ot_var_axis_t *axes_array /* OUT */) const |
287 | 0 | { |
288 | 0 | if (axes_count) |
289 | 0 | { |
290 | 0 | hb_array_t<const AxisRecord> arr = get_axes ().sub_array (start_offset, axes_count); |
291 | 0 | for (unsigned i = 0; i < arr.length; ++i) |
292 | 0 | arr[i].get_axis_deprecated (&axes_array[i]); |
293 | 0 | } |
294 | 0 | return axisCount; |
295 | 0 | } |
296 | | #endif |
297 | | |
298 | | unsigned int get_axis_infos (unsigned int start_offset, |
299 | | unsigned int *axes_count /* IN/OUT */, |
300 | | hb_ot_var_axis_info_t *axes_array /* OUT */) const |
301 | 24 | { |
302 | 24 | if (axes_count) |
303 | 24 | { |
304 | 24 | hb_array_t<const AxisRecord> arr = get_axes ().sub_array (start_offset, axes_count); |
305 | 72 | for (unsigned i = 0; i < arr.length; ++i) |
306 | 48 | arr[i].get_axis_info (start_offset + i, &axes_array[i]); |
307 | 24 | } |
308 | 24 | return axisCount; |
309 | 24 | } |
310 | | |
311 | | #ifndef HB_DISABLE_DEPRECATED |
312 | | bool |
313 | | find_axis_deprecated (hb_tag_t tag, unsigned *axis_index, hb_ot_var_axis_t *info) const |
314 | 0 | { |
315 | 0 | unsigned i; |
316 | 0 | if (!axis_index) axis_index = &i; |
317 | 0 | *axis_index = HB_OT_VAR_NO_AXIS_INDEX; |
318 | 0 | auto axes = get_axes (); |
319 | 0 | return axes.lfind (tag, axis_index) && ((void) axes[*axis_index].get_axis_deprecated (info), true); |
320 | 0 | } |
321 | | #endif |
322 | | bool |
323 | | find_axis_info (hb_tag_t tag, hb_ot_var_axis_info_t *info) const |
324 | 8.03k | { |
325 | 8.03k | unsigned i; |
326 | 8.03k | auto axes = get_axes (); |
327 | 8.03k | return axes.lfind (tag, &i) && ((void) axes[i].get_axis_info (i, info), true); |
328 | 8.03k | } |
329 | | |
330 | | float normalize_axis_value (unsigned int axis_index, float v) const |
331 | 8.64k | { return get_axes ()[axis_index].normalize_axis_value (v); } |
332 | | |
333 | 0 | unsigned int get_instance_count () const { return instanceCount; } |
334 | | |
335 | | hb_ot_name_id_t get_instance_subfamily_name_id (unsigned int instance_index) const |
336 | 0 | { |
337 | 0 | const InstanceRecord *instance = get_instance (instance_index); |
338 | 0 | if (unlikely (!instance)) return HB_OT_NAME_ID_INVALID; |
339 | 0 | return instance->subfamilyNameID; |
340 | 0 | } |
341 | | |
342 | | hb_ot_name_id_t get_instance_postscript_name_id (unsigned int instance_index) const |
343 | 0 | { |
344 | 0 | const InstanceRecord *instance = get_instance (instance_index); |
345 | 0 | if (unlikely (!instance)) return HB_OT_NAME_ID_INVALID; |
346 | 0 | if (instanceSize >= axisCount * 4 + 6) |
347 | 0 | return StructAfter<NameID> (instance->get_coordinates (axisCount)); |
348 | 0 | return HB_OT_NAME_ID_INVALID; |
349 | 0 | } |
350 | | |
351 | | unsigned int get_instance_coords (unsigned int instance_index, |
352 | | unsigned int *coords_length, /* IN/OUT */ |
353 | | float *coords /* OUT */) const |
354 | 0 | { |
355 | 0 | const InstanceRecord *instance = get_instance (instance_index); |
356 | 0 | if (unlikely (!instance)) |
357 | 0 | { |
358 | 0 | if (coords_length) |
359 | 0 | *coords_length = 0; |
360 | 0 | return 0; |
361 | 0 | } |
362 | | |
363 | 0 | if (coords_length && *coords_length) |
364 | 0 | { |
365 | 0 | hb_array_t<const F16DOT16> instanceCoords = instance->get_coordinates (axisCount) |
366 | 0 | .sub_array (0, coords_length); |
367 | 0 | for (unsigned int i = 0; i < instanceCoords.length; i++) |
368 | 0 | coords[i] = instanceCoords.arrayZ[i].to_float (); |
369 | 0 | } |
370 | 0 | return axisCount; |
371 | 0 | } |
372 | | |
373 | | void collect_name_ids (hb_hashmap_t<hb_tag_t, Triple> *user_axes_location, |
374 | | hb_map_t *axes_old_index_tag_map, |
375 | | hb_set_t *nameids /* IN/OUT */) const |
376 | 38.8k | { |
377 | 38.8k | if (!has_data ()) return; |
378 | | |
379 | 7.01k | auto axis_records = get_axes (); |
380 | 87.2k | for (unsigned i = 0 ; i < (unsigned)axisCount; i++) |
381 | 80.2k | { |
382 | 80.2k | hb_tag_t axis_tag = axis_records[i].get_axis_tag (); |
383 | 80.2k | if (user_axes_location->has (axis_tag) && |
384 | 8.68k | user_axes_location->get (axis_tag).is_point ()) |
385 | 8.25k | continue; |
386 | | |
387 | 71.9k | nameids->add (axis_records[i].get_name_id ()); |
388 | 71.9k | } |
389 | | |
390 | 49.7k | for (unsigned i = 0 ; i < (unsigned)instanceCount; i++) |
391 | 42.7k | { |
392 | 42.7k | const InstanceRecord *instance = get_instance (i); |
393 | | |
394 | 42.7k | if (!instance->keep_instance (axisCount, axes_old_index_tag_map, user_axes_location)) |
395 | 8.09k | continue; |
396 | | |
397 | 34.6k | nameids->add (instance->subfamilyNameID); |
398 | | |
399 | 34.6k | if (instanceSize >= axisCount * 4 + 6) |
400 | 5.10k | { |
401 | 5.10k | unsigned post_script_name_id = StructAfter<NameID> (instance->get_coordinates (axisCount)); |
402 | 5.10k | if (post_script_name_id != HB_OT_NAME_ID_INVALID) nameids->add (post_script_name_id); |
403 | 5.10k | } |
404 | 34.6k | } |
405 | 7.01k | } |
406 | | |
407 | | bool subset (hb_subset_context_t *c) const |
408 | 969 | { |
409 | 969 | TRACE_SUBSET (this); |
410 | 969 | unsigned retained_axis_count = c->plan->axes_index_map.get_population (); |
411 | 969 | if (!retained_axis_count) //all axes are pinned |
412 | 0 | return_trace (false); |
413 | | |
414 | 969 | fvar *out = c->serializer->embed (this); |
415 | 969 | if (unlikely (!out)) return_trace (false); |
416 | | |
417 | 969 | if (!c->serializer->check_assign (out->axisCount, retained_axis_count, HB_SERIALIZE_ERROR_INT_OVERFLOW)) |
418 | 0 | return_trace (false); |
419 | | |
420 | 969 | bool has_postscript_nameid = false; |
421 | 969 | if (instanceSize >= axisCount * 4 + 6) |
422 | 230 | has_postscript_nameid = true; |
423 | | |
424 | 969 | if (!c->serializer->check_assign (out->instanceSize, retained_axis_count * 4 + (has_postscript_nameid ? 6 : 4), |
425 | 969 | HB_SERIALIZE_ERROR_INT_OVERFLOW)) |
426 | 0 | return_trace (false); |
427 | | |
428 | 969 | auto axes_records = get_axes (); |
429 | 6.26k | for (unsigned i = 0 ; i < (unsigned)axisCount; i++) |
430 | 5.29k | { |
431 | 5.29k | if (!c->plan->axes_index_map.has (i)) continue; |
432 | 3.66k | if (unlikely (!axes_records[i].subset (c))) |
433 | 0 | return_trace (false); |
434 | 3.66k | } |
435 | | |
436 | 969 | if (!c->serializer->check_assign (out->firstAxis, get_size (), HB_SERIALIZE_ERROR_INT_OVERFLOW)) |
437 | 0 | return_trace (false); |
438 | | |
439 | 969 | unsigned num_retained_instances = 0; |
440 | 6.83k | for (unsigned i = 0 ; i < (unsigned)instanceCount; i++) |
441 | 5.86k | { |
442 | 5.86k | const InstanceRecord *instance = get_instance (i); |
443 | 5.86k | auto snap = c->serializer->snapshot (); |
444 | 5.86k | if (!instance->subset (c, axisCount, has_postscript_nameid)) |
445 | 5.48k | c->serializer->revert (snap); |
446 | 375 | else |
447 | 375 | num_retained_instances++; |
448 | 5.86k | } |
449 | | |
450 | 969 | return_trace (c->serializer->check_assign (out->instanceCount, num_retained_instances, HB_SERIALIZE_ERROR_INT_OVERFLOW)); |
451 | 969 | } |
452 | | |
453 | | public: |
454 | | hb_array_t<const AxisRecord> get_axes () const |
455 | 90.2k | { return hb_array (&(this+firstAxis), axisCount); } |
456 | | |
457 | | const InstanceRecord *get_instance (unsigned int i) const |
458 | 48.6k | { |
459 | 48.6k | if (unlikely (i >= instanceCount)) return nullptr; |
460 | 48.6k | return &StructAtOffset<InstanceRecord> (&StructAfter<InstanceRecord> (get_axes ()), |
461 | 48.6k | i * instanceSize); |
462 | 48.6k | } |
463 | | |
464 | | protected: |
465 | | FixedVersion<>version; /* Version of the fvar table |
466 | | * initially set to 0x00010000u */ |
467 | | Offset16To<AxisRecord> |
468 | | firstAxis; /* Offset in bytes from the beginning of the table |
469 | | * to the start of the AxisRecord array. */ |
470 | | HBUINT16 reserved; /* This field is permanently reserved. Set to 2. */ |
471 | | HBUINT16 axisCount; /* The number of variation axes in the font (the |
472 | | * number of records in the axes array). */ |
473 | | HBUINT16 axisSize; /* The size in bytes of each VariationAxisRecord — |
474 | | * set to 20 (0x0014) for this version. */ |
475 | | HBUINT16 instanceCount; /* The number of named instances defined in the font |
476 | | * (the number of records in the instances array). */ |
477 | | HBUINT16 instanceSize; /* The size in bytes of each InstanceRecord — set |
478 | | * to either axisCount * sizeof(F16DOT16) + 4, or to |
479 | | * axisCount * sizeof(F16DOT16) + 6. */ |
480 | | |
481 | | public: |
482 | | DEFINE_SIZE_STATIC (16); |
483 | | }; |
484 | | |
485 | | } /* namespace OT */ |
486 | | |
487 | | |
488 | | #endif /* HB_OT_VAR_FVAR_TABLE_HH */ |