Coverage Report

Created: 2026-10-22 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/hb-ot-hmtx-table.hh
Line
Count
Source
1
/*
2
 * Copyright © 2011,2012  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, Roderick Sheeter
25
 */
26
27
#ifndef HB_OT_HMTX_TABLE_HH
28
#define HB_OT_HMTX_TABLE_HH
29
30
#include "hb-open-type.hh"
31
#include "hb-ot-dual.hh"
32
#include "hb-ot-maxp-table.hh"
33
#include "hb-ot-hhea-table.hh"
34
#include "hb-ot-os2-table.hh"
35
#include "hb-ot-var-hvar-table.hh"
36
#include "hb-ot-var-mvar-table.hh"
37
#include "hb-ot-metrics.hh"
38
39
/*
40
 * hmtx -- Horizontal Metrics
41
 * https://docs.microsoft.com/en-us/typography/opentype/spec/hmtx
42
 * vmtx -- Vertical Metrics
43
 * https://docs.microsoft.com/en-us/typography/opentype/spec/vmtx
44
 */
45
#define HB_OT_TAG_hmtx HB_TAG('h','m','t','x')
46
#define HB_OT_TAG_HMTX HB_TAG('H','M','T','X')
47
#define HB_OT_TAG_vmtx HB_TAG('v','m','t','x')
48
#define HB_OT_TAG_VMTX HB_TAG('V','M','T','X')
49
50
51
namespace OT {
52
53
54
struct LongMetric
55
{
56
  UFWORD  advance; /* Advance width/height. */
57
  FWORD   sb; /* Leading (left/top) side bearing. */
58
  public:
59
  DEFINE_SIZE_STATIC (4);
60
};
61
62
63
template <typename T/*Data table type*/, typename H/*Header table type*/, typename V/*Var table type*/>
64
struct hmtxvmtx
65
{
66
  bool sanitize (hb_sanitize_context_t *c HB_UNUSED) const
67
0
  {
68
0
    TRACE_SANITIZE (this);
69
    /* We don't check for anything specific here.  The users of the
70
     * struct do all the hard work... */
71
0
    return_trace (true);
72
0
  }
Unexecuted instantiation: OT::hmtxvmtx<OT::hmtx, OT::hhea, OT::HVAR>::sanitize(hb_sanitize_context_t*) const
Unexecuted instantiation: OT::hmtxvmtx<OT::vmtx, OT::vhea, OT::VVAR>::sanitize(hb_sanitize_context_t*) const
73
74
  const hb_hashmap_t<hb_codepoint_t, hb_pair_t<unsigned, int>>* get_mtx_map (const hb_subset_plan_t *plan) const
75
  { return T::is_horizontal ? &plan->hmtx_map : &plan->vmtx_map; }
76
77
  bool subset_update_header (hb_subset_context_t *c,
78
           unsigned int num_hmetrics,
79
           const hb_hashmap_t<hb_codepoint_t, hb_pair_t<unsigned, int>> *mtx_map,
80
           const hb_vector_t<unsigned> &bounds_vec) const
81
  {
82
    hb_blob_t *src_blob = hb_sanitize_context_t ().reference_table<H> (c->plan->source, H::tableTag);
83
    hb_blob_t *dest_blob = hb_blob_copy_writable_or_fail (src_blob);
84
    hb_blob_destroy (src_blob);
85
86
    if (unlikely (!dest_blob)) {
87
      return false;
88
    }
89
90
    unsigned int length;
91
    H *table = (H *) hb_blob_get_data (dest_blob, &length);
92
    c->serializer->check_assign (table->numberOfLongMetrics, num_hmetrics, HB_SERIALIZE_ERROR_INT_OVERFLOW);
93
94
#ifndef HB_NO_VAR
95
    if (c->plan->normalized_coords)
96
    {
97
      auto &MVAR = *c->plan->source->table.MVAR;
98
      if (T::is_horizontal)
99
      {
100
  HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_CARET_RISE,   caretSlopeRise);
101
  HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_CARET_RUN,    caretSlopeRun);
102
  HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_HORIZONTAL_CARET_OFFSET, caretOffset);
103
      }
104
      else
105
      {
106
  HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_VERTICAL_CARET_RISE,     caretSlopeRise);
107
  HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_VERTICAL_CARET_RUN,      caretSlopeRun);
