Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/workdir/UnpackedTarball/harfbuzz/src/hb-ot-var-gvar-table.hh
Line
Count
Source
1
/*
2
 * Copyright © 2019  Adobe Inc.
3
 * Copyright © 2019  Ebrahim Byagowi
4
 *
5
 *  This is part of HarfBuzz, a text shaping library.
6
 *
7
 * Permission is hereby granted, without written agreement and without
8
 * license or royalty fees, to use, copy, modify, and distribute this
9
 * software and its documentation for any purpose, provided that the
10
 * above copyright notice and the following two paragraphs appear in
11
 * all copies of this software.
12
 *
13
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17
 * DAMAGE.
18
 *
19
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24
 *
25
 * Adobe Author(s): Michiharu Ariza
26
 */
27
28
#ifndef HB_OT_VAR_GVAR_TABLE_HH
29
#define HB_OT_VAR_GVAR_TABLE_HH
30
31
#include "hb-decycler.hh"
32
#include "hb-open-type.hh"
33
#include "hb-ot-var-common.hh"
34
35
/*
36
 * gvar -- Glyph Variation Table
37
 * https://docs.microsoft.com/en-us/typography/opentype/spec/gvar
38
 */
39
#define HB_OT_TAG_gvar HB_TAG('g','v','a','r')
40
#define HB_OT_TAG_GVAR HB_TAG('G','V','A','R')
41
42
struct hb_glyf_scratch_t
43
{
44
  // glyf
45
  contour_point_vector_t all_points;
46
  contour_point_vector_t comp_points;
47
  hb_decycler_t decycler;
48
49
  // gvar
50
  contour_point_vector_t orig_points;
51
  hb_vector_t<int> x_deltas;
52
  hb_vector_t<int> y_deltas;
53
  contour_point_vector_t deltas;
54
  hb_vector_t<unsigned int> shared_indices;
55
  hb_vector_t<unsigned int> private_indices;
56
};
57
58
namespace OT {
59
60
template <typename OffsetType>
61
struct glyph_variations_t
62
{
63
  // TODO: Move tuple_variations_t to outside of TupleVariationData
64
  using tuple_variations_t = typename TupleVariationData<OffsetType>::tuple_variations_t;
65
  using GlyphVariationData = TupleVariationData<OffsetType>;
66
67
  hb_vector_t<tuple_variations_t> glyph_variations;
68
69
  hb_vector_t<F2DOT14> compiled_shared_tuples;
70
  private:
71
  unsigned shared_tuples_count = 0;
72
73
  /* shared coords-> index map after instantiation */
74
  hb_hashmap_t<const hb_vector_t<F2DOT14>*, unsigned> shared_tuples_idx_map;
75
76
  hb_alloc_pool_t pool;
77
78
  public:
79
  unsigned compiled_shared_tuples_count () const
80
0
  { return shared_tuples_count; }
81
82
  unsigned compiled_byte_size () const
83
0
  {
84
0
    unsigned byte_size = 0;
85
0
    for (const auto& _ : glyph_variations)
86
0
      byte_size += _.get_compiled_byte_size ();
87
88
0
    return byte_size;
89
0
  }
90
91
  bool create_from_glyphs_var_data (unsigned axis_count,
92
                                    const hb_array_t<const F2DOT14> shared_tuples,
93
                                    const hb_subset_plan_t *plan,
94
                                    const hb_hashmap_t<hb_codepoint_t, hb_bytes_t>& new_gid_var_data_map)
95
0
  {
96
0
    if (unlikely (!glyph_variations.alloc_exact (plan->new_to_old_gid_list.length)))
97
0
      return false;
98
99
0
    auto it = hb_iter (plan->new_to_old_gid_list);
100
0
    for (auto &_ : it)
101
0
    {
102
0
      hb_codepoint_t new_gid = _.first;
103
0
      contour_point_vector_t *all_contour_points;
104
0
      if (!new_gid_var_data_map.has (new_gid) ||
105
0
          !plan->new_gid_contour_points_map.has (new_gid, &all_contour_points))
106
0
        return false;
107
0
      hb_bytes_t var_data = new_gid_var_data_map.get (new_gid);
108
109
0
      const GlyphVariationData* p = reinterpret_cast<const GlyphVariationData*> (var_data.arrayZ);
110
0
      typename GlyphVariationData::tuple_iterator_t iterator;
111
0
      tuple_variations_t tuple_vars;
112
113
0
      hb_vector_t<unsigned> shared_indices;
114
115
      /* in case variation data is empty, push an empty struct into the vector,
116
       * keep the vector in sync with the new_to_old_gid_list */
117
0
      if (!var_data || ! p->has_data () || !all_contour_points->length ||
118
0
          !GlyphVariationData::get_tuple_iterator (var_data, axis_count,
119
0
                                                   var_data.arrayZ,
120
0
                                                   shared_indices, &iterator))
121
0
      {
122
0
        glyph_variations.push (std::move (tuple_vars));
123
0
        continue;
124
0
      }
125
126
0
      bool is_composite_glyph = false;
127
0
      is_composite_glyph = plan->composite_new_gids.has (new_gid);
128
129
0
      if (!p->decompile_tuple_variations (all_contour_points->length, true /* is_gvar */,
130
0
                                          iterator, &(plan->axes_old_index_tag_map),
131
0
                                          shared_indices, shared_tuples,
132
0
                                          tuple_vars, /* OUT */
133
0
            &pool,
134
0
                                          is_composite_glyph))
135
0
        return false;
136
0
      glyph_variations.push (std::move (tuple_vars));
137
0
    }
138
0
    return !glyph_variations.in_error () && glyph_variations.length == plan->new_to_old_gid_list.length;
139
0
  }
140
141
  bool instantiate (const hb_subset_plan_t *plan)
142
0
  {
143
0
    unsigned count = plan->new_to_old_gid_list.length;
144
0
    bool iup_optimize = false;
145
0
    optimize_scratch_t scratch;
146
0
    iup_optimize = plan->flags & HB_SUBSET_FLAGS_OPTIMIZE_IUP_DELTAS;
147
0
    for (unsigned i = 0; i < count; i++)
148
0
    {
149
0
      hb_codepoint_t new_gid = plan->new_to_old_gid_list[i].first;
150
0
      contour_point_vector_t *all_points;
151
0
      if (!plan->new_gid_contour_points_map.has (new_gid, &all_points))
152
0
        return false;
153
      /* avar2 partial instancing: cull unreachable tuples. */
154
0
      if (plan->has_avar2 && plan->avar2_reachable_ranges.get_population ())
155
0
  glyph_variations[i].cull_unreachable (plan->avar2_reachable_ranges);
156
0
      if (!glyph_variations[i].instantiate (plan->axes_location, plan->axes_triple_distances, scratch, &pool, all_points, iup_optimize))
157
0
        return false;
158
0
    }
159
0
    return true;
160
0
  }
161
162
  bool compile_bytes (const hb_map_t& axes_index_map,
163
                      const hb_map_t& axes_old_index_tag_map)
164
0
  {
165
0
    if (!compile_shared_tuples (axes_index_map, axes_old_index_tag_map))
166
0
      return false;
167
0
    for (tuple_variations_t& vars: glyph_variations)
168
0
      if (!vars.compile_bytes (axes_index_map, axes_old_index_tag_map,
169
0
                               true, /* use shared points*/
170
0
                               true,
171
0
                               &shared_tuples_idx_map,
172
0
             &pool))
173
0
        return false;
174
175
0
    return true;
176
0
  }
177
178
  bool compile_shared_tuples (const hb_map_t& axes_index_map,
179
                              const hb_map_t& axes_old_index_tag_map)
180
0
  {
181
    /* key is pointer to compiled_peak_coords inside each tuple, hashing
182
     * function will always deref pointers first */
183
0
    hb_hashmap_t<const hb_vector_t<F2DOT14>*, unsigned> coords_count_map;
184
185
    /* count the num of shared coords */
186
0
    for (tuple_variations_t& vars: glyph_variations)
187
0
    {
188
0
      for (tuple_delta_t& var : vars.tuple_vars)
189
0
      {
190
0
        if (!var.compile_coords (axes_index_map, axes_old_index_tag_map, &pool))
191
0
          return false;
192
0
        unsigned *count;
193
0
  unsigned hash = hb_hash (&var.compiled_peak_coords);
194
0
        if (coords_count_map.has_with_hash (&(var.compiled_peak_coords), hash, &count))
195
0
    (*count)++;
196
0
        else
197
0
          coords_count_map.set_with_hash (&(var.compiled_peak_coords), hash, 1);
198
0
      }
199
0
    }
200
201
0
    if (!coords_count_map || coords_count_map.in_error ())
202
0
      return false;
203
204
    /* add only those coords that are used more than once into the vector and sort */
205
0
    hb_vector_t<hb_pair_t<const hb_vector_t<F2DOT14>*, unsigned>> shared_coords {
206
0
      + hb_iter (coords_count_map)
207
0
      | hb_filter ([] (const hb_pair_t<const hb_vector_t<F2DOT14>*, unsigned>& p) { return p.second > 1; })
208
0
    };
209
0
    if (unlikely (shared_coords.in_error ())) return false;
210
211
    /* no shared tuples: no coords are used more than once */
212
0
    if (!shared_coords) return true;
213
    /* sorting based on the coords frequency first (high to low), then compare
214
     * the coords bytes */
215
0
    shared_coords.qsort (_cmp_coords);
216
217
    /* build shared_coords->idx map and shared tuples byte array */
218
219
0
    shared_tuples_count = hb_min (0xFFFu + 1, shared_coords.length);
220
0
    unsigned len = shared_tuples_count * (shared_coords[0].first->length);
221
0
    if (unlikely (!compiled_shared_tuples.alloc (len)))
222
0
      return false;
223
224
0
    for (unsigned i = 0; i < shared_tuples_count; i++)
225
0
    {
226
0
      shared_tuples_idx_map.set (shared_coords[i].first, i);
227
      /* add a concat() in hb_vector_t? */
228
0
      for (auto c : shared_coords[i].first->iter ())
229
0
        compiled_shared_tuples.push (c);
230
0
    }
231
232
0
    return true;
233
0
  }
234
235
  static int _cmp_coords (const void *pa, const void *pb)
236
0
  {
237
0
    const hb_pair_t<hb_vector_t<F2DOT14> *, unsigned> *a = (const hb_pair_t<hb_vector_t<F2DOT14> *, unsigned> *) pa;
238
0
    const hb_pair_t<hb_vector_t<F2DOT14> *, unsigned> *b = (const hb_pair_t<hb_vector_t<F2DOT14> *, unsigned> *) pb;
239
240
0
    if (a->second != b->second)
241
0
      return b->second - a->second; // high to low
242
243
0
    return b->first->as_array().cmp (a->first->as_array ());
244
0
  }
245
246
  template<typename Iterator,
247
           hb_requires (hb_is_iterator (Iterator))>
248
  bool serialize_glyph_var_data (hb_serialize_context_t *c,
249
                                 Iterator it,
250
                                 bool long_offset,
251
                                 unsigned num_glyphs,
252
                                 char* glyph_var_data_offsets /* OUT: glyph var data offsets array */) const
253
0
  {
254
0
    TRACE_SERIALIZE (this);
255
256
0
    if (long_offset)
257
0
    {
258
0
      ((HBUINT32 *) glyph_var_data_offsets)[0] = 0;
259
0
      glyph_var_data_offsets += 4;
260
0
    }
261
0
    else
262
0
    {
263
0
      ((HBUINT16 *) glyph_var_data_offsets)[0] = 0;
264
0
      glyph_var_data_offsets += 2;
265
0
    }
266
0
    unsigned glyph_offset = 0;
267
0
    hb_codepoint_t last_gid = 0;
268
0
    unsigned idx = 0;
269
270
0
    GlyphVariationData* cur_glyph = c->start_embed<GlyphVariationData> ();
271
0
    if (!cur_glyph) return_trace (false);
272
0
    for (auto &_ : it)
273
0
    {
274
0
      hb_codepoint_t gid = _.first;
275
0
      if (long_offset)
276
0
        for (; last_gid < gid; last_gid++)
277
0
          ((HBUINT32 *) glyph_var_data_offsets)[last_gid] = glyph_offset;
278
0
      else
279
0
        for (; last_gid < gid; last_gid++)
280
0
          ((HBUINT16 *) glyph_var_data_offsets)[last_gid] = glyph_offset / 2;
281
282
0
      if (idx >= glyph_variations.length) return_trace (false);
283
0
      if (!cur_glyph->serialize (c, true, glyph_variations[idx])) return_trace (false);
284
0
      GlyphVariationData* next_glyph = c->start_embed<GlyphVariationData> ();
285
0
      glyph_offset += (char *) next_glyph - (char *) cur_glyph;
286
287
0
      if (long_offset)
288
0
        ((HBUINT32 *) glyph_var_data_offsets)[gid] = glyph_offset;
289
0
      else
290
0
        ((HBUINT16 *) glyph_var_data_offsets)[gid] = glyph_offset / 2;
291
292
0
      last_gid++;
293
0
      idx++;
294
0
      cur_glyph = next_glyph;
295
0
    }
296
297
0
    if (long_offset)
298
0
      for (; last_gid < num_glyphs; last_gid++)
299
0
        ((HBUINT32 *) glyph_var_data_offsets)[last_gid] = glyph_offset;
300
0
    else
301
0
      for (; last_gid < num_glyphs; last_gid++)
302
0
        ((HBUINT16 *) glyph_var_data_offsets)[last_gid] = glyph_offset / 2;
303
0
    return_trace (true);
304
0
  }
305
};
306
307
template <typename GidOffsetType, unsigned TableTag>
308
struct gvar_GVAR
309
{
310
  static constexpr hb_tag_t tableTag = TableTag;
311
312
  using GlyphVariationData = TupleVariationData<GidOffsetType>;
313
314
0
  bool has_data () const { return version.to_int () != 0; }
315
316
  bool sanitize_shallow (hb_sanitize_context_t *c) const
317
0
  {
318
0
    TRACE_SANITIZE (this);
319
0
    return_trace (c->check_struct (this) &&
320
0
      hb_barrier () &&
321
0
      (version.major == 1) &&
322
0
      sharedTuples.sanitize (c, this, axisCount * sharedTupleCount) &&
323
0
      (is_long_offset () ?
324
0
         c->check_array (get_long_offset_array (), c->get_num_glyphs () + 1) :
325
0
         c->check_array (get_short_offset_array (), c->get_num_glyphs () + 1)));
326
0
  }
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned short, 2u>, 1735811442u>::sanitize_shallow(hb_sanitize_context_t*) const
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned int, 3u>, 1196835154u>::sanitize_shallow(hb_sanitize_context_t*) const
327
328
  /* GlyphVariationData not sanitized here; must be checked while accessing each glyph variation data */
329
  bool sanitize (hb_sanitize_context_t *c) const
330
0
  { return sanitize_shallow (c); }
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned short, 2u>, 1735811442u>::sanitize(hb_sanitize_context_t*) const
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned int, 3u>, 1196835154u>::sanitize(hb_sanitize_context_t*) const
331
332
  bool decompile_glyph_variations (hb_subset_context_t *c,
333
                                   glyph_variations_t<GidOffsetType>& glyph_vars /* OUT */) const
334
0
  {
335
0
    hb_hashmap_t<hb_codepoint_t, hb_bytes_t> new_gid_var_data_map;
336
0
    auto it = hb_iter (c->plan->new_to_old_gid_list);
337
0
    if (it->first == 0 && !(c->plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE))
338
0
    {
339
0
      new_gid_var_data_map.set (0, hb_bytes_t ());
340
0
      it++;
341
0
    }
342
343
0
    for (auto &_ : it)
344
0
    {
345
0
      hb_codepoint_t new_gid = _.first;
346
0
      hb_codepoint_t old_gid = _.second;
347
0
      hb_bytes_t var_data_bytes = get_glyph_var_data_bytes (c->source_blob, glyphCountX, old_gid);
348
0
      new_gid_var_data_map.set (new_gid, var_data_bytes);
349
0
    }
350
351
0
    if (new_gid_var_data_map.in_error ()) return false;
352
353
0
    hb_array_t<const F2DOT14> shared_tuples = (this+sharedTuples).as_array ((unsigned) sharedTupleCount * (unsigned) axisCount);
354
0
    return glyph_vars.create_from_glyphs_var_data (axisCount, shared_tuples, c->plan, new_gid_var_data_map);
355
0
  }
356
357
  template<typename Iterator,
358
           hb_requires (hb_is_iterator (Iterator))>
359
  bool serialize (hb_serialize_context_t *c,
360
                  const glyph_variations_t<GidOffsetType>& glyph_vars,
361
                  Iterator it,
362
                  unsigned axis_count,
363
                  unsigned num_glyphs,
364
                  bool force_long_offsets) const
365
0
  {
366
0
    TRACE_SERIALIZE (this);
367
0
    gvar_GVAR *out = c->allocate_min<gvar_GVAR> ();
368
0
    if (unlikely (!out)) return_trace (false);
369
370
0
    out->version.major = 1;
371
0
    out->version.minor = 0;
372
0
    out->axisCount = axis_count;
373
0
    out->glyphCountX = hb_min (0xFFFFu, num_glyphs);
374
375
0
    unsigned glyph_var_data_size = glyph_vars.compiled_byte_size ();
376
    /* According to the spec: If the short format (Offset16) is used for offsets,
377
     * the value stored is the offset divided by 2, so the maximum data size should
378
     * be 2 * 0xFFFFu, which is 0x1FFFEu */
379
0
    bool long_offset = glyph_var_data_size > 0x1FFFEu || force_long_offsets;
380
0
    out->flags = long_offset ? 1 : 0;
381
382
0
    unsigned glyph_var_data_offsets_size = (long_offset ? 4 : 2) * (num_glyphs + 1);
383
0
    HBUINT8 *glyph_var_data_offsets = c->allocate_size<HBUINT8> (glyph_var_data_offsets_size, false);
384
0
    if (!glyph_var_data_offsets) return_trace (false);
385
386
    /* shared tuples */
387
0
    unsigned shared_tuple_count = glyph_vars.compiled_shared_tuples_count ();
388
0
    out->sharedTupleCount = shared_tuple_count;
389
390
0
    if (!shared_tuple_count)
391
0
      out->sharedTuples = (char *) glyph_var_data_offsets + glyph_var_data_offsets_size - (char *) out;
392
0
    else
393
0
    {
394
0
      hb_array_t<const F2DOT14> shared_tuples = glyph_vars.compiled_shared_tuples.as_array ().copy (c);
395
0
      if (!shared_tuples.arrayZ) return_trace (false);
396
0
      out->sharedTuples = (const char *) shared_tuples.arrayZ - (char *) out;
397
0
    }
398
399
0
    char *glyph_var_data = c->start_embed<char> ();
400
0
    if (!glyph_var_data) return_trace (false);
401
0
    out->dataZ = glyph_var_data - (char *) out;
402
403
0
    return_trace (glyph_vars.serialize_glyph_var_data (c, it, long_offset, num_glyphs,
404
0
                                                       (char *) glyph_var_data_offsets));
405
0
  }
406
407
  bool instantiate (hb_subset_context_t *c) const
408
0
  {
409
0
    TRACE_SUBSET (this);
410
0
    glyph_variations_t<GidOffsetType> glyph_vars;
411
0
    if (!decompile_glyph_variations (c, glyph_vars))
412
0
      return_trace (false);
413
414
0
    if (!glyph_vars.instantiate (c->plan)) return_trace (false);
415
0
    if (!glyph_vars.compile_bytes (c->plan->axes_index_map, c->plan->axes_old_index_tag_map))
416
0
      return_trace (false);
417
418
0
    unsigned axis_count = c->plan->axes_index_map.get_population ();
419
0
    unsigned num_glyphs = c->plan->num_output_glyphs ();
420
0
    auto it = hb_iter (c->plan->new_to_old_gid_list);
421
422
0
    bool force_long_offsets = false;
423
#ifdef HB_EXPERIMENTAL_API
424
    force_long_offsets = c->plan->flags & HB_SUBSET_FLAGS_IFTB_REQUIREMENTS;
425
#endif
426
0
    return_trace (serialize (c->serializer, glyph_vars, it, axis_count, num_glyphs, force_long_offsets));
427
0
  }
428
429
  bool subset (hb_subset_context_t *c) const
430
0
  {
431
0
    TRACE_SUBSET (this);
432
0
    if (c->plan->all_axes_pinned)
433
0
      return_trace (false);
434
435
0
    if (c->plan->normalized_coords)
436
0
      return_trace (instantiate (c));
437
438
0
    unsigned glyph_count = version.to_int () ? c->plan->source->get_num_glyphs () : 0;
439
440
0
    gvar_GVAR *out = c->serializer->allocate_min<gvar_GVAR> ();
441
0
    if (unlikely (!out)) return_trace (false);
442
443
0
    out->version.major = 1;
444
0
    out->version.minor = 0;
445
0
    out->axisCount = axisCount;
446
0
    out->sharedTupleCount = sharedTupleCount;
447
448
0
    unsigned int num_glyphs = c->plan->num_output_glyphs ();
449
0
    out->glyphCountX = hb_min (0xFFFFu, num_glyphs);
450
451
    /* avar2 partial instancing: cull tuple variations whose region falls
452
     * outside the reachable old-space final-coord ranges. Rewritten glyph
453
     * data is cached per new gid; untouched glyphs are copied verbatim. */
454
0
    hb_vector_t<hb_vector_t<char>> culled_vars;
455
0
    hb_set_t culled_gids;
456
0
    if (c->plan->has_avar2 && c->plan->avar2_reachable_ranges.get_population ())
457
0
    {
458
0
      hb_array_t<const F2DOT14> shared_tuples_array =
459
0
    (this+sharedTuples).as_array ((unsigned) sharedTupleCount * (unsigned) axisCount);
460
0
      if (unlikely (!culled_vars.resize (num_glyphs))) return_trace (false);
461
0
      auto cull_it = hb_iter (c->plan->new_to_old_gid_list);
462
0
      if (cull_it->first == 0 && !(c->plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE))
463
0
  cull_it++;
464
0
      for (auto &_ : cull_it)
465
0
      {
466
0
  hb_bytes_t var_data_bytes = get_glyph_var_data_bytes (c->source_blob, glyph_count, _.second);
467
0
  if (var_data_bytes.length < GlyphVariationData::min_size) continue;
468
0
  bool changed = false;
469
0
  if (unlikely (!var_data_bytes.as<GlyphVariationData> ()
470
0
          ->cull_tuple_variations (var_data_bytes, axisCount,
471
0
                 shared_tuples_array,
472
0
                 &c->plan->axes_old_index_tag_map,
473
0
                 c->plan->avar2_reachable_ranges,
474
0
                 culled_vars[_.first], &changed)))
475
0
    return_trace (false);
476
0
  if (changed) culled_gids.add (_.first);
477
0
      }
478
0
      if (unlikely (culled_gids.in_error ())) return_trace (false);
479
0
    }
480
481
0
    auto it = hb_iter (c->plan->new_to_old_gid_list);
482
0
    if (it->first == 0 && !(c->plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE))
483
0
      it++;
484
0
    unsigned subset_data_size = 0;
485
0
    unsigned padding_size = 0;
486
0
    for (auto &_ : it)
487
0
    {
488
0
      hb_codepoint_t old_gid = _.second;
489
0
      unsigned glyph_data_size = culled_gids.has (_.first)
490
0
         ? culled_vars[_.first].length
491
0
         : get_glyph_var_data_bytes (c->source_blob, glyph_count, old_gid).length;
492
0
      if (glyph_data_size % 2)
493
0
      {
494
0
        glyph_data_size++;
495
0
        padding_size++;
496
0
      }
497
498
0
      if (unlikely (hb_unsigned_add_overflows (subset_data_size, glyph_data_size, &subset_data_size)))
499
0
  return_trace (false);
500
0
    }
501
502
    /* According to the spec: If the short format (Offset16) is used for offsets,
503
     * the value stored is the offset divided by 2, so the maximum data size should
504
     * be 2 * 0xFFFFu, which is 0x1FFFEu */
505
0
    bool long_offset = subset_data_size > 0x1FFFEu;
506
#ifdef HB_EXPERIMENTAL_API
507
    long_offset = long_offset || (c->plan->flags & HB_SUBSET_FLAGS_IFTB_REQUIREMENTS);
508
#endif
509
0
    out->flags = long_offset ? 1 : 0;
510
511
0
    unsigned subset_offsets_size = (long_offset ? 4 : 2) * (num_glyphs + 1);
512
0
    HBUINT8 *subset_offsets = c->serializer->allocate_size<HBUINT8> (subset_offsets_size, false);
513
0
    if (!subset_offsets) return_trace (false);
514
515
    /* shared tuples */
516
0
    if (!sharedTupleCount || !sharedTuples)
517
0
      out->sharedTuples = (char *) subset_offsets + subset_offsets_size - (char *) out;
518
0
    else
519
0
    {
520
0
      unsigned int shared_tuple_size = F2DOT14::static_size * axisCount * sharedTupleCount;
521
0
      F2DOT14 *tuples = c->serializer->allocate_size<F2DOT14> (shared_tuple_size);
522
0
      if (!tuples) return_trace (false);
523
0
      out->sharedTuples = (char *) tuples - (char *) out;
524
0
      hb_memcpy (tuples, this+sharedTuples, shared_tuple_size);
525
0
    }
526
527
    /* This ordering relative to the shared tuples array, which puts the glyphVariationData
528
       last in the table, is required when HB_SUBSET_FLAGS_IFTB_REQUIREMENTS is set */
529
0
    if (long_offset)
530
0
      subset_data_size -= padding_size;
531
0
    char *subset_data = c->serializer->allocate_size<char> (subset_data_size, false);
532
0
    if (!subset_data) return_trace (false);
533
0
    out->dataZ = subset_data - (char *) out;
534
535
536
0
    if (long_offset)
537
0
    {
538
0
      ((HBUINT32 *) subset_offsets)[0] = 0;
539
0
      subset_offsets += 4;
540
0
    }
541
0
    else
542
0
    {
543
0
      ((HBUINT16 *) subset_offsets)[0] = 0;
544
0
      subset_offsets += 2;
545
0
    }
546
0
    unsigned int glyph_offset = 0;
547
548
0
    hb_codepoint_t last = 0;
549
0
    it = hb_iter (c->plan->new_to_old_gid_list);
550
0
    if (it->first == 0 && !(c->plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE))
551
0
      it++;
552
0
    for (auto &_ : it)
553
0
    {
554
0
      hb_codepoint_t gid = _.first;
555
0
      hb_codepoint_t old_gid = _.second;
556
557
0
      if (long_offset)
558
0
  for (; last < gid; last++)
559
0
    ((HBUINT32 *) subset_offsets)[last] = glyph_offset;
560
0
      else
561
0
  for (; last < gid; last++)
562
0
    ((HBUINT16 *) subset_offsets)[last] = glyph_offset / 2;
563
564
0
      hb_bytes_t var_data_bytes = culled_gids.has (gid)
565
0
          ? hb_bytes_t (culled_vars[gid].arrayZ,
566
0
            culled_vars[gid].length)
567
0
          : get_glyph_var_data_bytes (c->source_blob,
568
0
                    glyph_count,
569
0
                    old_gid);
570
571
0
      hb_memcpy (subset_data, var_data_bytes.arrayZ, var_data_bytes.length);
572
0
      unsigned glyph_data_size = var_data_bytes.length;
573
0
      subset_data += glyph_data_size;
574
0
      glyph_offset += glyph_data_size;
575
576
0
      if (!long_offset && (glyph_data_size % 2))
577
0
      {
578
0
        *subset_data = 0;
579
0
        subset_data++;
580
0
        glyph_offset++;
581
0
      }
582
583
0
      if (long_offset)
584
0
  ((HBUINT32 *) subset_offsets)[gid] = glyph_offset;
585
0
      else
586
0
  ((HBUINT16 *) subset_offsets)[gid] = glyph_offset / 2;
587
588
0
      last++; // Skip over gid
589
0
    }
590
591
0
    if (long_offset)
592
0
      for (; last < num_glyphs; last++)
593
0
  ((HBUINT32 *) subset_offsets)[last] = glyph_offset;
594
0
    else
595
0
      for (; last < num_glyphs; last++)
596
0
  ((HBUINT16 *) subset_offsets)[last] = glyph_offset / 2;
597
598
0
    return_trace (true);
599
0
  }
600
601
  protected:
602
  const hb_bytes_t get_glyph_var_data_bytes (hb_blob_t *blob,
603
               unsigned glyph_count,
604
               hb_codepoint_t glyph) const
605
0
  {
606
0
    unsigned start_offset = get_offset (glyph_count, glyph);
607
0
    unsigned end_offset = get_offset (glyph_count, glyph+1);
608
0
    if (unlikely (end_offset < start_offset)) return hb_bytes_t ();
609
0
    unsigned length = end_offset - start_offset;
610
0
    hb_bytes_t var_data = blob->as_bytes ().sub_array (((unsigned) dataZ) + start_offset, length);
611
0
    return likely (var_data.length >= GlyphVariationData::min_size) ? var_data : hb_bytes_t ();
612
0
  }
613
614
0
  bool is_long_offset () const { return flags & 1; }
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned short, 2u>, 1735811442u>::is_long_offset() const
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned int, 3u>, 1196835154u>::is_long_offset() const
615
616
  unsigned get_offset (unsigned glyph_count, unsigned i) const
617
0
  {
618
0
    if (unlikely (i > glyph_count)) return 0;
619
0
    hb_barrier ();
620
0
    return is_long_offset () ? get_long_offset_array ()[i] : get_short_offset_array ()[i] * 2;
621
0
  }
622
623
0
  const HBUINT32 * get_long_offset_array () const { return (const HBUINT32 *) &offsetZ; }
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned short, 2u>, 1735811442u>::get_long_offset_array() const
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned int, 3u>, 1196835154u>::get_long_offset_array() const
624
0
  const HBUINT16 *get_short_offset_array () const { return (const HBUINT16 *) &offsetZ; }
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned short, 2u>, 1735811442u>::get_short_offset_array() const
Unexecuted instantiation: OT::gvar_GVAR<OT::NumType<true, unsigned int, 3u>, 1196835154u>::get_short_offset_array() const
625
626
  public:
627
  struct accelerator_t
628
  {
629
630
    hb_scalar_cache_t *create_cache () const
631
0
    {
632
0
      return hb_scalar_cache_t::create (hb_min ((unsigned) table->sharedTupleCount,
633
0
            +TupleVariationHeader::max_shared_tuple_count));
634
0
    }
635
636
    static void destroy_cache (hb_scalar_cache_t *cache)
637
0
    {
638
0
      hb_scalar_cache_t::destroy (cache);
639
0
    }
640
641
0
    bool has_data () const { return table->has_data (); }
642
643
    accelerator_t (hb_face_t *face)
644
24
    {
645
24
      table = hb_sanitize_context_t ().reference_table<gvar_GVAR> (face);
646
      /* If sanitize failed, set glyphCount to 0. */
647
24
      glyphCount = table->version.to_int () ? face->get_num_glyphs () : 0;
648
24
    }
649
0
    ~accelerator_t () { table.destroy (); }
650
651
    private:
652
653
    static float infer_delta (const hb_array_t<contour_point_t> points,
654
            const hb_array_t<contour_point_t> deltas,
655
            unsigned int target, unsigned int prev, unsigned int next,
656
            float contour_point_t::*m)
657
0
    {
658
0
      float target_val = points.arrayZ[target].*m;
659
0
      float prev_val = points.arrayZ[prev].*m;
660
0
      float next_val = points.arrayZ[next].*m;
661
0
      float prev_delta =  deltas.arrayZ[prev].*m;
662
0
      float next_delta =  deltas.arrayZ[next].*m;
663
664
0
      if (prev_val == next_val)
665
0
  return (prev_delta == next_delta) ? prev_delta : 0.f;
666
0
      else if (target_val <= hb_min (prev_val, next_val))
667
0
  return (prev_val < next_val) ? prev_delta : next_delta;
668
0
      else if (target_val >= hb_max (prev_val, next_val))
669
0
  return (prev_val > next_val) ? prev_delta : next_delta;
670
671
      /* linear interpolation */
672
0
      float r = (target_val - prev_val) / (next_val - prev_val);
673
0
      return prev_delta + r * (next_delta - prev_delta);
674
0
    }
675
676
    static unsigned int next_index (unsigned int i, unsigned int start, unsigned int end)
677
0
    { return (i >= end) ? start : (i + 1); }
678
679
#ifndef HB_OPTIMIZE_SIZE
680
    template <bool is_x>
681
#endif
682
    static bool decompile_deltas_add_to_points (const HBUINT8 *&p /* IN/OUT */,
683
            hb_array_t<contour_point_t> points,
684
            float scalar,
685
            const HBUINT8 *end,
686
            unsigned start
687
#ifdef HB_OPTIMIZE_SIZE
688
            , bool is_x
689
#endif
690
            )
691
0
    {
692
0
      unsigned i = 0;
693
0
      unsigned count = points.length;
694
0
      while (i < count)
695
0
      {
696
0
  if (unlikely (p + 1 > end)) return false;
697
0
  unsigned control = *p++;
698
0
  unsigned run_count = (control & TupleValues::VALUE_RUN_COUNT_MASK) + 1;
699
0
  unsigned stop = i + run_count;
700
0
  if (unlikely (stop > count)) return false;
701
702
0
  unsigned skip = i < start ? hb_min (start - i, run_count) : 0;
703
0
  i += skip;
704
705
0
  switch (control & TupleValues::VALUES_SIZE_MASK)
706
0
  {
707
0
    case TupleValues::VALUES_ARE_ZEROS:
708
0
      i = stop;
709
0
      break;
710
0
    case TupleValues::VALUES_ARE_WORDS:
711
0
    {
712
0
      if (unlikely (p + run_count * HBINT16::static_size > end)) return false;
713
0
      p += skip * HBINT16::static_size;
714
0
      const auto *pp = (const HBINT16 *) p;
715
0
      for (; i < stop; i++)
716
0
      {
717
0
        float v = *pp++ * scalar;
718
0
        if (is_x) points.arrayZ[i].x += v;
719
0
        else points.arrayZ[i].y += v;
720
0
      }
721
0
      p = (const HBUINT8 *) pp;
722
0
    }
723
0
    break;
724
0
    case TupleValues::VALUES_ARE_LONGS:
725
0
    {
726
0
      if (unlikely (p + run_count * HBINT32::static_size > end)) return false;
727
0
      p += skip * HBINT32::static_size;
728
0
      const auto *pp = (const HBINT32 *) p;
729
0
      for (; i < stop; i++)
730
0
      {
731
0
        float v = *pp++ * scalar;
732
0
        if (is_x) points.arrayZ[i].x += v;
733
0
        else points.arrayZ[i].y += v;
734
0
      }
735
0
      p = (const HBUINT8 *) pp;
736
0
    }
737
0
    break;
738
0
    case TupleValues::VALUES_ARE_BYTES:
739
0
    {
740
0
      if (unlikely (p + run_count > end)) return false;
741
0
      p += skip * HBINT8::static_size;
742
0
      const auto *pp = (const HBINT8 *) p;
743
0
      for (; i < stop; i++)
744
0
      {
745
0
        float v = *pp++ * scalar;
746
0
        if (is_x) points.arrayZ[i].x += v;
747
0
        else points.arrayZ[i].y += v;
748
0
      }
749
0
      p = (const HBUINT8 *) pp;
750
0
    }
751
0
    break;
752
0
  }
753
0
      }
754
0
      return true;
755
0
    }
Unexecuted instantiation: bool OT::gvar_GVAR<OT::NumType<true, unsigned short, 2u>, 1735811442u>::accelerator_t::decompile_deltas_add_to_points<true>(OT::NumType<true, unsigned char, 1u> const*&, hb_array_t<contour_point_t>, float, OT::NumType<true, unsigned char, 1u> const*, unsigned int)
Unexecuted instantiation: bool OT::gvar_GVAR<OT::NumType<true, unsigned short, 2u>, 1735811442u>::accelerator_t::decompile_deltas_add_to_points<false>(OT::NumType<true, unsigned char, 1u> const*&, hb_array_t<contour_point_t>, float, OT::NumType<true, unsigned char, 1u> const*, unsigned int)
756
    public:
757
    bool apply_deltas_to_points (hb_codepoint_t glyph,
758
         hb_array_t<const int> coords,
759
         const hb_array_t<contour_point_t> points,
760
         hb_glyf_scratch_t &scratch,
761
         hb_scalar_cache_t *gvar_cache = nullptr,
762
         bool phantom_only = false,
763
         int64_t *budget = nullptr) const
764
0
    {
765
0
      if (unlikely (glyph >= glyphCount)) return true;
766
0
      hb_scalar_cache_t *scalar_cache = gvar_cache ?
767
0
          gvar_cache :
768
0
          (hb_scalar_cache_t *) &Null(hb_scalar_cache_t);
769
770
0
      hb_bytes_t var_data_bytes = table->get_glyph_var_data_bytes (table.get_blob (), glyphCount, glyph);
771
0
      if (!var_data_bytes.as<GlyphVariationData> ()->has_data ()) return true;
772
773
0
      auto &shared_indices = scratch.shared_indices;
774
0
      shared_indices.clear ();
775
776
0
      typename GlyphVariationData::tuple_iterator_t iterator;
777
0
      if (!GlyphVariationData::get_tuple_iterator (var_data_bytes, table->axisCount,
778
0
               var_data_bytes.arrayZ,
779
0
               shared_indices, &iterator))
780
0
  return true; /* so isn't applied at all */
781
782
0
      bool any_private_points = false;
783
0
      bool private_points_checked = false;
784
785
      /* Save original points for inferred delta calculation */
786
0
      auto &orig_points_vec = scratch.orig_points;
787
0
      orig_points_vec.clear (); // Populated lazily
788
0
      auto orig_points = orig_points_vec.as_array ();
789
790
      /* flag is used to indicate referenced point */
791
0
      auto &deltas_vec = scratch.deltas;
792
0
      deltas_vec.clear (); // Populated lazily
793
0
      auto deltas = deltas_vec.as_array ();
794
795
0
      unsigned num_coords = table->axisCount;
796
0
      hb_array_t<const F2DOT14> shared_tuples = (table+table->sharedTuples).as_array (table->sharedTupleCount * num_coords);
797
798
0
      auto &private_indices = scratch.private_indices;
799
0
      auto &x_deltas = scratch.x_deltas;
800
0
      auto &y_deltas = scratch.y_deltas;
801
802
0
      unsigned count = points.length;
803
0
      bool flush = false;
804
805
0
      do
806
0
      {
807
0
  float scalar = iterator.current_tuple->calculate_scalar (coords, num_coords, shared_tuples,
808
0
                 scalar_cache);
809
810
0
  if (scalar == 0.f) continue;
811
812
0
  if (budget &&
813
0
      unlikely (!hb_budget_spend (*budget, HB_BUDGET_1,
814
0
           phantom_only && count >= 4 ? 4 : count)))
815
0
    return false;
816
817
0
  if (!private_points_checked)
818
0
  {
819
0
    auto scan = iterator;
820
0
    do
821
0
    {
822
0
      if (scan.current_tuple->has_private_points ())
823
0
      {
824
0
        any_private_points = true;
825
0
        break;
826
0
      }
827
0
    } while (scan.move_to_next ());
828
0
    private_points_checked = true;
829
0
  }
830
0
  const HBUINT8 *p = iterator.get_serialized_data ();
831
0
  unsigned int length = iterator.current_tuple->get_data_size ();
832
0
  if (unlikely (!iterator.var_data_bytes.check_range (p, length)))
833
0
    return false;
834
835
0
  if (!deltas)
836
0
  {
837
0
    if (unlikely (!deltas_vec.resize_dirty  (count))) return false;
838
0
    deltas = deltas_vec.as_array ();
839
0
    hb_memset (deltas.arrayZ + (phantom_only ? count - 4 : 0), 0,
840
0
         (phantom_only ? 4 : count) * sizeof (deltas[0]));
841
0
  }
842
843
0
  const HBUINT8 *end = p + length;
844
845
0
  bool has_private_points = iterator.current_tuple->has_private_points ();
846
0
  if (has_private_points &&
847
0
      !GlyphVariationData::decompile_points (p, private_indices, end))
848
0
    return false;
849
0
  const hb_array_t<unsigned int> &indices = has_private_points ? private_indices : shared_indices;
850
851
0
  bool apply_to_all = (indices.length == 0);
852
0
  unsigned num_deltas = apply_to_all ? points.length : indices.length;
853
0
  unsigned start_deltas = (apply_to_all && phantom_only && num_deltas >= 4 ? num_deltas - 4 : 0);
854
855
0
  if (apply_to_all && !any_private_points)
856
0
  {
857
#ifdef HB_OPTIMIZE_SIZE
858
    if (unlikely (!decompile_deltas_add_to_points (p, points, scalar, end, start_deltas, true))) return false;
859
    if (unlikely (!decompile_deltas_add_to_points (p, points, scalar, end, start_deltas, false))) return false;
860
#else
861
0
    if (unlikely (!decompile_deltas_add_to_points<true> (p, points, scalar, end, start_deltas))) return false;
862
0
    if (unlikely (!decompile_deltas_add_to_points<false> (p, points, scalar, end, start_deltas))) return false;
863
0
#endif
864
0
    continue;
865
0
  }
866
867
0
  if (unlikely (!x_deltas.resize_dirty  (num_deltas))) return false;
868
0
  if (unlikely (!GlyphVariationData::decompile_deltas (p, x_deltas, end, false, start_deltas))) return false;
869
0
  if (unlikely (!y_deltas.resize_dirty  (num_deltas))) return false;
870
0
  if (unlikely (!GlyphVariationData::decompile_deltas (p, y_deltas, end, false, start_deltas))) return false;
871
872
0
  if (!apply_to_all)
873
0
  {
874
0
    if (!orig_points && !phantom_only)
875
0
    {
876
0
      orig_points_vec.extend (points);
877
0
      if (unlikely (orig_points_vec.in_error ())) return false;
878
0
      orig_points = orig_points_vec.as_array ();
879
0
    }
880
881
0
    if (flush)
882
0
    {
883
0
      for (unsigned int i = phantom_only ? count - 4 : 0; i < count; i++)
884
0
        points.arrayZ[i].translate (deltas.arrayZ[i]);
885
0
    }
886
0
    hb_memset (deltas.arrayZ + (phantom_only ? count - 4 : 0), 0,
887
0
         (phantom_only ? 4 : count) * sizeof (deltas[0]));
888
0
  }
889
890
0
  if (HB_OPTIMIZE_SIZE_VAL)
891
0
  {
892
0
    for (unsigned int i = 0; i < num_deltas; i++)
893
0
    {
894
0
      unsigned int pt_index;
895
0
      if (apply_to_all)
896
0
        pt_index = i;
897
0
      else
898
0
      {
899
0
        pt_index = indices[i];
900
0
        if (unlikely (pt_index >= deltas.length)) continue;
901
0
      }
902
0
      if (phantom_only && pt_index < count - 4) continue;
903
0
      auto &delta = deltas.arrayZ[pt_index];
904
0
      delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */
905
0
      delta.add_delta (x_deltas.arrayZ[i] * scalar,
906
0
           y_deltas.arrayZ[i] * scalar);
907
0
    }
908
0
  }
909
0
  else
910
0
  {
911
    /* Ouch. Four cases... for optimization. */
912
0
    if (scalar != 1.0f)
913
0
    {
914
0
      if (apply_to_all)
915
0
        for (unsigned int i = phantom_only ? count - 4 : 0; i < count; i++)
916
0
        {
917
0
    auto &delta = deltas.arrayZ[i];
918
0
    delta.add_delta (x_deltas.arrayZ[i] * scalar,
919
0
         y_deltas.arrayZ[i] * scalar);
920
0
        }
921
0
      else
922
0
        for (unsigned int i = 0; i < num_deltas; i++)
923
0
        {
924
0
    unsigned int pt_index = indices[i];
925
0
    if (unlikely (pt_index >= deltas.length)) continue;
926
0
    if (phantom_only && pt_index < count - 4) continue;
927
0
    auto &delta = deltas.arrayZ[pt_index];
928
0
    delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */
929
0
    delta.add_delta (x_deltas.arrayZ[i] * scalar,
930
0
         y_deltas.arrayZ[i] * scalar);
931
0
        }
932
0
    }
933
0
    else
934
0
    {
935
0
      if (apply_to_all)
936
0
        for (unsigned int i = phantom_only ? count - 4 : 0; i < count; i++)
937
0
        {
938
0
    auto &delta = deltas.arrayZ[i];
939
0
    delta.add_delta (x_deltas.arrayZ[i],
940
0
         y_deltas.arrayZ[i]);
941
0
        }
942
0
      else
943
0
        for (unsigned int i = 0; i < num_deltas; i++)
944
0
        {
945
0
    unsigned int pt_index = indices[i];
946
0
    if (unlikely (pt_index >= deltas.length)) continue;
947
0
    if (phantom_only && pt_index < count - 4) continue;
948
0
    auto &delta = deltas.arrayZ[pt_index];
949
0
    delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */
950
0
    delta.add_delta (x_deltas.arrayZ[i],
951
0
         y_deltas.arrayZ[i]);
952
0
        }
953
0
    }
954
0
  }
955
956
  /* infer deltas for unreferenced points */
957
0
  if (!apply_to_all && !phantom_only)
958
0
  {
959
0
    unsigned start_point = 0;
960
0
    unsigned end_point = 0;
961
0
    while (true)
962
0
    {
963
0
      while (end_point < count && !points.arrayZ[end_point].is_end_point)
964
0
        end_point++;
965
0
      if (unlikely (end_point == count)) break;
966
967
      /* Check the number of unreferenced points in a contour. If no unref points or no ref points, nothing to do. */
968
0
      unsigned unref_count = 0;
969
0
      for (unsigned i = start_point; i < end_point + 1; i++)
970
0
        unref_count += deltas.arrayZ[i].flag;
971
0
      unref_count = (end_point - start_point + 1) - unref_count;
972
973
0
      unsigned j = start_point;
974
0
      if (unref_count == 0 || unref_count > end_point - start_point)
975
0
        goto no_more_gaps;
976
977
0
      for (;;)
978
0
      {
979
        /* Locate the next gap of unreferenced points between two referenced points prev and next.
980
         * Note that a gap may wrap around at left (start_point) and/or at right (end_point).
981
         */
982
0
        unsigned int prev, next, i;
983
0
        for (;;)
984
0
        {
985
0
    i = j;
986
0
    j = next_index (i, start_point, end_point);
987
0
    if (deltas.arrayZ[i].flag && !deltas.arrayZ[j].flag) break;
988
0
        }
989
0
        prev = j = i;
990
0
        for (;;)
991
0
        {
992
0
    i = j;
993
0
    j = next_index (i, start_point, end_point);
994
0
    if (!deltas.arrayZ[i].flag && deltas.arrayZ[j].flag) break;
995
0
        }
996
0
        next = j;
997
        /* Infer deltas for all unref points in the gap between prev and next */
998
0
        i = prev;
999
0
        for (;;)
1000
0
        {
1001
0
    i = next_index (i, start_point, end_point);
1002
0
    if (i == next) break;
1003
0
    deltas.arrayZ[i].x = infer_delta (orig_points, deltas, i, prev, next, &contour_point_t::x);
1004
0
    deltas.arrayZ[i].y = infer_delta (orig_points, deltas, i, prev, next, &contour_point_t::y);
1005
0
    if (--unref_count == 0) goto no_more_gaps;
1006
0
        }
1007
0
      }
1008
0
    no_more_gaps:
1009
0
      start_point = end_point = end_point + 1;
1010
0
    }
1011
0
  }
1012
1013
0
  flush = true;
1014
1015
0
      } while (iterator.move_to_next ());
1016
1017
0
      if (flush)
1018
0
      {
1019
0
  for (unsigned int i = phantom_only ? count - 4 : 0; i < count; i++)
1020
0
    points.arrayZ[i].translate (deltas.arrayZ[i]);
1021
0
      }
1022
1023
0
      return true;
1024
0
    }
1025
1026
    unsigned int get_axis_count () const { return table->axisCount; }
1027
1028
    private:
1029
    hb_blob_ptr_t<gvar_GVAR> table;
1030
    unsigned glyphCount;
1031
  };
1032
1033
  protected:
1034
  FixedVersion<>version;  /* Version number of the glyph variations table
1035
         * Set to 0x00010000u. */
1036
  HBUINT16  axisCount;  /* The number of variation axes for this font. This must be
1037
         * the same number as axisCount in the 'fvar' table. */
1038
  HBUINT16  sharedTupleCount;
1039
        /* The number of shared tuple records. Shared tuple records
1040
         * can be referenced within glyph variation data tables for
1041
         * multiple glyphs, as opposed to other tuple records stored
1042
         * directly within a glyph variation data table. */
1043
  NNOffset32To<UnsizedArrayOf<F2DOT14>>
1044
    sharedTuples; /* Offset from the start of this table to the shared tuple records.
1045
         * Array of tuple records shared across all glyph variation data tables. */
1046
  GidOffsetType glyphCountX;  /* The number of glyphs in this font. This must match the number of
1047
         * glyphs stored elsewhere in the font. */
1048
  HBUINT16  flags;    /* Bit-field that gives the format of the offset array that follows.
1049
         * If bit 0 is clear, the offsets are uint16; if bit 0 is set, the
1050
         * offsets are uint32. */
1051
  Offset32To<GlyphVariationData>
1052
    dataZ;    /* Offset from the start of this table to the array of
1053
         * GlyphVariationData tables. */
1054
  UnsizedArrayOf<HBUINT8>
1055
    offsetZ;  /* Offsets from the start of the GlyphVariationData array
1056
         * to each GlyphVariationData table. */
1057
  public:
1058
  DEFINE_SIZE_ARRAY (20, offsetZ);
1059
};
1060
1061
using gvar = gvar_GVAR<HBUINT16, HB_OT_TAG_gvar>;
1062
using GVAR = gvar_GVAR<HBUINT24, HB_OT_TAG_GVAR>;
1063
1064
struct gvar_accelerator_t : gvar::accelerator_t {
1065
24
  gvar_accelerator_t (hb_face_t *face) : gvar::accelerator_t (face) {}
1066
};
1067
struct GVAR_accelerator_t : GVAR::accelerator_t {
1068
0
  GVAR_accelerator_t (hb_face_t *face) : GVAR::accelerator_t (face) {}
1069
};
1070
1071
} /* namespace OT */
1072
1073
#endif /* HB_OT_VAR_GVAR_TABLE_HH */