Coverage Report

Created: 2021-08-22 09:07

/src/skia/third_party/externals/harfbuzz/src/hb-ot-layout-gdef-table.hh
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2007,2008,2009  Red Hat, Inc.
3
 * Copyright © 2010,2011,2012  Google, Inc.
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
 * Red Hat Author(s): Behdad Esfahbod
26
 * Google Author(s): Behdad Esfahbod
27
 */
28
29
#ifndef HB_OT_LAYOUT_GDEF_TABLE_HH
30
#define HB_OT_LAYOUT_GDEF_TABLE_HH
31
32
#include "hb-ot-layout-common.hh"
33
34
#include "hb-font.hh"
35
36
37
namespace OT {
38
39
40
/*
41
 * Attachment List Table
42
 */
43
44
/* Array of contour point indices--in increasing numerical order */
45
struct AttachPoint : Array16Of<HBUINT16>
46
{
47
  bool subset (hb_subset_context_t *c) const
48
0
  {
49
0
    TRACE_SUBSET (this);
50
0
    auto *out = c->serializer->start_embed (*this);
51
0
    if (unlikely (!out)) return_trace (false);
52
53
0
    return_trace (out->serialize (c->serializer, + iter ()));
54
0
  }
Unexecuted instantiation: OT::AttachPoint::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::AttachPoint::subset(hb_subset_context_t*) const
55
};
56
57
struct AttachList
58
{
59
  unsigned int get_attach_points (hb_codepoint_t glyph_id,
60
          unsigned int start_offset,
61
          unsigned int *point_count /* IN/OUT */,
62
          unsigned int *point_array /* OUT */) const
63
0
  {
64
0
    unsigned int index = (this+coverage).get_coverage (glyph_id);
65
0
    if (index == NOT_COVERED)
66
0
    {
67
0
      if (point_count)
68
0
  *point_count = 0;
69
0
      return 0;
70
0
    }
71
72
0
    const AttachPoint &points = this+attachPoint[index];
73
74
0
    if (point_count)
75
0
    {
76
0
      + points.sub_array (start_offset, point_count)
77
0
      | hb_sink (hb_array (point_array, *point_count))
78
0
      ;
79
0
    }
80
81
0
    return points.len;
82
0
  }
83
84
  bool subset (hb_subset_context_t *c) const
85
0
  {
86
0
    TRACE_SUBSET (this);
87
0
    const hb_set_t &glyphset = *c->plan->glyphset ();
88
0
    const hb_map_t &glyph_map = *c->plan->glyph_map;
89
90
0
    auto *out = c->serializer->start_embed (*this);
91
0
    if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
92
93
0
    hb_sorted_vector_t<hb_codepoint_t> new_coverage;
94
0
    + hb_zip (this+coverage, attachPoint)
95
0
    | hb_filter (glyphset, hb_first)
96
0
    | hb_filter (subset_offset_array (c, out->attachPoint, this), hb_second)
97
0
    | hb_map (hb_first)
98
0
    | hb_map (glyph_map)
99
0
    | hb_sink (new_coverage)
100
0
    ;
101
0
    out->coverage.serialize_serialize (c->serializer, new_coverage.iter ());
102
0
    return_trace (bool (new_coverage));
103
0
  }
Unexecuted instantiation: OT::AttachList::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::AttachList::subset(hb_subset_context_t*) const
104
105
  bool sanitize (hb_sanitize_context_t *c) const
106
0
  {
107
0
    TRACE_SANITIZE (this);
108
0
    return_trace (coverage.sanitize (c, this) && attachPoint.sanitize (c, this));
109
0
  }
110
111
  protected:
112
  Offset16To<Coverage>
113
    coverage;   /* Offset to Coverage table -- from
114
           * beginning of AttachList table */
115
  Array16OfOffset16To<AttachPoint>
116
    attachPoint;    /* Array of AttachPoint tables
117
           * in Coverage Index order */
118
  public:
119
  DEFINE_SIZE_ARRAY (4, attachPoint);
120
};
121
122
/*
123
 * Ligature Caret Table
124
 */
125
126
struct CaretValueFormat1
127
{
128
  friend struct CaretValue;
129
  bool subset (hb_subset_context_t *c) const
130
0
  {
131
0
    TRACE_SUBSET (this);
132
0
    auto *out = c->serializer->embed (this);
133
0
    if (unlikely (!out)) return_trace (false);
134
0
    return_trace (true);
135
0
  }
Unexecuted instantiation: OT::CaretValueFormat1::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::CaretValueFormat1::subset(hb_subset_context_t*) const
136
137
  private:
138
  hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction) const
139
0
  {
140
0
    return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate);
141
0
  }