108
  HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_VERTICAL_CARET_OFFSET,   caretOffset);
109
      }
110
111
      bool empty = true;
112
      int min_lsb = 0x7FFF;
113
      int min_rsb = 0x7FFF;
114
      int max_extent = -0x7FFF;
115
      unsigned max_adv = 0;
116
      for (const auto _ : *mtx_map)
117
      {
118
        hb_codepoint_t gid = _.first;
119
        unsigned adv = _.second.first;
120
        int lsb = _.second.second;
121
        max_adv = hb_max (max_adv, adv);
122
123
        if (bounds_vec[gid] != 0xFFFFFFFF)
124
        {
125
    empty = false;
126
          unsigned bound_width = bounds_vec[gid];
127
          int rsb = adv - lsb - bound_width;
128
          int extent = lsb + bound_width;
129
          min_lsb = hb_min (min_lsb, lsb);
130
          min_rsb = hb_min (min_rsb, rsb);
131
          max_extent = hb_max (max_extent, extent);
132
        }
133
      }
134
135
      table->advanceMax = max_adv;
136
      if (!empty)
137
      {
138
        table->minLeadingBearing = min_lsb;
139
        table->minTrailingBearing = min_rsb;
140
        table->maxExtent = max_extent;
141
      }
142
143
      if (T::is_horizontal)
144
      {
145
        const auto &OS2 = *c->plan->source->table.OS2;
146
        if (OS2.has_data () &&
147
            table->ascender == OS2.sTypoAscender &&
148
            table->descender == OS2.sTypoDescender &&
149
            table->lineGap == OS2.sTypoLineGap)
150
        {
151
          table->ascender = static_cast<int> (roundf (OS2.sTypoAscender +
152
                                                      MVAR.get_var (HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER,
153
                                                                    c->plan->normalized_coords.arrayZ,
154
                                                                    c->plan->normalized_coords.length)));
155
          table->descender = static_cast<int> (roundf (OS2.sTypoDescender +
156
                                                       MVAR.get_var (HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER,
157
                                                                     c->plan->normalized_coords.arrayZ,
158
                                                                     c->plan->normalized_coords.length)));
159
          table->lineGap = static_cast<int> (roundf (OS2.sTypoLineGap +
160
                                                     MVAR.get_var (HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP,
161
                                                                   c->plan->normalized_coords.arrayZ,
162
                                                                   c->plan->normalized_coords.length)));
163
        }
164
      }
165
    }
166
#endif
167
168
    bool result = c->plan->add_table (H::tableTag, dest_blob);
169
    hb_blob_destroy (dest_blob);
170
171
    return result;
172
  }
173
174
  template<typename Iterator,
175
     hb_requires (hb_is_iterator (Iterator))>
176
  void serialize (hb_serialize_context_t *c,
177
      Iterator it,
178
      hb_array_t<const hb_codepoint_pair_t> new_to_old_gid_list,
179
      unsigned num_long_metrics,
180
                  unsigned total_num_metrics)
181
  {
182
    LongMetric* long_metrics = c->allocate_size<LongMetric> (num_long_metrics * LongMetric::static_size);
183
    FWORD* short_metrics = c->allocate_size<FWORD> ((total_num_metrics - num_long_metrics) * FWORD::static_size);
184
    if (!long_metrics || !short_metrics) return;
185
186
    short_metrics -= num_long_metrics;
187
188
    for (auto _ : new_to_old_gid_list)
189
    {
190
      hb_codepoint_t gid = _.first;
191
      auto mtx = *it++;
192
193
      if (gid < num_long_metrics)
194
      {
195
  LongMetric& lm = long_metrics[gid];
196
  lm.advance = mtx.first;
197
  lm.sb = mtx.second;
198
      }
199
      else
200
        short_metrics[gid] = mtx.second;
201
    }
202
  }
203
204
  bool subset (hb_subset_context_t *c) const
