/src/harfbuzz/src/hb-ot-var-avar-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_AVAR_TABLE_HH |
28 | | #define HB_OT_VAR_AVAR_TABLE_HH |
29 | | |
30 | | #include "hb-open-type.hh" |
31 | | #include "hb-ot-var-common.hh" |
32 | | |
33 | | |
34 | | /* |
35 | | * avar -- Axis Variations |
36 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/avar |
37 | | */ |
38 | | |
39 | | #define HB_OT_TAG_avar HB_TAG('a','v','a','r') |
40 | | |
41 | | |
42 | | namespace OT { |
43 | | |
44 | | |
45 | | /* "Spec": https://github.com/be-fonts/boring-expansion-spec/issues/14 */ |
46 | | struct avarV2Tail |
47 | | { |
48 | | friend struct avar; |
49 | | |
50 | | bool sanitize (hb_sanitize_context_t *c, |
51 | | const void *base) const |
52 | 714 | { |
53 | 714 | TRACE_SANITIZE (this); |
54 | 714 | return_trace (varIdxMap.sanitize (c, base) && |
55 | 714 | varStore.sanitize (c, base)); |
56 | 714 | } |
57 | | |
58 | | protected: |
59 | | Offset32To<DeltaSetIndexMap> varIdxMap; /* Offset from the beginning of 'avar' table. */ |
60 | | Offset32To<ItemVariationStore> varStore; /* Offset from the beginning of 'avar' table. */ |
61 | | |
62 | | public: |
63 | | DEFINE_SIZE_STATIC (8); |
64 | | }; |
65 | | |
66 | | |
67 | | struct AxisValueMap |
68 | | { |
69 | | bool sanitize (hb_sanitize_context_t *c) const |
70 | 0 | { |
71 | 0 | TRACE_SANITIZE (this); |
72 | 0 | return_trace (c->check_struct (this)); |
73 | 0 | } |
74 | | |
75 | | void set_mapping (float from_coord, float to_coord) |
76 | 504 | { |
77 | 504 | coords[0].set_float (from_coord); |
78 | 504 | coords[1].set_float (to_coord); |
79 | 504 | } |
80 | | |
81 | | bool is_outside_axis_range (const Triple& axis_range) const |
82 | 944 | { |
83 | 944 | double from_coord = (double) coords[0].to_float (); |
84 | 944 | return !axis_range.contains (from_coord); |
85 | 944 | } |
86 | | |
87 | | bool must_include () const |
88 | 0 | { |
89 | 0 | float from_coord = coords[0].to_float (); |
90 | 0 | float to_coord = coords[1].to_float (); |
91 | 0 | return (from_coord == -1.f && to_coord == -1.f) || |
92 | 0 | (from_coord == 0.f && to_coord == 0.f) || |
93 | 0 | (from_coord == 1.f && to_coord == 1.f); |
94 | 0 | } |
95 | | |
96 | | void instantiate (const Triple& axis_range, |
97 | | const Triple& unmapped_range, |
98 | | const TripleDistances& triple_distances) |
99 | 444 | { |
100 | 444 | float from_coord = coords[0].to_float (); |
101 | 444 | float to_coord = coords[1].to_float (); |
102 | | |
103 | 444 | from_coord = renormalizeValue ((double) from_coord, unmapped_range, triple_distances); |
104 | 444 | to_coord = renormalizeValue ((double) to_coord, axis_range, triple_distances); |
105 | | |
106 | 444 | coords[0].set_float (from_coord); |
107 | 444 | coords[1].set_float (to_coord); |
108 | 444 | } |
109 | | |
110 | | HB_INTERNAL static int cmp (const void *pa, const void *pb) |
111 | 1.28k | { |
112 | 1.28k | const AxisValueMap *a = (const AxisValueMap *) pa; |
113 | 1.28k | const AxisValueMap *b = (const AxisValueMap *) pb; |
114 | | |
115 | 1.28k | int a_from = a->coords[0].to_int (); |
116 | 1.28k | int b_from = b->coords[0].to_int (); |
117 | 1.28k | if (a_from != b_from) |
118 | 1.20k | return a_from - b_from; |
119 | | |
120 | | /* this should never be reached. according to the spec, all of the axis |
121 | | * value map records for a given axis must have different fromCoord values |
122 | | * */ |
123 | 76 | int a_to = a->coords[1].to_int (); |
124 | 76 | int b_to = b->coords[1].to_int (); |
125 | 76 | return a_to - b_to; |
126 | 1.28k | } |
127 | | |
128 | | bool serialize (hb_serialize_context_t *c) const |
129 | 832 | { |
130 | 832 | TRACE_SERIALIZE (this); |
131 | 832 | return_trace (c->embed (this)); |
132 | 832 | } |
133 | | |
134 | | public: |
135 | | F2DOT14 coords[2]; |
136 | | // F2DOT14 fromCoord; /* A normalized coordinate value obtained using |
137 | | // * default normalization. */ |
138 | | // F2DOT14 toCoord; /* The modified, normalized coordinate value. */ |
139 | | |
140 | | public: |
141 | | DEFINE_SIZE_STATIC (4); |
142 | | }; |
143 | | |
144 | | struct SegmentMaps : Array16Of<AxisValueMap> |
145 | | { |
146 | | float map_float (float value, unsigned int from_offset = 0, unsigned int to_offset = 1) const |
147 | 12.7k | { |
148 | 175k | #define fromCoord coords[from_offset].to_float () |
149 | 35.0k | #define toCoord coords[to_offset].to_float () |
150 | | |
151 | 12.7k | const auto *map = arrayZ; |
152 | | |
153 | | /* The following special-cases are not part of OpenType, which requires |
154 | | * that at least -1, 0, and +1 must be mapped. But we include these as |
155 | | * part of a better error recovery scheme. */ |
156 | 12.7k | if (len < 2) |
157 | 3.07k | { |
158 | 3.07k | if (!len) |
159 | 2.67k | return value; |
160 | 396 | else /* len == 1*/ |
161 | 396 | return value - map[0].fromCoord + map[0].toCoord; |
162 | 3.07k | } |
163 | | |
164 | | // At least two mappings now. |
165 | | |
166 | | /* CoreText is wild... |
167 | | * PingFangUI avar needs all this special-casing... |
168 | | * So we implement an extended version of the spec here, |
169 | | * which is more robust and more likely to be compatible with |
170 | | * the wild. */ |
171 | | |
172 | 9.64k | unsigned start = 0; |
173 | 9.64k | unsigned end = len; |
174 | 9.64k | if (map[start].fromCoord == -1 && map[start].toCoord == -1 && map[start+1].fromCoord == -1) |
175 | 14 | start++; |
176 | 9.64k | if (map[end-1].fromCoord == +1 && map[end-1].toCoord == +1 && map[end-2].fromCoord == +1) |
177 | 34 | end--; |
178 | | |
179 | | /* Look for exact match first, and do lots of special-casing. */ |
180 | 9.64k | unsigned i; |
181 | 111k | for (i = start; i < end; i++) |
182 | 106k | if (value == map[i].fromCoord) |
183 | 4.36k | break; |
184 | 9.64k | if (i < end) |
185 | 4.36k | { |
186 | | // There's at least one exact match. See if there are more. |
187 | 4.36k | unsigned j = i; |
188 | 6.95k | for (; j + 1 < end; j++) |
189 | 6.58k | if (value != map[j + 1].fromCoord) |
190 | 3.99k | break; |
191 | | |
192 | | // [i,j] inclusive are all exact matches: |
193 | | |
194 | | // If there's only one, return it. This is the only spec-compliant case. |
195 | 4.36k | if (i == j) |
196 | 3.73k | return map[i].toCoord; |
197 | | // If there's exactly three, return the middle one. |
198 | 627 | if (i + 2 == j) |
199 | 157 | return map[i + 1].toCoord; |
200 | | |
201 | | // Ignore the middle ones. Return the one mapping closer to 0. |
202 | 470 | if (value < 0) return map[j].toCoord; |
203 | 458 | if (value > 0) return map[i].toCoord; |
204 | | |
205 | | // Mapping 0? CoreText seems confused. It seems to prefer 0 here... |
206 | | // So we'll just return the smallest one. lol |
207 | 446 | return fabsf (map[i].toCoord) < fabsf (map[j].toCoord) ? map[i].toCoord : map[j].toCoord; |
208 | | |
209 | | // Mapping 0? Return one not mapping to 0. |
210 | 0 | if (map[i].toCoord == 0) |
211 | 0 | return map[j].toCoord; |
212 | 0 | else |
213 | 0 | return map[i].toCoord; |
214 | 0 | } |
215 | | |
216 | | /* There's at least two and we're not an exact match. Prepare to lerp. */ |
217 | | |
218 | | // Find the segment we're in. |
219 | 13.6k | for (i = start; i < end; i++) |
220 | 13.5k | if (value < map[i].fromCoord) |
221 | 5.17k | break; |
222 | | |
223 | 5.28k | if (i == 0) |
224 | 688 | { |
225 | | // Value before all segments; Shift. |
226 | 688 | return value - map[0].fromCoord + map[0].toCoord; |
227 | 688 | } |
228 | 4.59k | if (i == end) |
229 | 109 | { |
230 | | // Value after all segments; Shift. |
231 | 109 | return value - map[end - 1].fromCoord + map[end - 1].toCoord; |
232 | 109 | } |
233 | | |
234 | | // Actually interpolate. |
235 | 4.48k | auto &before = map[i-1]; |
236 | 4.48k | auto &after = map[i]; |
237 | 4.48k | float denom = after.fromCoord - before.fromCoord; // Can't be zero by now. |
238 | 4.48k | return before.toCoord + ((after.toCoord - before.toCoord) * (value - before.fromCoord)) / denom; |
239 | | |
240 | 4.59k | #undef toCoord |
241 | 4.59k | #undef fromCoord |
242 | 4.59k | } |
243 | | |
244 | 504 | float unmap_float (float value) const { return map_float (value, 1, 0); } |
245 | | |
246 | | |
247 | | // TODO Kill this. |
248 | | Triple unmap_axis_range (const Triple& axis_range) const |
249 | 168 | { |
250 | 168 | float unmapped_min = unmap_float (axis_range.minimum); |
251 | 168 | float unmapped_middle = unmap_float (axis_range.middle); |
252 | 168 | float unmapped_max = unmap_float (axis_range.maximum); |
253 | | |
254 | 168 | return Triple{(double) unmapped_min, (double) unmapped_middle, (double) unmapped_max}; |
255 | 168 | } |
256 | | |
257 | | bool subset (hb_subset_context_t *c, hb_tag_t axis_tag) const |
258 | 196 | { |
259 | 196 | TRACE_SUBSET (this); |
260 | | |
261 | | /* This function cannot work on avar2 table (and currently doesn't). |
262 | | * We should instead keep the design coords in the shape plan and use |
263 | | * those. unmap_axis_range needs to be killed. */ |
264 | | |
265 | | /* avar mapped normalized axis range*/ |
266 | 196 | Triple *axis_range; |
267 | 196 | if (!c->plan->axes_location.has (axis_tag, &axis_range)) |
268 | 28 | return c->serializer->embed (*this); |
269 | | |
270 | 168 | TripleDistances *axis_triple_distances; |
271 | 168 | if (!c->plan->axes_triple_distances.has (axis_tag, &axis_triple_distances)) |
272 | 0 | return_trace (false); |
273 | | |
274 | 168 | auto *out = c->serializer->start_embed (this); |
275 | 168 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
276 | | |
277 | 168 | Triple unmapped_range = unmap_axis_range (*axis_range); |
278 | | |
279 | | /* create a vector of retained mappings and sort */ |
280 | 168 | hb_vector_t<AxisValueMap> value_mappings; |
281 | 168 | for (const auto& _ : as_array ()) |
282 | 944 | { |
283 | 944 | if (_.is_outside_axis_range (unmapped_range)) |
284 | 500 | continue; |
285 | 444 | AxisValueMap mapping; |
286 | 444 | mapping = _; |
287 | 444 | mapping.instantiate (*axis_range, unmapped_range, *axis_triple_distances); |
288 | | /* (-1, -1), (0, 0), (1, 1) mappings will be added later, so avoid |
289 | | * duplicates here */ |
290 | 444 | if (mapping.must_include ()) |
291 | 116 | continue; |
292 | 328 | value_mappings.push (mapping); |
293 | 328 | } |
294 | | |
295 | 168 | AxisValueMap m; |
296 | 168 | m.set_mapping (-1.f, -1.f); |
297 | 168 | value_mappings.push (m); |
298 | | |
299 | 168 | m.set_mapping (0.f, 0.f); |
300 | 168 | value_mappings.push (m); |
301 | | |
302 | 168 | m.set_mapping (1.f, 1.f); |
303 | 168 | value_mappings.push (m); |
304 | | |
305 | 168 | value_mappings.qsort (); |
306 | | |
307 | 168 | for (const auto& _ : value_mappings) |
308 | 832 | { |
309 | 832 | if (!_.serialize (c->serializer)) |
310 | 0 | return_trace (false); |
311 | 832 | } |
312 | 168 | return_trace (c->serializer->check_assign (out->len, value_mappings.length, HB_SERIALIZE_ERROR_INT_OVERFLOW)); |
313 | 168 | } Unexecuted instantiation: OT::SegmentMaps::subset(hb_subset_context_t*, unsigned int) const OT::SegmentMaps::subset(hb_subset_context_t*, unsigned int) const Line | Count | Source | 258 | 196 | { | 259 | 196 | TRACE_SUBSET (this); | 260 | | | 261 | | /* This function cannot work on avar2 table (and currently doesn't). | 262 | | * We should instead keep the design coords in the shape plan and use | 263 | | * those. unmap_axis_range needs to be killed. */ | 264 | | | 265 | | /* avar mapped normalized axis range*/ | 266 | 196 | Triple *axis_range; | 267 | 196 | if (!c->plan->axes_location.has (axis_tag, &axis_range)) | 268 | 28 | return c->serializer->embed (*this); | 269 | | | 270 | 168 | TripleDistances *axis_triple_distances; | 271 | 168 | if (!c->plan->axes_triple_distances.has (axis_tag, &axis_triple_distances)) | 272 | 0 | return_trace (false); | 273 | | | 274 | 168 | auto *out = c->serializer->start_embed (this); | 275 | 168 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); | 276 | | | 277 | 168 | Triple unmapped_range = unmap_axis_range (*axis_range); | 278 | | | 279 | | /* create a vector of retained mappings and sort */ | 280 | 168 | hb_vector_t<AxisValueMap> value_mappings; | 281 | 168 | for (const auto& _ : as_array ()) | 282 | 944 | { | 283 | 944 | if (_.is_outside_axis_range (unmapped_range)) | 284 | 500 | continue; | 285 | 444 | AxisValueMap mapping; | 286 | 444 | mapping = _; | 287 | 444 | mapping.instantiate (*axis_range, unmapped_range, *axis_triple_distances); | 288 | | /* (-1, -1), (0, 0), (1, 1) mappings will be added later, so avoid | 289 | | * duplicates here */ | 290 | 444 | if (mapping.must_include ()) | 291 | 116 | continue; | 292 | 328 | value_mappings.push (mapping); | 293 | 328 | } | 294 | | | 295 | 168 | AxisValueMap m; | 296 | 168 | m.set_mapping (-1.f, -1.f); | 297 | 168 | value_mappings.push (m); | 298 | | | 299 | 168 | m.set_mapping (0.f, 0.f); | 300 | 168 | value_mappings.push (m); | 301 | | | 302 | 168 | m.set_mapping (1.f, 1.f); | 303 | 168 | value_mappings.push (m); | 304 | | | 305 | 168 | value_mappings.qsort (); | 306 | | | 307 | 168 | for (const auto& _ : value_mappings) | 308 | 832 | { | 309 | 832 | if (!_.serialize (c->serializer)) | 310 | 0 | return_trace (false); | 311 | 832 | } | 312 | 168 | return_trace (c->serializer->check_assign (out->len, value_mappings.length, HB_SERIALIZE_ERROR_INT_OVERFLOW)); | 313 | 168 | } |
|
314 | | |
315 | | public: |
316 | | DEFINE_SIZE_ARRAY (2, *this); |
317 | | }; |
318 | | |
319 | | struct avar |
320 | | { |
321 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_avar; |
322 | | |
323 | 2.34k | bool has_data () const { return version.to_int (); } |
324 | | |
325 | | const SegmentMaps* get_segment_maps () const |
326 | 0 | { return &firstAxisSegmentMaps; } |
327 | | |
328 | | unsigned get_axis_count () const |
329 | 0 | { return axisCount; } |
330 | | |
331 | | bool sanitize (hb_sanitize_context_t *c) const |
332 | 6.05k | { |
333 | 6.05k | TRACE_SANITIZE (this); |
334 | 6.05k | if (!(version.sanitize (c) && |
335 | 6.04k | hb_barrier () && |
336 | 6.04k | (version.major == 1 |
337 | 2.86k | #ifndef HB_NO_AVAR2 |
338 | 2.86k | || version.major == 2 |
339 | 6.04k | #endif |
340 | 6.04k | ) && |
341 | 3.95k | c->check_struct (this))) |
342 | 2.10k | return_trace (false); |
343 | | |
344 | 3.95k | const SegmentMaps *map = &firstAxisSegmentMaps; |
345 | 3.95k | unsigned int count = axisCount; |
346 | 20.6k | for (unsigned int i = 0; i < count; i++) |
347 | 17.1k | { |
348 | 17.1k | if (unlikely (!map->sanitize (c))) |
349 | 415 | return_trace (false); |
350 | 16.7k | map = &StructAfter<SegmentMaps> (*map); |
351 | 16.7k | } |
352 | | |
353 | 3.53k | #ifndef HB_NO_AVAR2 |
354 | 3.53k | if (version.major < 2) |
355 | 2.82k | return_trace (true); |
356 | 714 | hb_barrier (); |
357 | | |
358 | 714 | const auto &v2 = * (const avarV2Tail *) map; |
359 | 714 | if (unlikely (!v2.sanitize (c, this))) |
360 | 235 | return_trace (false); |
361 | 479 | #endif |
362 | | |
363 | 714 | return_trace (true); |
364 | 714 | } |
365 | | |
366 | | void map_coords_16_16 (int *coords, unsigned int coords_length) const |
367 | 159k | { |
368 | 159k | unsigned int count = hb_min (coords_length, axisCount); |
369 | | |
370 | 159k | const SegmentMaps *map = &firstAxisSegmentMaps; |
371 | 167k | for (unsigned int i = 0; i < count; i++) |
372 | 8.58k | { |
373 | 8.58k | coords[i] = roundf (map->map_float (coords[i] / 65536.f) * 65536.f); |
374 | 8.58k | map = &StructAfter<SegmentMaps> (*map); |
375 | 8.58k | } |
376 | | |
377 | 159k | #ifndef HB_NO_AVAR2 |
378 | 159k | if (version.major < 2) |
379 | 158k | return; |
380 | 777 | hb_barrier (); |
381 | | |
382 | 7.79k | for (; count < axisCount; count++) |
383 | 7.01k | map = &StructAfter<SegmentMaps> (*map); |
384 | | |
385 | 777 | const auto &v2 = * (const avarV2Tail *) map; |
386 | | |
387 | 777 | const auto &varidx_map = this+v2.varIdxMap; |
388 | 777 | const auto &var_store = this+v2.varStore; |
389 | 777 | auto *var_store_cache = var_store.create_cache (); |
390 | | |
391 | 777 | hb_vector_t<int> coords_2_14; |
392 | 777 | coords_2_14.resize (coords_length); |
393 | 15.4k | for (unsigned i = 0; i < coords_length; i++) |
394 | 14.6k | coords_2_14[i] = roundf (coords[i] / 4.f); // 16.16 -> 2.14 |
395 | | |
396 | 777 | hb_vector_t<int> out; |
397 | 777 | out.alloc (coords_length); |
398 | 15.4k | for (unsigned i = 0; i < coords_length; i++) |
399 | 14.6k | { |
400 | 14.6k | int v = coords[i]; |
401 | 14.6k | uint32_t varidx = varidx_map.map (i); |
402 | 14.6k | float delta = var_store.get_delta (varidx, coords_2_14.arrayZ, coords_2_14.length, var_store_cache); |
403 | 14.6k | float d = hb_clamp (delta * 4, -(float) (1<<16), +(float) (1<<16)); // 2.14 -> 16.16 |
404 | 14.6k | v += (int) roundf (d); |
405 | 14.6k | v = hb_clamp (v, -(1<<16), +(1<<16)); |
406 | 14.6k | out.push (v); |
407 | 14.6k | } |
408 | 15.4k | for (unsigned i = 0; i < coords_length; i++) |
409 | 14.6k | coords[i] = out[i]; |
410 | | |
411 | 777 | OT::ItemVariationStore::destroy_cache (var_store_cache); |
412 | 777 | #endif |
413 | 777 | } |
414 | | |
415 | 624 | bool has_v2_data () const { return version.major > 1; } |
416 | | |
417 | | // axis normalization is done in 2.14 here |
418 | | // TODO: deprecate this API once fonttools is updated to use 16.16 normalization |
419 | | bool map_coords_2_14 (float *coords, unsigned int coords_length) const |
420 | 1.86k | { |
421 | 1.86k | hb_vector_t<int> coords_2_14; |
422 | 1.86k | if (!coords_2_14.resize (coords_length)) return false; |
423 | 1.86k | unsigned int count = hb_min (coords_length, axisCount); |
424 | | |
425 | 1.86k | const SegmentMaps *map = &firstAxisSegmentMaps; |
426 | 5.50k | for (unsigned int i = 0; i < count; i++) |
427 | 3.63k | { |
428 | 3.63k | int v = roundf (map->map_float (coords[i]) * 16384.f); |
429 | 3.63k | coords_2_14[i] = v; |
430 | 3.63k | coords[i] = v / 16384.f; |
431 | 3.63k | map = &StructAfter<SegmentMaps> (*map); |
432 | 3.63k | } |
433 | | |
434 | 1.86k | #ifndef HB_NO_AVAR2 |
435 | 1.86k | if (version.major < 2) |
436 | 1.86k | return true; |
437 | 3 | hb_barrier (); |
438 | | |
439 | 3 | for (; count < axisCount; count++) |
440 | 0 | map = &StructAfter<SegmentMaps> (*map); |
441 | | |
442 | 3 | const auto &v2 = * (const avarV2Tail *) map; |
443 | | |
444 | 3 | const auto &varidx_map = this+v2.varIdxMap; |
445 | 3 | const auto &var_store = this+v2.varStore; |
446 | 3 | auto *var_store_cache = var_store.create_cache (); |
447 | | |
448 | 9 | for (unsigned i = 0; i < coords_length; i++) |
449 | 6 | { |
450 | 6 | int v = coords_2_14[i]; |
451 | 6 | uint32_t varidx = varidx_map.map (i); |
452 | 6 | float delta = var_store.get_delta (varidx, coords_2_14.arrayZ, coords_2_14.length, var_store_cache); |
453 | 6 | v += roundf (delta); |
454 | 6 | v = hb_clamp (v, -(1<<16), +(1<<16)); |
455 | 6 | coords[i] = v / 16384.f; |
456 | 6 | } |
457 | | |
458 | 3 | OT::ItemVariationStore::destroy_cache (var_store_cache); |
459 | 3 | return true; |
460 | | #else |
461 | | return version.major < 2; |
462 | | #endif |
463 | 1.86k | } Unexecuted instantiation: OT::avar::map_coords_2_14(float*, unsigned int) const OT::avar::map_coords_2_14(float*, unsigned int) const Line | Count | Source | 420 | 1.86k | { | 421 | 1.86k | hb_vector_t<int> coords_2_14; | 422 | 1.86k | if (!coords_2_14.resize (coords_length)) return false; | 423 | 1.86k | unsigned int count = hb_min (coords_length, axisCount); | 424 | | | 425 | 1.86k | const SegmentMaps *map = &firstAxisSegmentMaps; | 426 | 5.50k | for (unsigned int i = 0; i < count; i++) | 427 | 3.63k | { | 428 | 3.63k | int v = roundf (map->map_float (coords[i]) * 16384.f); | 429 | 3.63k | coords_2_14[i] = v; | 430 | 3.63k | coords[i] = v / 16384.f; | 431 | 3.63k | map = &StructAfter<SegmentMaps> (*map); | 432 | 3.63k | } | 433 | | | 434 | 1.86k | #ifndef HB_NO_AVAR2 | 435 | 1.86k | if (version.major < 2) | 436 | 1.86k | return true; | 437 | 3 | hb_barrier (); | 438 | | | 439 | 3 | for (; count < axisCount; count++) | 440 | 0 | map = &StructAfter<SegmentMaps> (*map); | 441 | | | 442 | 3 | const auto &v2 = * (const avarV2Tail *) map; | 443 | | | 444 | 3 | const auto &varidx_map = this+v2.varIdxMap; | 445 | 3 | const auto &var_store = this+v2.varStore; | 446 | 3 | auto *var_store_cache = var_store.create_cache (); | 447 | | | 448 | 9 | for (unsigned i = 0; i < coords_length; i++) | 449 | 6 | { | 450 | 6 | int v = coords_2_14[i]; | 451 | 6 | uint32_t varidx = varidx_map.map (i); | 452 | 6 | float delta = var_store.get_delta (varidx, coords_2_14.arrayZ, coords_2_14.length, var_store_cache); | 453 | 6 | v += roundf (delta); | 454 | 6 | v = hb_clamp (v, -(1<<16), +(1<<16)); | 455 | 6 | coords[i] = v / 16384.f; | 456 | 6 | } | 457 | | | 458 | 3 | OT::ItemVariationStore::destroy_cache (var_store_cache); | 459 | 3 | return true; | 460 | | #else | 461 | | return version.major < 2; | 462 | | #endif | 463 | 1.86k | } |
|
464 | | |
465 | | bool subset (hb_subset_context_t *c) const |
466 | 157 | { |
467 | 157 | TRACE_SUBSET (this); |
468 | 157 | unsigned retained_axis_count = c->plan->axes_index_map.get_population (); |
469 | 157 | if (!retained_axis_count) //all axes are pinned/dropped |
470 | 0 | return_trace (false); |
471 | | |
472 | 157 | avar *out = c->serializer->allocate_min<avar> (); |
473 | 157 | if (unlikely (!out)) return_trace (false); |
474 | | |
475 | 157 | out->version.major = 1; |
476 | 157 | out->version.minor = 0; |
477 | 157 | if (!c->serializer->check_assign (out->axisCount, retained_axis_count, HB_SERIALIZE_ERROR_INT_OVERFLOW)) |
478 | 0 | return_trace (false); |
479 | | |
480 | 157 | const hb_map_t& axes_index_map = c->plan->axes_index_map; |
481 | 157 | const SegmentMaps *map = &firstAxisSegmentMaps; |
482 | 157 | unsigned count = axisCount; |
483 | 470 | for (unsigned int i = 0; i < count; i++) |
484 | 313 | { |
485 | 313 | if (axes_index_map.has (i)) |
486 | 196 | { |
487 | 196 | hb_tag_t *axis_tag; |
488 | 196 | if (!c->plan->axes_old_index_tag_map.has (i, &axis_tag)) |
489 | 0 | return_trace (false); |
490 | 196 | if (!map->subset (c, *axis_tag)) |
491 | 0 | return_trace (false); |
492 | 196 | } |
493 | 313 | map = &StructAfter<SegmentMaps> (*map); |
494 | 313 | } |
495 | 157 | return_trace (true); |
496 | 157 | } |
497 | | |
498 | | protected: |
499 | | FixedVersion<>version; /* Version of the avar table |
500 | | * initially set to 0x00010000u */ |
501 | | HBUINT16 reserved; /* This field is permanently reserved. Set to 0. */ |
502 | | HBUINT16 axisCount; /* The number of variation axes in the font. This |
503 | | * must be the same number as axisCount in the |
504 | | * 'fvar' table. */ |
505 | | SegmentMaps firstAxisSegmentMaps; |
506 | | |
507 | | public: |
508 | | DEFINE_SIZE_MIN (8); |
509 | | }; |
510 | | |
511 | | } /* namespace OT */ |
512 | | |
513 | | |
514 | | #endif /* HB_OT_VAR_AVAR_TABLE_HH */ |