142
143
  bool sanitize (hb_sanitize_context_t *c) const
144
0
  {
145
0
    TRACE_SANITIZE (this);
146
0
    return_trace (c->check_struct (this));
147
0
  }
148
149
  protected:
150
  HBUINT16  caretValueFormat; /* Format identifier--format = 1 */
151
  FWORD   coordinate;   /* X or Y value, in design units */
152
  public:
153
  DEFINE_SIZE_STATIC (4);
154
};
155
156
struct CaretValueFormat2
157
{
158
  friend struct CaretValue;
159
  bool subset (hb_subset_context_t *c) const
160
0
  {
161
0
    TRACE_SUBSET (this);
162
0
    auto *out = c->serializer->embed (this);
163
0
    if (unlikely (!out)) return_trace (false);
164
0
    return_trace (true);
165
0
  }
Unexecuted instantiation: OT::CaretValueFormat2::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::CaretValueFormat2::subset(hb_subset_context_t*) const
166
167
  private:
168
  hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
169
0
  {
170
0
    hb_position_t x, y;
171
0
    font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y);
172
0
    return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
173
0
  }
174
175
  bool sanitize (hb_sanitize_context_t *c) const
176
0
  {
177
0
    TRACE_SANITIZE (this);
178
0
    return_trace (c->check_struct (this));
179
0
  }
180
181
  protected:
182
  HBUINT16  caretValueFormat; /* Format identifier--format = 2 */
183
  HBUINT16  caretValuePoint;  /* Contour point index on glyph */
184
  public:
185
  DEFINE_SIZE_STATIC (4);
186
};
187
188
struct CaretValueFormat3
189
{
190
  friend struct CaretValue;
191
192
  hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction,
193
         const VariationStore &var_store) const
194
0
  {
195
0
    return HB_DIRECTION_IS_HORIZONTAL (direction) ?
196
0
     font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font, var_store) :
197
0
     font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font, var_store);
198
0
  }
199
200
  bool subset (hb_subset_context_t *c) const
201
0
  {
202
0
    TRACE_SUBSET (this);
203
0
    auto *out = c->serializer->embed (this);
204
0
    if (unlikely (!out)) return_trace (false);
205
206
0
    return_trace (out->deviceTable.serialize_copy (c->serializer, deviceTable, this, c->serializer->to_bias (out),
207
0
               hb_serialize_context_t::Head, c->plan->layout_variation_idx_map));
208
0
  }
Unexecuted instantiation: OT::CaretValueFormat3::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::CaretValueFormat3::subset(hb_subset_context_t*) const
209
210
  void collect_variation_indices (hb_set_t *layout_variation_indices) const
211
0
  { (this+deviceTable).collect_variation_indices (layout_variation_indices); }
212
213
  bool sanitize (hb_sanitize_context_t *c) const
214
0
  {
215
0
    TRACE_SANITIZE (this);
216
0
    return_trace (c->check_struct (this) && deviceTable.sanitize (c, this));
217
0
  }
218
219
  protected:
220
  HBUINT16  caretValueFormat; /* Format identifier--format = 3 */
221
  FWORD   coordinate;   /* X or Y value, in design units */
222
  Offset16To<Device>
223
    deviceTable;    /* Offset to Device table for X or Y
224
           * value--from beginning of CaretValue
225
           * table */
226
  public:
227
  DEFINE_SIZE_STATIC (6);