205
  {
206
    TRACE_SUBSET (this);
207
208
    auto *table_prime = c->serializer->start_embed <T> ();
209
210
    accelerator_t _mtx (c->plan->source);
211
    unsigned num_long_metrics;
212
    const hb_hashmap_t<hb_codepoint_t, hb_pair_t<unsigned, int>> *mtx_map = get_mtx_map (c->plan);
213
    {
214
      /* Determine num_long_metrics to encode. */
215
      auto& plan = c->plan;
216
217
      // TODO Don't consider retaingid holes here.
218
219
      num_long_metrics = hb_min (plan->num_output_glyphs (), H::long_metric_count_max ());
220
      unsigned int last_advance = get_new_gid_advance_unscaled (plan, mtx_map, num_long_metrics - 1, _mtx);
221
      while (num_long_metrics > 1 &&
222
       last_advance == get_new_gid_advance_unscaled (plan, mtx_map, num_long_metrics - 2, _mtx))
223
      {
224
  num_long_metrics--;
225
      }
226
    }
227
228
    auto it =
229
    + hb_iter (c->plan->new_to_old_gid_list)
230
    | hb_map ([&_mtx, mtx_map] (hb_codepoint_pair_t _)
231
        {
232
    hb_codepoint_t new_gid = _.first;
233
    hb_codepoint_t old_gid = _.second;
234
235
    hb_pair_t<unsigned, int> *v = nullptr;
236
    if (!mtx_map->has (new_gid, &v))
237
    {
238
      int lsb = 0;
239
      _mtx.get_leading_bearing_without_var_unscaled (old_gid, &lsb);
240
      return hb_pair (_mtx.get_advance_without_var_unscaled (old_gid), +lsb);
241
    }
242
    return *v;
243
        })
244
    ;
245
246
    table_prime->serialize (c->serializer,
247
          it,
248
          c->plan->new_to_old_gid_list,
249
          num_long_metrics,
250
          c->plan->num_output_glyphs ());
251
252
    if (unlikely (c->serializer->in_error ()))
253
      return_trace (false);
254
255
    // Amend header num hmetrics
256
    if (unlikely (!subset_update_header (c, num_long_metrics, mtx_map,
257
                                         T::is_horizontal ? c->plan->bounds_width_vec : c->plan->bounds_height_vec)))
258
      return_trace (false);
259
260
    return_trace (true);
261
  }
262
263
  struct accelerator_t
