/src/harfbuzz/src/hb-ot-var-hvar-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_HVAR_TABLE_HH |
28 | | #define HB_OT_VAR_HVAR_TABLE_HH |
29 | | |
30 | | #include "hb-ot-layout-common.hh" |
31 | | #include "hb-ot-var-common.hh" |
32 | | |
33 | | namespace OT { |
34 | | |
35 | | |
36 | | struct index_map_subset_plan_t |
37 | | { |
38 | | enum index_map_index_t { |
39 | | ADV_INDEX, |
40 | | LSB_INDEX, /* dual as TSB */ |
41 | | RSB_INDEX, /* dual as BSB */ |
42 | | VORG_INDEX |
43 | | }; |
44 | | |
45 | | void init (const DeltaSetIndexMap *index_map, |
46 | | hb_inc_bimap_t &outer_map, |
47 | | hb_vector_t<hb_set_t *> &inner_sets, |
48 | | const hb_subset_plan_t *plan, |
49 | | bool bypass_empty = true) |
50 | 4.15k | { |
51 | 4.15k | map_count = 0; |
52 | 4.15k | max_inners.init (); |
53 | 4.15k | output_map.init (); |
54 | | |
55 | 4.15k | if (bypass_empty && (!index_map || !index_map->get_map_count ())) return; |
56 | | |
57 | 2.20k | unsigned int last_val = (unsigned int)-1; |
58 | 2.20k | hb_codepoint_t last_gid = HB_CODEPOINT_INVALID; |
59 | | |
60 | 2.20k | max_inners.resize (inner_sets.length); |
61 | 8.20k | for (unsigned i = 0; i < inner_sets.length; i++) max_inners[i] = 0; |
62 | | |
63 | | /* Search backwards for a map value different from the last map value */ |
64 | 2.20k | auto &new_to_old_gid_list = plan->new_to_old_gid_list; |
65 | 2.20k | unsigned count = new_to_old_gid_list.length; |
66 | 2.20k | if (!index_map) |
67 | 584 | { |
68 | 584 | map_count = new_to_old_gid_list.tail ().first + 1; |
69 | 584 | } |
70 | 1.62k | else |
71 | 1.62k | { |
72 | 6.73k | for (unsigned j = count; j; j--) |
73 | 6.11k | { |
74 | 6.11k | hb_codepoint_t gid = new_to_old_gid_list.arrayZ[j - 1].first; |
75 | 6.11k | hb_codepoint_t old_gid = new_to_old_gid_list.arrayZ[j - 1].second; |
76 | | |
77 | 6.11k | unsigned int v = index_map->map (old_gid); |
78 | 6.11k | if (last_gid == HB_CODEPOINT_INVALID) |
79 | 1.62k | { |
80 | 1.62k | last_val = v; |
81 | 1.62k | last_gid = gid; |
82 | 1.62k | continue; |
83 | 1.62k | } |
84 | 4.49k | if (v != last_val) |
85 | 1.00k | break; |
86 | | |
87 | 3.48k | last_gid = gid; |
88 | 3.48k | } |
89 | | |
90 | 1.62k | if (unlikely (last_gid == (hb_codepoint_t)-1)) return; |
91 | 1.62k | map_count = last_gid + 1; |
92 | 1.62k | } |
93 | | |
94 | 2.20k | for (auto _ : plan->new_to_old_gid_list) |
95 | 9.51k | { |
96 | 9.51k | hb_codepoint_t gid = _.first; |
97 | 9.51k | if (gid >= map_count) break; |
98 | | |
99 | 9.25k | hb_codepoint_t old_gid = _.second; |
100 | 9.25k | unsigned int v = index_map ? index_map->map (old_gid): old_gid; |
101 | 9.25k | unsigned int outer = v >> 16; |
102 | 9.25k | unsigned int inner = v & 0xFFFF; |
103 | 9.25k | outer_map.add (outer); |
104 | 9.25k | if (inner > max_inners[outer]) max_inners[outer] = inner; |
105 | 9.25k | if (outer >= inner_sets.length) return; |
106 | 8.82k | inner_sets[outer]->add (inner); |
107 | 8.82k | } |
108 | 2.20k | } |
109 | | |
110 | | void fini () |
111 | 0 | { |
112 | 0 | max_inners.fini (); |
113 | 0 | output_map.fini (); |
114 | 0 | } |
115 | | |
116 | | void remap (const DeltaSetIndexMap *input_map, |
117 | | const hb_inc_bimap_t &outer_map, |
118 | | const hb_vector_t<hb_inc_bimap_t> &inner_maps, |
119 | | const hb_subset_plan_t *plan) |
120 | 4.15k | { |
121 | 4.15k | outer_bit_count = 1; |
122 | 4.15k | inner_bit_count = 1; |
123 | | |
124 | 10.1k | for (unsigned int i = 0; i < max_inners.length; i++) |
125 | 5.98k | { |
126 | 5.98k | if (inner_maps[i].get_population () == 0) continue; |
127 | 2.47k | unsigned int bit_count = (max_inners[i]==0)? 1: hb_bit_storage (inner_maps[i][max_inners[i]]); |
128 | 2.47k | if (bit_count > inner_bit_count) inner_bit_count = bit_count; |
129 | 2.47k | } |
130 | | |
131 | 4.15k | if (unlikely (!output_map.resize (map_count))) return; |
132 | 4.14k | for (const auto &_ : plan->new_to_old_gid_list) |
133 | 14.5k | { |
134 | 14.5k | hb_codepoint_t new_gid = _.first; |
135 | 14.5k | hb_codepoint_t old_gid = _.second; |
136 | | |
137 | 14.5k | if (unlikely (new_gid >= map_count)) break; |
138 | | |
139 | 12.1k | uint32_t v = input_map? input_map->map (old_gid) : old_gid; |
140 | 12.1k | unsigned outer = v >> 16; |
141 | 12.1k | unsigned new_outer = outer_map[outer]; |
142 | 12.1k | unsigned bit_count = (new_outer == 0) ? 1 : hb_bit_storage (new_outer); |
143 | 12.1k | outer_bit_count = hb_max (bit_count, outer_bit_count); |
144 | | |
145 | 12.1k | output_map.arrayZ[new_gid] = (new_outer << 16) | (inner_maps[outer][v & 0xFFFF]); |
146 | 12.1k | } |
147 | 4.14k | } |
148 | | |
149 | | bool remap_after_instantiation (const hb_subset_plan_t *plan, |
150 | | const hb_map_t& varidx_map) |
151 | 0 | { |
152 | | /* recalculate bit_count after remapping */ |
153 | 0 | outer_bit_count = 1; |
154 | 0 | inner_bit_count = 1; |
155 | |
|
156 | 0 | for (const auto &_ : plan->new_to_old_gid_list) |
157 | 0 | { |
158 | 0 | hb_codepoint_t new_gid = _.first; |
159 | 0 | if (unlikely (new_gid >= map_count)) break; |
160 | | |
161 | 0 | uint32_t v = output_map.arrayZ[new_gid]; |
162 | 0 | uint32_t *new_varidx; |
163 | 0 | if (!varidx_map.has (v, &new_varidx)) |
164 | 0 | return false; |
165 | | |
166 | 0 | output_map.arrayZ[new_gid] = *new_varidx; |
167 | |
|
168 | 0 | unsigned outer = (*new_varidx) >> 16; |
169 | 0 | unsigned bit_count = (outer == 0) ? 1 : hb_bit_storage (outer); |
170 | 0 | outer_bit_count = hb_max (bit_count, outer_bit_count); |
171 | |
|
172 | 0 | unsigned inner = (*new_varidx) & 0xFFFF; |
173 | 0 | bit_count = (inner == 0) ? 1 : hb_bit_storage (inner); |
174 | 0 | inner_bit_count = hb_max (bit_count, inner_bit_count); |
175 | 0 | } |
176 | 0 | return true; |
177 | 0 | } |
178 | | |
179 | 1.47k | unsigned int get_inner_bit_count () const { return inner_bit_count; } |
180 | 1.47k | unsigned int get_width () const { return ((outer_bit_count + inner_bit_count + 7) / 8); } |
181 | 264 | unsigned int get_map_count () const { return map_count; } |
182 | | |
183 | | unsigned int get_size () const |
184 | 0 | { return (map_count? (DeltaSetIndexMap::min_size + get_width () * map_count): 0); } |
185 | | |
186 | 3.97k | bool is_identity () const { return get_output_map ().length == 0; } |
187 | 6.91k | hb_array_t<const uint32_t> get_output_map () const { return output_map.as_array (); } |
188 | | |
189 | | protected: |
190 | | unsigned int map_count; |
191 | | hb_vector_t<unsigned int> max_inners; |
192 | | unsigned int outer_bit_count; |
193 | | unsigned int inner_bit_count; |
194 | | hb_vector_t<uint32_t> output_map; |
195 | | }; |
196 | | |
197 | | struct hvarvvar_subset_plan_t |
198 | | { |
199 | 1.68k | hvarvvar_subset_plan_t() : inner_maps (), index_map_plans () {} |
200 | 1.68k | ~hvarvvar_subset_plan_t() { fini (); } |
201 | | |
202 | | void init (const hb_array_t<const DeltaSetIndexMap *> &index_maps, |
203 | | const ItemVariationStore &_var_store, |
204 | | const hb_subset_plan_t *plan) |
205 | 1.68k | { |
206 | 1.68k | index_map_plans.resize (index_maps.length); |
207 | | |
208 | 1.68k | var_store = &_var_store; |
209 | 1.68k | inner_sets.resize (var_store->get_sub_table_count ()); |
210 | 5.94k | for (unsigned int i = 0; i < inner_sets.length; i++) |
211 | 4.25k | inner_sets[i] = hb_set_create (); |
212 | 1.68k | adv_set = hb_set_create (); |
213 | | |
214 | 1.68k | inner_maps.resize (var_store->get_sub_table_count ()); |
215 | | |
216 | 1.68k | if (unlikely (!index_map_plans.length || !inner_sets.length || !inner_maps.length)) return; |
217 | | |
218 | 1.33k | bool retain_adv_map = false; |
219 | 1.33k | index_map_plans[0].init (index_maps[0], outer_map, inner_sets, plan, false); |
220 | 1.33k | if (!index_maps[0]) |
221 | 584 | { |
222 | 584 | retain_adv_map = plan->flags & HB_SUBSET_FLAGS_RETAIN_GIDS; |
223 | 584 | outer_map.add (0); |
224 | 584 | for (hb_codepoint_t old_gid : plan->glyphset()->iter()) |
225 | 2.91k | inner_sets[0]->add (old_gid); |
226 | 584 | hb_set_union (adv_set, inner_sets[0]); |
227 | 584 | } |
228 | | |
229 | 4.15k | for (unsigned int i = 1; i < index_maps.length; i++) |
230 | 2.82k | index_map_plans[i].init (index_maps[i], outer_map, inner_sets, plan); |
231 | | |
232 | 1.33k | outer_map.sort (); |
233 | | |
234 | 1.33k | if (retain_adv_map) |
235 | 205 | { |
236 | 205 | for (const auto &_ : plan->new_to_old_gid_list) |
237 | 764 | { |
238 | 764 | hb_codepoint_t old_gid = _.second; |
239 | 764 | inner_maps[0].add (old_gid); |
240 | 764 | } |
241 | 205 | } |
242 | 1.13k | else |
243 | 1.13k | { |
244 | 1.13k | inner_maps[0].add_set (adv_set); |
245 | 1.13k | hb_set_subtract (inner_sets[0], adv_set); |
246 | 1.13k | inner_maps[0].add_set (inner_sets[0]); |
247 | 1.13k | } |
248 | | |
249 | 4.24k | for (unsigned int i = 1; i < inner_maps.length; i++) |
250 | 2.90k | inner_maps[i].add_set (inner_sets[i]); |
251 | | |
252 | 5.49k | for (unsigned int i = 0; i < index_maps.length; i++) |
253 | 4.15k | index_map_plans[i].remap (index_maps[i], outer_map, inner_maps, plan); |
254 | 1.33k | } |
255 | | |
256 | | /* remap */ |
257 | | bool remap_index_map_plans (const hb_subset_plan_t *plan, |
258 | | const hb_map_t& varidx_map) |
259 | 0 | { |
260 | 0 | for (unsigned i = 0; i < index_map_plans.length; i++) |
261 | 0 | if (!index_map_plans[i].remap_after_instantiation (plan, varidx_map)) |
262 | 0 | return false; |
263 | 0 | return true; |
264 | 0 | } |
265 | | |
266 | | void fini () |
267 | 1.68k | { |
268 | 5.94k | for (unsigned int i = 0; i < inner_sets.length; i++) |
269 | 4.25k | hb_set_destroy (inner_sets[i]); |
270 | 1.68k | hb_set_destroy (adv_set); |
271 | 1.68k | inner_maps.fini (); |
272 | 1.68k | index_map_plans.fini (); |
273 | 1.68k | } |
274 | | |
275 | | hb_inc_bimap_t outer_map; |
276 | | hb_vector_t<hb_inc_bimap_t> inner_maps; |
277 | | hb_vector_t<index_map_subset_plan_t> index_map_plans; |
278 | | const ItemVariationStore *var_store; |
279 | | |
280 | | protected: |
281 | | hb_vector_t<hb_set_t *> inner_sets; |
282 | | hb_set_t *adv_set; |
283 | | }; |
284 | | |
285 | | /* |
286 | | * HVAR -- Horizontal Metrics Variations |
287 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/hvar |
288 | | * VVAR -- Vertical Metrics Variations |
289 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/vvar |
290 | | */ |
291 | | #define HB_OT_TAG_HVAR HB_TAG('H','V','A','R') |
292 | | #define HB_OT_TAG_VVAR HB_TAG('V','V','A','R') |
293 | | |
294 | | struct HVARVVAR |
295 | | { |
296 | | static constexpr hb_tag_t HVARTag = HB_OT_TAG_HVAR; |
297 | | static constexpr hb_tag_t VVARTag = HB_OT_TAG_VVAR; |
298 | | |
299 | 0 | bool has_data () const { return version.major != 0; } |
300 | | |
301 | | bool sanitize (hb_sanitize_context_t *c) const |
302 | 7.21k | { |
303 | 7.21k | TRACE_SANITIZE (this); |
304 | 7.21k | return_trace (version.sanitize (c) && |
305 | 7.21k | hb_barrier () && |
306 | 7.21k | likely (version.major == 1) && |
307 | 7.21k | varStore.sanitize (c, this) && |
308 | 7.21k | advMap.sanitize (c, this) && |
309 | 7.21k | lsbMap.sanitize (c, this) && |
310 | 7.21k | rsbMap.sanitize (c, this)); |
311 | 7.21k | } |
312 | | |
313 | | const ItemVariationStore& get_var_store () const |
314 | 0 | { return this+varStore; } |
315 | | |
316 | | void listup_index_maps (hb_vector_t<const DeltaSetIndexMap *> &index_maps) const |
317 | 1.68k | { |
318 | 1.68k | if (advMap) index_maps.push (&(this+advMap)); |
319 | 816 | else index_maps.push (nullptr); |
320 | | |
321 | 1.68k | if (lsbMap) index_maps.push (&(this+lsbMap)); |
322 | 923 | else index_maps.push (nullptr); |
323 | | |
324 | 1.68k | if (rsbMap) index_maps.push (&(this+rsbMap)); |
325 | 1.11k | else index_maps.push (nullptr); |
326 | 1.68k | } |
327 | | |
328 | | bool serialize_index_maps (hb_serialize_context_t *c, |
329 | | const hb_array_t<index_map_subset_plan_t> &im_plans) |
330 | 1.41k | { |
331 | 1.41k | TRACE_SERIALIZE (this); |
332 | 1.41k | if (im_plans[index_map_subset_plan_t::ADV_INDEX].is_identity ()) |
333 | 354 | advMap = 0; |
334 | 1.06k | else if (unlikely (!advMap.serialize_serialize (c, im_plans[index_map_subset_plan_t::ADV_INDEX]))) |
335 | 104 | return_trace (false); |
336 | 1.31k | if (im_plans[index_map_subset_plan_t::LSB_INDEX].is_identity ()) |
337 | 1.12k | lsbMap = 0; |
338 | 192 | else if (unlikely (!lsbMap.serialize_serialize (c, im_plans[index_map_subset_plan_t::LSB_INDEX]))) |
339 | 74 | return_trace (false); |
340 | 1.24k | if (im_plans[index_map_subset_plan_t::RSB_INDEX].is_identity ()) |
341 | 1.10k | rsbMap = 0; |
342 | 136 | else if (unlikely (!rsbMap.serialize_serialize (c, im_plans[index_map_subset_plan_t::RSB_INDEX]))) |
343 | 36 | return_trace (false); |
344 | | |
345 | 1.24k | return_trace (true); |
346 | 1.24k | } |
347 | | |
348 | | template <typename T> |
349 | | bool _subset (hb_subset_context_t *c) const |
350 | 1.68k | { |
351 | 1.68k | TRACE_SUBSET (this); |
352 | 1.68k | if (c->plan->all_axes_pinned) |
353 | 0 | return_trace (false); |
354 | | |
355 | 1.68k | hvarvvar_subset_plan_t hvar_plan; |
356 | 1.68k | hb_vector_t<const DeltaSetIndexMap *> |
357 | 1.68k | index_maps; |
358 | | |
359 | 1.68k | ((T*)this)->listup_index_maps (index_maps); |
360 | 1.68k | hvar_plan.init (index_maps.as_array (), this+varStore, c->plan); |
361 | | |
362 | 1.68k | T *out = c->serializer->allocate_min<T> (); |
363 | 1.68k | if (unlikely (!out)) return_trace (false); |
364 | | |
365 | 1.68k | out->version.major = 1; |
366 | 1.68k | out->version.minor = 0; |
367 | | |
368 | 1.68k | if (c->plan->normalized_coords) |
369 | 0 | { |
370 | 0 | item_variations_t item_vars; |
371 | 0 | if (!item_vars.instantiate (this+varStore, c->plan, |
372 | 0 | advMap == 0 ? false : true, |
373 | 0 | false, /* use_no_variation_idx = false */ |
374 | 0 | hvar_plan.inner_maps.as_array ())) |
375 | 0 | return_trace (false); |
376 | | |
377 | 0 | if (!out->varStore.serialize_serialize (c->serializer, |
378 | 0 | item_vars.has_long_word (), |
379 | 0 | c->plan->axis_tags, |
380 | 0 | item_vars.get_region_list (), |
381 | 0 | item_vars.get_vardata_encodings ())) |
382 | 0 | return_trace (false); |
383 | | |
384 | | /* if varstore is optimized, remap output_map */ |
385 | 0 | if (advMap) |
386 | 0 | { |
387 | 0 | if (!hvar_plan.remap_index_map_plans (c->plan, item_vars.get_varidx_map ())) |
388 | 0 | return_trace (false); |
389 | 0 | } |
390 | 0 | } |
391 | 1.68k | else |
392 | 1.68k | { |
393 | 1.68k | if (unlikely (!out->varStore |
394 | 1.68k | .serialize_serialize (c->serializer, |
395 | 1.68k | hvar_plan.var_store, |
396 | 1.68k | hvar_plan.inner_maps.as_array ()))) |
397 | 268 | return_trace (false); |
398 | 1.68k | } |
399 | | |
400 | 1.68k | return_trace (out->T::serialize_index_maps (c->serializer, |
401 | 1.68k | hvar_plan.index_map_plans.as_array ())); |
402 | 1.68k | } bool OT::HVARVVAR::_subset<OT::HVAR>(hb_subset_context_t*) const Line | Count | Source | 350 | 1.41k | { | 351 | 1.41k | TRACE_SUBSET (this); | 352 | 1.41k | if (c->plan->all_axes_pinned) | 353 | 0 | return_trace (false); | 354 | | | 355 | 1.41k | hvarvvar_subset_plan_t hvar_plan; | 356 | 1.41k | hb_vector_t<const DeltaSetIndexMap *> | 357 | 1.41k | index_maps; | 358 | | | 359 | 1.41k | ((T*)this)->listup_index_maps (index_maps); | 360 | 1.41k | hvar_plan.init (index_maps.as_array (), this+varStore, c->plan); | 361 | | | 362 | 1.41k | T *out = c->serializer->allocate_min<T> (); | 363 | 1.41k | if (unlikely (!out)) return_trace (false); | 364 | | | 365 | 1.41k | out->version.major = 1; | 366 | 1.41k | out->version.minor = 0; | 367 | | | 368 | 1.41k | if (c->plan->normalized_coords) | 369 | 0 | { | 370 | 0 | item_variations_t item_vars; | 371 | 0 | if (!item_vars.instantiate (this+varStore, c->plan, | 372 | 0 | advMap == 0 ? false : true, | 373 | 0 | false, /* use_no_variation_idx = false */ | 374 | 0 | hvar_plan.inner_maps.as_array ())) | 375 | 0 | return_trace (false); | 376 | | | 377 | 0 | if (!out->varStore.serialize_serialize (c->serializer, | 378 | 0 | item_vars.has_long_word (), | 379 | 0 | c->plan->axis_tags, | 380 | 0 | item_vars.get_region_list (), | 381 | 0 | item_vars.get_vardata_encodings ())) | 382 | 0 | return_trace (false); | 383 | | | 384 | | /* if varstore is optimized, remap output_map */ | 385 | 0 | if (advMap) | 386 | 0 | { | 387 | 0 | if (!hvar_plan.remap_index_map_plans (c->plan, item_vars.get_varidx_map ())) | 388 | 0 | return_trace (false); | 389 | 0 | } | 390 | 0 | } | 391 | 1.41k | else | 392 | 1.41k | { | 393 | 1.41k | if (unlikely (!out->varStore | 394 | 1.41k | .serialize_serialize (c->serializer, | 395 | 1.41k | hvar_plan.var_store, | 396 | 1.41k | hvar_plan.inner_maps.as_array ()))) | 397 | 262 | return_trace (false); | 398 | 1.41k | } | 399 | | | 400 | 1.15k | return_trace (out->T::serialize_index_maps (c->serializer, | 401 | 1.41k | hvar_plan.index_map_plans.as_array ())); | 402 | 1.41k | } |
bool OT::HVARVVAR::_subset<OT::VVAR>(hb_subset_context_t*) const Line | Count | Source | 350 | 275 | { | 351 | 275 | TRACE_SUBSET (this); | 352 | 275 | if (c->plan->all_axes_pinned) | 353 | 0 | return_trace (false); | 354 | | | 355 | 275 | hvarvvar_subset_plan_t hvar_plan; | 356 | 275 | hb_vector_t<const DeltaSetIndexMap *> | 357 | 275 | index_maps; | 358 | | | 359 | 275 | ((T*)this)->listup_index_maps (index_maps); | 360 | 275 | hvar_plan.init (index_maps.as_array (), this+varStore, c->plan); | 361 | | | 362 | 275 | T *out = c->serializer->allocate_min<T> (); | 363 | 275 | if (unlikely (!out)) return_trace (false); | 364 | | | 365 | 275 | out->version.major = 1; | 366 | 275 | out->version.minor = 0; | 367 | | | 368 | 275 | if (c->plan->normalized_coords) | 369 | 0 | { | 370 | 0 | item_variations_t item_vars; | 371 | 0 | if (!item_vars.instantiate (this+varStore, c->plan, | 372 | 0 | advMap == 0 ? false : true, | 373 | 0 | false, /* use_no_variation_idx = false */ | 374 | 0 | hvar_plan.inner_maps.as_array ())) | 375 | 0 | return_trace (false); | 376 | | | 377 | 0 | if (!out->varStore.serialize_serialize (c->serializer, | 378 | 0 | item_vars.has_long_word (), | 379 | 0 | c->plan->axis_tags, | 380 | 0 | item_vars.get_region_list (), | 381 | 0 | item_vars.get_vardata_encodings ())) | 382 | 0 | return_trace (false); | 383 | | | 384 | | /* if varstore is optimized, remap output_map */ | 385 | 0 | if (advMap) | 386 | 0 | { | 387 | 0 | if (!hvar_plan.remap_index_map_plans (c->plan, item_vars.get_varidx_map ())) | 388 | 0 | return_trace (false); | 389 | 0 | } | 390 | 0 | } | 391 | 275 | else | 392 | 275 | { | 393 | 275 | if (unlikely (!out->varStore | 394 | 275 | .serialize_serialize (c->serializer, | 395 | 275 | hvar_plan.var_store, | 396 | 275 | hvar_plan.inner_maps.as_array ()))) | 397 | 6 | return_trace (false); | 398 | 275 | } | 399 | | | 400 | 269 | return_trace (out->T::serialize_index_maps (c->serializer, | 401 | 275 | hvar_plan.index_map_plans.as_array ())); | 402 | 275 | } |
|
403 | | |
404 | | HB_ALWAYS_INLINE |
405 | | float get_advance_delta_unscaled (hb_codepoint_t glyph, |
406 | | const int *coords, unsigned int coord_count, |
407 | | hb_scalar_cache_t *store_cache = nullptr) const |
408 | 0 | { |
409 | 0 | uint32_t varidx = (this+advMap).map (glyph); |
410 | 0 | return (this+varStore).get_delta (varidx, |
411 | 0 | coords, coord_count, |
412 | 0 | store_cache); |
413 | 0 | } |
414 | | |
415 | | public: |
416 | | FixedVersion<>version; /* Version of the metrics variation table |
417 | | * initially set to 0x00010000u */ |
418 | | Offset32To<ItemVariationStore> |
419 | | varStore; /* Offset to item variation store table. */ |
420 | | Offset32To<DeltaSetIndexMap> |
421 | | advMap; /* Offset to advance var-idx mapping. */ |
422 | | Offset32To<DeltaSetIndexMap> |
423 | | lsbMap; /* Offset to lsb/tsb var-idx mapping. */ |
424 | | Offset32To<DeltaSetIndexMap> |
425 | | rsbMap; /* Offset to rsb/bsb var-idx mapping. */ |
426 | | |
427 | | public: |
428 | | DEFINE_SIZE_STATIC (20); |
429 | | }; |
430 | | |
431 | | struct HVAR : HVARVVAR { |
432 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_HVAR; |
433 | 1.41k | bool subset (hb_subset_context_t *c) const { return HVARVVAR::_subset<HVAR> (c); } |
434 | | }; |
435 | | struct VVAR : HVARVVAR { |
436 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_VVAR; |
437 | | |
438 | | bool sanitize (hb_sanitize_context_t *c) const |
439 | 1.57k | { |
440 | 1.57k | TRACE_SANITIZE (this); |
441 | 1.57k | return_trace (static_cast<const HVARVVAR *> (this)->sanitize (c) && |
442 | 1.57k | vorgMap.sanitize (c, this)); |
443 | 1.57k | } |
444 | | |
445 | | void listup_index_maps (hb_vector_t<const DeltaSetIndexMap *> &index_maps) const |
446 | 275 | { |
447 | 275 | HVARVVAR::listup_index_maps (index_maps); |
448 | 275 | if (vorgMap) index_maps.push (&(this+vorgMap)); |
449 | 158 | else index_maps.push (nullptr); |
450 | 275 | } |
451 | | |
452 | | bool serialize_index_maps (hb_serialize_context_t *c, |
453 | | const hb_array_t<index_map_subset_plan_t> &im_plans) |
454 | 269 | { |
455 | 269 | TRACE_SERIALIZE (this); |
456 | 269 | if (unlikely (!HVARVVAR::serialize_index_maps (c, im_plans))) |
457 | 5 | return_trace (false); |
458 | 264 | if (!im_plans[index_map_subset_plan_t::VORG_INDEX].get_map_count ()) |
459 | 185 | vorgMap = 0; |
460 | 79 | else if (unlikely (!vorgMap.serialize_serialize (c, im_plans[index_map_subset_plan_t::VORG_INDEX]))) |
461 | 2 | return_trace (false); |
462 | | |
463 | 264 | return_trace (true); |
464 | 264 | } |
465 | | |
466 | 275 | bool subset (hb_subset_context_t *c) const { return HVARVVAR::_subset<VVAR> (c); } |
467 | | |
468 | | HB_ALWAYS_INLINE |
469 | | float get_vorg_delta_unscaled (hb_codepoint_t glyph, |
470 | | const int *coords, unsigned int coord_count, |
471 | | hb_scalar_cache_t *store_cache = nullptr) const |
472 | 0 | { |
473 | 0 | if (!vorgMap) return 0.f; |
474 | 0 | uint32_t varidx = (this+vorgMap).map (glyph); |
475 | 0 | return (this+varStore).get_delta (varidx, |
476 | 0 | coords, coord_count, |
477 | 0 | store_cache); |
478 | 0 | } |
479 | | |
480 | | protected: |
481 | | Offset32To<DeltaSetIndexMap> |
482 | | vorgMap; /* Offset to vertical-origin var-idx mapping. */ |
483 | | |
484 | | public: |
485 | | DEFINE_SIZE_STATIC (24); |
486 | | }; |
487 | | |
488 | | } /* namespace OT */ |
489 | | |
490 | | |
491 | | #endif /* HB_OT_VAR_HVAR_TABLE_HH */ |