228
};
229
230
struct CaretValue
231
{
232
  hb_position_t get_caret_value (hb_font_t *font,
233
         hb_direction_t direction,
234
         hb_codepoint_t glyph_id,
235
         const VariationStore &var_store) const
236
0
  {
237
0
    switch (u.format) {
238
0
    case 1: return u.format1.get_caret_value (font, direction);
239
0
    case 2: return u.format2.get_caret_value (font, direction, glyph_id);
240
0
    case 3: return u.format3.get_caret_value (font, direction, var_store);
241
0
    default:return 0;
242
0
    }
243
0
  }
244
245
  template <typename context_t, typename ...Ts>
246
  typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const
247
0
  {
248
0
    TRACE_DISPATCH (this, u.format);
249
0
    if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
250
0
    switch (u.format) {
251
0
    case 1: return_trace (c->dispatch (u.format1, hb_forward<Ts> (ds)...));
252
0
    case 2: return_trace (c->dispatch (u.format2, hb_forward<Ts> (ds)...));
253
0
    case 3: return_trace (c->dispatch (u.format3, hb_forward<Ts> (ds)...));
254
0
    default:return_trace (c->default_return_value ());
255
0
    }
256
0
  }
Unexecuted instantiation: hb_subset_context_t::return_t OT::CaretValue::dispatch<hb_subset_context_t>(hb_subset_context_t*) const
Unexecuted instantiation: hb_subset_context_t::return_t OT::CaretValue::dispatch<hb_subset_context_t>(hb_subset_context_t*) const
257
258
  void collect_variation_indices (hb_set_t *layout_variation_indices) const
259
0
  {
260
0
    switch (u.format) {
261
0
    case 1:
262
0
    case 2:
263
0
      return;
264
0
    case 3:
265
0
      u.format3.collect_variation_indices (layout_variation_indices);
266
0
      return;
267
0
    default: return;
268
0
    }
269
0
  }
270
271
  bool sanitize (hb_sanitize_context_t *c) const
272
0
  {
273
0
    TRACE_SANITIZE (this);
274
0
    if (!u.format.sanitize (c)) return_trace (false);
275
0
    switch (u.format) {
276
0
    case 1: return_trace (u.format1.sanitize (c));
277
0
    case 2: return_trace (u.format2.sanitize (c));
278
0
    case 3: return_trace (u.format3.sanitize (c));
279
0
    default:return_trace (true);
280
0
    }
281
0
  }
282
283
  protected:
284
  union {
285
  HBUINT16    format;   /* Format identifier */
286
  CaretValueFormat1 format1;
287
  CaretValueFormat2 format2;
288
  CaretValueFormat3 format3;
289
  } u;
290
  public:
291
  DEFINE_SIZE_UNION (2, format);
292
};
293
294
struct LigGlyph
295
{
296
  unsigned get_lig_carets (hb_font_t            *font,
297
         hb_direction_t        direction,
298
         hb_codepoint_t        glyph_id,
299
         const VariationStore &var_store,
300
         unsigned              start_offset,
301
         unsigned             *caret_count /* IN/OUT */,
302
         hb_position_t        *caret_array /* OUT */) const
303
0
  {
304
0
    if (caret_count)
305
0
    {
306
0
      + carets.sub_array (start_offset, caret_count)
307
0
      | hb_map (hb_add (this))
308
0
      | hb_map ([&] (const CaretValue &value) { return value.get_caret_value (font, direction, glyph_id, var_store); })
309
0
      | hb_sink (hb_array (caret_array, *caret_count))
310
0
      ;
311
0
    }
312
313
0
    return carets.len;
314
0
  }
315
316
  bool subset (hb_subset_context_t *c) const
317
0
  {
318
0
    TRACE_SUBSET (this);
319
0
    auto *out = c->serializer->start_embed (*this);
320
0
    if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
321
322
0
    + hb_iter (carets)
323
0
    | hb_apply (subset_offset_array (c, out->carets, this))
324
0
    ;
325
326
0
    return_trace (bool (out->carets));
327
0
  }
Unexecuted instantiation: OT::LigGlyph::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::LigGlyph::subset(hb_subset_context_t*) const
328
329
  void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
330
0
  {
331
0
    for (const Offset16To<CaretValue>& offset : carets.iter ())
332
0
      (this+offset).collect_variation_indices (c->layout_variation_indices);
333
0
  }
334
335
  bool sanitize (hb_sanitize_context_t *c) const
336
0
  {
337
0
    TRACE_SANITIZE (this);
338
0
    return_trace (carets.sanitize (c, this));
339
0
  }
340
341
  protected:
342
  Array16OfOffset16To<CaretValue>
343
    carets;     /* Offset array of CaretValue tables
344
           * --from beginning of LigGlyph table
345
           * --in increasing coordinate order */
346
  public:
347
  DEFINE_SIZE_ARRAY (2, carets);
348
};
349
350
struct LigCaretList
351
{
352
  unsigned int get_lig_carets (hb_font_t *font,
353
             hb_direction_t direction,
354
             hb_codepoint_t glyph_id,
355
             const VariationStore &var_store,
356
             unsigned int start_offset,
357
             unsigned int *caret_count /* IN/OUT */,
358
             hb_position_t *caret_array /* OUT */) const
359
0
  {
360
0
    unsigned int index = (this+coverage).get_coverage (glyph_id);
361
0
    if (index == NOT_COVERED)
362
0
    {
363
0
      if (caret_count)
364
0
  *caret_count = 0;
365
0
      return 0;
366
0
    }
367
0
    const LigGlyph &lig_glyph = this+ligGlyph[index];
368
0
    return lig_glyph.get_lig_carets (font, direction, glyph_id, var_store, start_offset, caret_count, caret_array);
369
0
  }
370
371
  bool subset (hb_subset_context_t *c) const
372
0
  {
373
0
    TRACE_SUBSET (this);
374
0
    const hb_set_t &glyphset = *c->plan->glyphset ();
375
0
    const hb_map_t &glyph_map = *c->plan->glyph_map;
376
377
0
    auto *out = c->serializer->start_embed (*this);
378
0
    if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
379
380
0
    hb_sorted_vector_t<hb_codepoint_t> new_coverage;
381
0
    + hb_zip (this+coverage, ligGlyph)
382
0
    | hb_filter (glyphset, hb_first)
383
0
    | hb_filter (subset_offset_array (c, out->ligGlyph, this), hb_second)
384
0
    | hb_map (hb_first)
385
0
    | hb_map (glyph_map)
386
0
    | hb_sink (new_coverage)
387
0
    ;
388
0
    out->coverage.serialize_serialize (c->serializer, new_coverage.iter ());
389
0
    return_trace (bool (new_coverage));
390
0
  }
Unexecuted instantiation: OT::LigCaretList::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::LigCaretList::subset(hb_subset_context_t*) const
391
392
  void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
393
0
  {
394
0
    + hb_zip (this+coverage, ligGlyph)
395
0
    | hb_filter (c->glyph_set, hb_first)
396
0
    | hb_map (hb_second)
397
0
    | hb_map (hb_add (this))
398
0
    | hb_apply ([c] (const LigGlyph& _) { _.collect_variation_indices (c); })
399
0
    ;
400
0
  }
401
402
  bool sanitize (hb_sanitize_context_t *c) const
403
0
  {
404
0
    TRACE_SANITIZE (this);
405
0
    return_trace (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this));
406
0
  }