264
  {
265
    friend struct hmtxvmtx;
266
267
    accelerator_t (hb_face_t *face) :
268
0
      accelerator_t (face, T::tableTag, get_num_long_metrics (face))
269
0
    {}
Unexecuted instantiation: OT::hmtxvmtx<OT::hmtx, OT::hhea, OT::HVAR>::accelerator_t::accelerator_t(hb_face_t*)
Unexecuted instantiation: OT::hmtxvmtx<OT::vmtx, OT::vhea, OT::VVAR>::accelerator_t::accelerator_t(hb_face_t*)
270
271
    accelerator_t (hb_face_t *face, hb_tag_t tableTag, unsigned num_long_metrics_)
272
0
    {
273
0
      table = hb_sanitize_context_t ().reference_table<hmtxvmtx> (face, tableTag);
274
0
      var_table = hb_sanitize_context_t ().reference_table<V> (face, T::variationsTag);
275
276
0
      default_advance = T::is_horizontal ? hb_face_get_upem (face) / 2 : hb_face_get_upem (face);
277
278
      /* Populate count variables and sort them out as we go */
279
280
0
      unsigned int len = table.get_length ();
281
0
      if (len & 1)
282
0
        len--;
283
284
0
      num_long_metrics = num_long_metrics_;
285
0
      if (unlikely (num_long_metrics > len / 4))
286
0
  num_long_metrics = len / 4;
287
0
      len -= num_long_metrics * 4;
288
289
0
      num_bearings = face->table.maxp->get_num_glyphs ();
290
291
0
      if (unlikely (num_bearings < num_long_metrics))
292
0
        num_bearings = num_long_metrics;
293
0
      if (unlikely ((num_bearings - num_long_metrics) * 2 > len))
294
0
        num_bearings = num_long_metrics + len / 2;
295
0
      len -= (num_bearings - num_long_metrics) * 2;
296
297
      /* We MUST set num_bearings to zero if num_long_metrics is zero.
298
       * Our get_advance() depends on that. */
299
0
      if (unlikely (!num_long_metrics))
300
0
  num_bearings = num_long_metrics = 0;
301
302
0
      num_advances = num_bearings + len / 2;
303
0
      num_glyphs = face->get_num_glyphs ();
304
0
      if (num_glyphs < num_advances)
305
0
        num_glyphs = num_advances;
306
0
    }
Unexecuted instantiation: OT::hmtxvmtx<OT::hmtx, OT::hhea, OT::HVAR>::accelerator_t::accelerator_t(hb_face_t*, unsigned int, unsigned int)
Unexecuted instantiation: OT::hmtxvmtx<OT::vmtx, OT::vhea, OT::VVAR>::accelerator_t::accelerator_t(hb_face_t*, unsigned int, unsigned int)
307
    ~accelerator_t ()
308
0
    {
309
0
      table.destroy ();
310
0
      var_table.destroy ();
311
0
    }
Unexecuted instantiation: OT::hmtxvmtx<OT::hmtx, OT::hhea, OT::HVAR>::accelerator_t::~accelerator_t()
Unexecuted instantiation: OT::hmtxvmtx<OT::vmtx, OT::vhea, OT::VVAR>::accelerator_t::~accelerator_t()
312
313
0
    bool has_data () const { return (bool) num_bearings; }
Unexecuted instantiation: OT::hmtxvmtx<OT::hmtx, OT::hhea, OT::HVAR>::accelerator_t::has_data() const
Unexecuted instantiation: OT::hmtxvmtx<OT::vmtx, OT::vhea, OT::VVAR>::accelerator_t::has_data() const
314
315
    void get_leading_bearing_without_var_unscaled (hb_codepoint_t glyph,
316
               int *lsb) const
317
0
    {
318
0
      if (glyph < num_long_metrics)
319
0
      {
320
0
  *lsb = table->longMetricZ[glyph].sb;
321
0
  return;
322
0
      }
323
324
0
      if (unlikely (glyph >= num_bearings))
325
0
      {
326
0
        *lsb = 0;
327
0
  return;
328
0
      }
329
330
0
      const FWORD *bearings = (const FWORD *) &table->longMetricZ[num_long_metrics];
331
0
      *lsb = bearings[glyph - num_long_metrics];
332
0
    }
Unexecuted instantiation: OT::hmtxvmtx<OT::hmtx, OT::hhea, OT::HVAR>::accelerator_t::get_leading_bearing_without_var_unscaled(unsigned int, int*) const
Unexecuted instantiation: OT::hmtxvmtx<OT::vmtx, OT::vhea, OT::VVAR>::accelerator_t::get_leading_bearing_without_var_unscaled(unsigned int, int*) const
333
334
    unsigned int get_advance_without_var_unscaled (hb_codepoint_t glyph) const
335
0
    {
336
0
      if (glyph < num_bearings)
337
0
  return table->longMetricZ[hb_min (glyph, (uint32_t) num_long_metrics - 1)].advance;
338
339
      /* If num_advances is zero, it means we don't have the metrics table
340
       * for this direction: return default advance. */
341
0
      if (unlikely (!num_advances))
342
0
  return default_advance;
343
344
0
      return 0;
345
0
    }
Unexecuted instantiation: OT::hmtxvmtx<OT::hmtx, OT::hhea, OT::HVAR>::accelerator_t::get_advance_without_var_unscaled(unsigned int) const
Unexecuted instantiation: OT::hmtxvmtx<OT::vmtx, OT::vhea, OT::VVAR>::accelerator_t::get_advance_without_var_unscaled(unsigned int) const
346
347
#ifndef HB_NO_VAR
348
    unsigned get_advance_with_var_unscaled (hb_codepoint_t     glyph,
349
              hb_font_t         *font,
350
              hb_scalar_cache_t *store_cache = nullptr) const
351
    {
352
      unsigned int advance = get_advance_without_var_unscaled (glyph);
353
      return hb_clamp_to<unsigned> (advance + roundf (var_table->get_advance_delta_unscaled (glyph,
354
                      font->coords, font->num_coords,
355
                      store_cache)));
356
    }
357
#endif
358
359
    protected:
360
    // 0 <= num_long_metrics <= num_bearings <= num_advances <= num_glyphs
361
    unsigned num_long_metrics;
362
    unsigned num_bearings;
363
    unsigned num_advances;
364
    unsigned num_glyphs;
365
366
    unsigned int default_advance;
367
368
    public:
369
    hb_blob_ptr_t<hmtxvmtx> table;
370
    hb_blob_ptr_t<V> var_table;
371
372
    private:
373
    static unsigned get_num_long_metrics (hb_face_t *face)
374
0
    {
375
0
      hb_blob_ptr_t<H> hea = hb_sanitize_context_t ().reference_table<H> (face);
376
0
      unsigned ret = hea->numberOfLongMetrics;
377
0
      hea.destroy ();
378
0
      return ret;
379
0
    }
Unexecuted instantiation: OT::hmtxvmtx<OT::hmtx, OT::hhea, OT::HVAR>::accelerator_t::get_num_long_metrics(hb_face_t*)
Unexecuted instantiation: OT::hmtxvmtx<OT::vmtx, OT::vhea, OT::VVAR>::accelerator_t::get_num_long_metrics(hb_face_t*)
380
  };