407
408
  protected:
409
  Offset16To<Coverage>
410
    coverage;   /* Offset to Coverage table--from
411
           * beginning of LigCaretList table */
412
  Array16OfOffset16To<LigGlyph>
413
    ligGlyph;   /* Array of LigGlyph tables
414
           * in Coverage Index order */
415
  public:
416
  DEFINE_SIZE_ARRAY (4, ligGlyph);
417
};
418
419
420
struct MarkGlyphSetsFormat1
421
{
422
  bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
423
0
  { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
424
425
  bool subset (hb_subset_context_t *c) const
426
0
  {
427
0
    TRACE_SUBSET (this);
428
0
    auto *out = c->serializer->start_embed (*this);
429
0
    if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
430
0
    out->format = format;
431
432
0
    bool ret = true;
433
0
    for (const Offset32To<Coverage>& offset : coverage.iter ())
434
0
    {
435
0
      auto *o = out->coverage.serialize_append (c->serializer);
436
0
      if (unlikely (!o))
437
0
      {
438
0
  ret = false;
439
0
  break;
440
0
      }
441
442
      //not using o->serialize_subset (c, offset, this, out) here because
443
      //OTS doesn't allow null offset.
444
      //See issue: https://github.com/khaledhosny/ots/issues/172
445
0
      c->serializer->push ();
446
0
      c->dispatch (this+offset);
447
0
      c->serializer->add_link (*o, c->serializer->pop_pack ());
448
0
    }
449
450
0
    return_trace (ret && out->coverage.len);
451
0
  }
Unexecuted instantiation: OT::MarkGlyphSetsFormat1::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::MarkGlyphSetsFormat1::subset(hb_subset_context_t*) const
452
453
  bool sanitize (hb_sanitize_context_t *c) const
454
0
  {
455
0
    TRACE_SANITIZE (this);
456
0
    return_trace (coverage.sanitize (c, this));
457
0
  }
458
459
  protected:
460
  HBUINT16  format;     /* Format identifier--format = 1 */
461
  Array16Of<Offset32To<Coverage>>
462
    coverage;   /* Array of long offsets to mark set
463
           * coverage tables */
464
  public:
465
  DEFINE_SIZE_ARRAY (4, coverage);
466
};
467
468
struct MarkGlyphSets
469
{
470
  bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
471
0
  {
472
0
    switch (u.format) {
473
0
    case 1: return u.format1.covers (set_index, glyph_id);
474
0
    default:return false;
475
0
    }
476
0
  }
477
478
  bool subset (hb_subset_context_t *c) const
479
0
  {
480
0
    TRACE_SUBSET (this);
481
0
    switch (u.format) {
482
0
    case 1: return_trace (u.format1.subset (c));
483
0
    default:return_trace (false);
484
0
    }
485
0
  }
Unexecuted instantiation: OT::MarkGlyphSets::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::MarkGlyphSets::subset(hb_subset_context_t*) const
486
487
  bool sanitize (hb_sanitize_context_t *c) const
488
0
  {
489
0
    TRACE_SANITIZE (this);
490
0
    if (!u.format.sanitize (c)) return_trace (false);
491
0
    switch (u.format) {
492
0
    case 1: return_trace (u.format1.sanitize (c));
493
0
    default:return_trace (true);
494
0
    }
495
0
  }
496
497
  protected:
498
  union {
499
  HBUINT16    format;   /* Format identifier */
500
  MarkGlyphSetsFormat1  format1;
501
  } u;
502
  public:
503
  DEFINE_SIZE_UNION (2, format);
504
};
505
506
507
/*
508
 * GDEF -- Glyph Definition
509
 * https://docs.microsoft.com/en-us/typography/opentype/spec/gdef
510
 */
511
512
513
struct GDEF
514
{
515
  static constexpr hb_tag_t tableTag = HB_OT_TAG_GDEF;
516
517
  enum GlyphClasses {
518
    UnclassifiedGlyph = 0,
519
    BaseGlyph   = 1,
520
    LigatureGlyph = 2,
521
    MarkGlyph   = 3,
522
    ComponentGlyph  = 4
523
  };
524
525
0
  bool has_data () const { return version.to_int (); }
526
623k
  bool has_glyph_classes () const { return glyphClassDef != 0; }
527
  unsigned int get_glyph_class (hb_codepoint_t glyph) const
528
8.68M
  { return (this+glyphClassDef).get_class (glyph); }
529
  void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const
530
0
  { (this+glyphClassDef).collect_class (glyphs, klass); }
531
532
0
  bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
533
  unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const
534
0
  { return (this+markAttachClassDef).get_class (glyph); }
535
536
0
  bool has_attach_points () const { return attachList != 0; }
537
  unsigned int get_attach_points (hb_codepoint_t glyph_id,
538
          unsigned int start_offset,
539
          unsigned int *point_count /* IN/OUT */,
540
          unsigned int *point_array /* OUT */) const
541
0
  { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
542
543
0
  bool has_lig_carets () const { return ligCaretList != 0; }
544
  unsigned int get_lig_carets (hb_font_t *font,
545
             hb_direction_t direction,
546
             hb_codepoint_t glyph_id,
547
             unsigned int start_offset,
548
             unsigned int *caret_count /* IN/OUT */,
549
             hb_position_t *caret_array /* OUT */) const
550
0
  { return (this+ligCaretList).get_lig_carets (font,
551
0
                 direction, glyph_id, get_var_store(),
552
0
                 start_offset, caret_count, caret_array); }
553
554
0
  bool has_mark_sets () const { return version.to_int () >= 0x00010002u && markGlyphSetsDef != 0; }
555
  bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
556
0
  { return version.to_int () >= 0x00010002u && (this+markGlyphSetsDef).covers (set_index, glyph_id); }
557
558
0
  bool has_var_store () const { return version.to_int () >= 0x00010003u && varStore != 0; }
559
  const VariationStore &get_var_store () const
560
623k
  { return version.to_int () >= 0x00010003u ? this+varStore : Null (VariationStore); }
561
562
  /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing
563
   * glyph class and other bits, and high 8-bit the mark attachment type (if any).
564
   * Not to be confused with lookup_props which is very similar. */
565
  unsigned int get_glyph_props (hb_codepoint_t glyph) const
566
8.68M
  {
567
8.68M
    unsigned int klass = get_glyph_class (glyph);
568
569
8.68M
    static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs), "");
570
8.68M
    static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures), "");