381
382
  /* get advance: when no variations, call get_advance_without_var_unscaled.
383
   * when there're variations, get advance value from mtx_map in subset_plan*/
384
  unsigned get_new_gid_advance_unscaled (const hb_subset_plan_t *plan,
385
                                         const hb_hashmap_t<hb_codepoint_t, hb_pair_t<unsigned, int>> *mtx_map,
386
                                         unsigned new_gid,
387
                                         const accelerator_t &_mtx) const
388
  {
389
    if (mtx_map->is_empty ())
390
    {
391
      hb_codepoint_t old_gid = 0;
392
      return plan->old_gid_for_new_gid (new_gid, &old_gid) ?
393
             _mtx.get_advance_without_var_unscaled (old_gid) : 0;
394
    }
395
    return mtx_map->get (new_gid).first;
396
  }
397
398
  protected:
399
  UnsizedArrayOf<LongMetric>
400
    longMetricZ;  /* Paired advance width and leading
401
         * bearing values for each glyph. The
402
         * value numOfHMetrics comes from
403
         * the 'hhea' table. If the font is
404
         * monospaced, only one entry need
405
         * be in the array, but that entry is
406
         * required. The last entry applies to
407
         * all subsequent glyphs. */
408
/*UnsizedArrayOf<FWORD> leadingBearingX;*/
409
        /* Here the advance is assumed
410
         * to be the same as the advance
411
         * for the last entry above. The
412
         * number of entries in this array is
413
         * derived from numGlyphs (from 'maxp'
414
         * table) minus numberOfLongMetrics.
415
         * This generally is used with a run
416
         * of monospaced glyphs (e.g., Kanji
417
         * fonts or Courier fonts). Only one
418
         * run is allowed and it must be at
419
         * the end. This allows a monospaced
420
         * font to vary the side bearing
421
         * values for each glyph. */
422
/*UnsizedArrayOf<UFWORD>advancesX;*/
423
        /* TODO Document. */
424
  public:
425
  DEFINE_SIZE_ARRAY (0, longMetricZ);
426
};
427
428
struct hmtx : hmtxvmtx<hmtx, hhea, HVAR> {
429
  static constexpr hb_tag_t tableTag = HB_OT_TAG_hmtx;
430
  static constexpr hb_tag_t variationsTag = HB_OT_TAG_HVAR;
431
  static constexpr bool is_horizontal = true;
432
};
433
struct HMTX : hmtxvmtx<HMTX, HHEA, HVAR> {
434
  static constexpr hb_tag_t tableTag = HB_OT_TAG_HMTX;
435
  static constexpr hb_tag_t variationsTag = HB_OT_TAG_HVAR;
436
  static constexpr bool is_horizontal = true;
437
};
438
struct vmtx : hmtxvmtx<vmtx, vhea, VVAR> {
439
  static constexpr hb_tag_t tableTag = HB_OT_TAG_vmtx;
440
  static constexpr hb_tag_t variationsTag = HB_OT_TAG_VVAR;
441
  static constexpr bool is_horizontal = false;
442
};
443
struct VMTX : hmtxvmtx<VMTX, VHEA, VVAR> {
444
  static constexpr hb_tag_t tableTag = HB_OT_TAG_VMTX;
445
  static constexpr hb_tag_t variationsTag = HB_OT_TAG_VVAR;
446
  static constexpr bool is_horizontal = false;
447
};
448
449
struct hmtx_accelerator_t : hb_dual_accelerator_t<hmtx::accelerator_t,
450
              HMTX::accelerator_t>