571
8.68M
    static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks), "");
572
573
8.68M
    switch (klass) {
574
8.68M
    default:      return 0;
575
0
    case BaseGlyph:   return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH;
576
0
    case LigatureGlyph:   return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
577
0
    case MarkGlyph:
578
0
    klass = get_mark_attachment_type (glyph);
579
0
    return HB_OT_LAYOUT_GLYPH_PROPS_MARK | (klass << 8);
580
8.68M
    }
581
8.68M
  }
582
583
  HB_INTERNAL bool is_blocklisted (hb_blob_t *blob,
584
           hb_face_t *face) const;
585
586
  struct accelerator_t
587
  {
588
    void init (hb_face_t *face)
589
1
    {
590
1
      this->table = hb_sanitize_context_t ().reference_table<GDEF> (face);
591
1
      if (unlikely (this->table->is_blocklisted (this->table.get_blob (), face)))
592
0
      {
593
0
  hb_blob_destroy (this->table.get_blob ());
594
0
  this->table = hb_blob_get_empty ();
595
0
      }
596
1
    }
597
598
1
    void fini () { this->table.destroy (); }
599
600
    hb_blob_ptr_t<GDEF> table;
601
  };
602
603
  unsigned int get_size () const
604
0
  {
605
0
    return min_size +
606
0
     (version.to_int () >= 0x00010002u ? markGlyphSetsDef.static_size : 0) +
607
0
     (version.to_int () >= 0x00010003u ? varStore.static_size : 0);
608
0
  }
609
610
  void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
611
0
  { (this+ligCaretList).collect_variation_indices (c); }
612
613
  void remap_layout_variation_indices (const hb_set_t *layout_variation_indices,
614
               hb_map_t *layout_variation_idx_map /* OUT */) const
615
0
  {
616
0
    if (version.to_int () < 0x00010003u || !varStore) return;
617
0
    if (layout_variation_indices->is_empty ()) return;
618
0
619
0
    unsigned new_major = 0, new_minor = 0;
620
0
    unsigned last_major = (layout_variation_indices->get_min ()) >> 16;
621
0
    for (unsigned idx : layout_variation_indices->iter ())
622
0
    {
623
0
      uint16_t major = idx >> 16;
624
0
      if (major >= (this+varStore).get_sub_table_count ()) break;
625
0
      if (major != last_major)
626
0
      {
627
0
  new_minor = 0;
628
0
  ++new_major;
629
0
      }
630
0
631
0
      unsigned new_idx = (new_major << 16) + new_minor;
632
0
      layout_variation_idx_map->set (idx, new_idx);
633
0
      ++new_minor;
634
0
      last_major = major;
635
0
    }
636
0
  }
637
638
  bool subset (hb_subset_context_t *c) const
639
0
  {
640
0
    TRACE_SUBSET (this);
641
0
    auto *out = c->serializer->embed (*this);
642
0
    if (unlikely (!out)) return_trace (false);
643
644
0
    bool subset_glyphclassdef = out->glyphClassDef.serialize_subset (c, glyphClassDef, this, nullptr, false, true);
645
0
    bool subset_attachlist = out->attachList.serialize_subset (c, attachList, this);
646
0
    bool subset_ligcaretlist = out->ligCaretList.serialize_subset (c, ligCaretList, this);
647
0
    bool subset_markattachclassdef = out->markAttachClassDef.serialize_subset (c, markAttachClassDef, this, nullptr, false, true);
648
649
0
    bool subset_markglyphsetsdef = true;
650
0
    if (version.to_int () >= 0x00010002u)
651
0
    {
652
0
      subset_markglyphsetsdef = out->markGlyphSetsDef.serialize_subset (c, markGlyphSetsDef, this);
653
0
      if (!subset_markglyphsetsdef &&
654
0
    version.to_int () == 0x00010002u)
655
0
  out->version.minor = 0;
656
0
    }
657
658
0
    bool subset_varstore = true;
659
0
    if (version.to_int () >= 0x00010003u)
660
0
    {
661
0
      subset_varstore = out->varStore.serialize_subset (c, varStore, this);
662
0
      if (!subset_varstore && version.to_int () == 0x00010003u)
663
0
  out->version.minor = 2;
664
0
    }
665
666
0
    return_trace (subset_glyphclassdef || subset_attachlist ||
667
0
      subset_ligcaretlist || subset_markattachclassdef ||
668
0
      (out->version.to_int () >= 0x00010002u && subset_markglyphsetsdef) ||
669
0
      (out->version.to_int () >= 0x00010003u && subset_varstore));
670
0
  }