451
{
452
  hmtx_accelerator_t (hb_face_t *face) :
453
0
    hb_dual_accelerator_t<hmtx::accelerator_t, HMTX::accelerator_t> (face)
454
0
  {
455
0
    var_table = hb_sanitize_context_t ().reference_table<HVAR> (face);
456
0
  }
457
458
  ~hmtx_accelerator_t ()
459
0
  {
460
0
    var_table.destroy ();
461
0
  }
462
463
  void get_leading_bearing_without_var_unscaled (hb_codepoint_t glyph,
464
             int *lsb) const
465
0
  {
466
0
    HB_DUAL_GET (*this, get_leading_bearing_without_var_unscaled (glyph, lsb));
467
0
  }
468
469
  unsigned int get_advance_without_var_unscaled (hb_codepoint_t glyph) const
470
0
  {
471
0
    return HB_DUAL_GET (*this, get_advance_without_var_unscaled (glyph));
472
0
  }
473
474
#ifndef HB_NO_VAR
475
  unsigned get_advance_with_var_unscaled (hb_codepoint_t     glyph,
476
            hb_font_t         *font,
477
            hb_scalar_cache_t *store_cache = nullptr) const
478
0
  {
479
0
    unsigned int advance = get_advance_without_var_unscaled (glyph);
480
0
    return hb_clamp_to<unsigned> (advance + roundf (var_table->get_advance_delta_unscaled (glyph,
481
0
                    font->coords, font->num_coords,
482
0
                    store_cache)));
483
0
  }
484
#endif
485
486
  hb_blob_ptr_t<HVAR> var_table;
487
};
488
489
#ifndef HB_NO_VERTICAL
490
struct vmtx_accelerator_t : hb_dual_accelerator_t<vmtx::accelerator_t,
491
              VMTX::accelerator_t>
492
{
493
  vmtx_accelerator_t (hb_face_t *face) :
494
0
    hb_dual_accelerator_t<vmtx::accelerator_t, VMTX::accelerator_t> (face)
495
0
  {
496
0
    var_table = hb_sanitize_context_t ().reference_table<VVAR> (face);
497
0
  }
498
499
  ~vmtx_accelerator_t ()
500
0
  {
501
0
    var_table.destroy ();
502
0
  }
503
504
  void get_leading_bearing_without_var_unscaled (hb_codepoint_t glyph,
505
             int *lsb) const
506
0
  {
507
0
    HB_DUAL_GET (*this, get_leading_bearing_without_var_unscaled (glyph, lsb));
508
0
  }
509
510
  unsigned int get_advance_without_var_unscaled (hb_codepoint_t glyph) const
511
0
  {
512
0
    return HB_DUAL_GET (*this, get_advance_without_var_unscaled (glyph));
513
0
  }
514
515
#ifndef HB_NO_VAR
516
  unsigned get_advance_with_var_unscaled (hb_codepoint_t     glyph,
517
            hb_font_t         *font,
518
            hb_scalar_cache_t *store_cache = nullptr) const
519
0
  {
520
0
    unsigned int advance = get_advance_without_var_unscaled (glyph);
521
0
    return hb_clamp_to<unsigned> (advance + roundf (var_table->get_advance_delta_unscaled (glyph,
522
0
                    font->coords, font->num_coords,
523
0
                    store_cache)));
524
0
  }
525
#endif
526
527
  hb_blob_ptr_t<VVAR> var_table;
528
};
529
#else
530
struct vmtx_accelerator_t : vmtx::accelerator_t {
531
  vmtx_accelerator_t (hb_face_t *face) : vmtx::accelerator_t (face) {}
532
};
533
#endif
534
535
} /* namespace OT */
536
537
538
#endif /* HB_OT_HMTX_TABLE_HH */