Unexecuted instantiation: OT::GDEF::subset(hb_subset_context_t*) const
Unexecuted instantiation: OT::GDEF::subset(hb_subset_context_t*) const
671
672
  bool sanitize (hb_sanitize_context_t *c) const
673
0
  {
674
0
    TRACE_SANITIZE (this);
675
0
    return_trace (version.sanitize (c) &&
676
0
      likely (version.major == 1) &&
677
0
      glyphClassDef.sanitize (c, this) &&
678
0
      attachList.sanitize (c, this) &&
679
0
      ligCaretList.sanitize (c, this) &&
680
0
      markAttachClassDef.sanitize (c, this) &&
681
0
      (version.to_int () < 0x00010002u || markGlyphSetsDef.sanitize (c, this)) &&
682
0
      (version.to_int () < 0x00010003u || varStore.sanitize (c, this)));
683
0
  }
684
685
  protected:
686
  FixedVersion<>version;    /* Version of the GDEF table--currently
687
           * 0x00010003u */
688
  Offset16To<ClassDef>
689
    glyphClassDef;    /* Offset to class definition table
690
           * for glyph type--from beginning of
691
           * GDEF header (may be Null) */
692
  Offset16To<AttachList>
693
    attachList;   /* Offset to list of glyphs with
694
           * attachment points--from beginning
695
           * of GDEF header (may be Null) */
696
  Offset16To<LigCaretList>
697
    ligCaretList;   /* Offset to list of positioning points
698
           * for ligature carets--from beginning
699
           * of GDEF header (may be Null) */
700
  Offset16To<ClassDef>
701
    markAttachClassDef; /* Offset to class definition table for
702
           * mark attachment type--from beginning
703
           * of GDEF header (may be Null) */
704
  Offset16To<MarkGlyphSets>
705
    markGlyphSetsDef; /* Offset to the table of mark set
706
           * definitions--from beginning of GDEF
707
           * header (may be NULL).  Introduced
708
           * in version 0x00010002. */
709
  Offset32To<VariationStore>
710
    varStore;   /* Offset to the table of Item Variation
711
           * Store--from beginning of GDEF
712
           * header (may be NULL).  Introduced
713
           * in version 0x00010003. */
714
  public:
715
  DEFINE_SIZE_MIN (12);
716
};
717
718
struct GDEF_accelerator_t : GDEF::accelerator_t {};
719
720
} /* namespace OT */
721
722
723
#endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */