Coverage Report

Created: 2025-10-28 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/OT/Layout/GSUB/AlternateSubstFormat1.hh
Line
Count
Source
1
#ifndef OT_LAYOUT_GSUB_ALTERNATESUBSTFORMAT1_HH
2
#define OT_LAYOUT_GSUB_ALTERNATESUBSTFORMAT1_HH
3
4
#include "AlternateSet.hh"
5
#include "Common.hh"
6
7
namespace OT {
8
namespace Layout {
9
namespace GSUB_impl {
10
11
template <typename Types>
12
struct AlternateSubstFormat1_2
13
{
14
  protected:
15
  HBUINT16      format;                 /* Format identifier--format = 1 */
16
  typename Types::template OffsetTo<Coverage>
17
                coverage;               /* Offset to Coverage table--from
18
                                         * beginning of Substitution table */
19
  Array16Of<typename Types::template OffsetTo<AlternateSet<Types>>>
20
                alternateSet;           /* Array of AlternateSet tables
21
                                         * ordered by Coverage Index */
22
  public:
23
  DEFINE_SIZE_ARRAY (2 + 2 * Types::size, alternateSet);
24
25
  bool sanitize (hb_sanitize_context_t *c) const
26
3.56k
  {
27
3.56k
    TRACE_SANITIZE (this);
28
3.56k
    return_trace (coverage.sanitize (c, this) && alternateSet.sanitize (c, this));
29
3.56k
  }
30
31
  bool intersects (const hb_set_t *glyphs) const
32
0
  { return (this+coverage).intersects (glyphs); }
33
34
  bool may_have_non_1to1 () const
35
0
  { return false; }
36
37
  void closure (hb_closure_context_t *c) const
38
0
  {
39
0
    + hb_zip (this+coverage, alternateSet)
40
0
    | hb_filter (c->parent_active_glyphs (), hb_first)
41
0
    | hb_map (hb_second)
42
0
    | hb_map (hb_add (this))
43
0
    | hb_apply ([c] (const AlternateSet<Types> &_) { _.closure (c); })
44
0
    ;
45
0
  }
46
47
0
  void closure_lookups (hb_closure_lookups_context_t *c) const {}
48
49
  void collect_glyphs (hb_collect_glyphs_context_t *c) const
50
0
  {
51
0
    if (unlikely (!(this+coverage).collect_coverage (c->input))) return;
52
0
    + hb_zip (this+coverage, alternateSet)
53
0
    | hb_map (hb_second)
54
0
    | hb_map (hb_add (this))
55
0
    | hb_apply ([c] (const AlternateSet<Types> &_) { _.collect_glyphs (c); })
56
0
    ;
57
0
  }
58
59
0
  const Coverage &get_coverage () const { return this+coverage; }
60
61
  bool would_apply (hb_would_apply_context_t *c) const
62
0
  { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; }
63
64
  unsigned
65
  get_glyph_alternates (hb_codepoint_t  gid,
66
                        unsigned        start_offset,
67
                        unsigned       *alternate_count  /* IN/OUT.  May be NULL. */,
68
                        hb_codepoint_t *alternate_glyphs /* OUT.     May be NULL. */) const
69
0
  { return (this+alternateSet[(this+coverage).get_coverage (gid)])
70
0
           .get_alternates (start_offset, alternate_count, alternate_glyphs); }
71
72
  void
73
  collect_glyph_alternates (hb_map_t  *alternate_count /* IN/OUT */,
74
          hb_map_t  *alternate_glyphs /* IN/OUT */) const
75
0
  {
76
0
    + hb_iter (alternateSet)
77
0
    | hb_map (hb_add (this))
78
0
    | hb_zip (this+coverage)
79
0
    | hb_apply ([&] (const hb_pair_t<const AlternateSet<Types> &, hb_codepoint_t> _) {
80
0
      _.first.collect_alternates (_.second, alternate_count, alternate_glyphs);
81
0
    })
82
0
    ;
83
0
  }
84
85
  bool apply (hb_ot_apply_context_t *c) const
86
0
  {
87
0
    TRACE_APPLY (this);
88
89
0
    unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
90
0
    if (index == NOT_COVERED) return_trace (false);
91
92
0
    return_trace ((this+alternateSet[index]).apply (c));
93
0
  }
94
95
  bool serialize (hb_serialize_context_t *c,
96
                  hb_sorted_array_t<const HBGlyphID16> glyphs,
97
                  hb_array_t<const unsigned int> alternate_len_list,
98
                  hb_array_t<const HBGlyphID16> alternate_glyphs_list)
99
0
  {
100
0
    TRACE_SERIALIZE (this);
101
0
    if (unlikely (!c->extend_min (this))) return_trace (false);
102
0
    if (unlikely (!alternateSet.serialize (c, glyphs.length))) return_trace (false);
103
0
    for (unsigned int i = 0; i < glyphs.length; i++)
104
0
    {
105
0
      unsigned int alternate_len = alternate_len_list[i];
106
0
      if (unlikely (!alternateSet[i]
107
0
                        .serialize_serialize (c, alternate_glyphs_list.sub_array (0, alternate_len))))
108
0
        return_trace (false);
109
0
      alternate_glyphs_list += alternate_len;
110
0
    }
111
0
    return_trace (coverage.serialize_serialize (c, glyphs));
112
0
  }
113
114
  bool subset (hb_subset_context_t *c) const
115
0
  {
116
0
    TRACE_SUBSET (this);
117
0
    const hb_set_t &glyphset = *c->plan->glyphset_gsub ();
118
0
    const hb_map_t &glyph_map = *c->plan->glyph_map;
119
0
120
0
    auto *out = c->serializer->start_embed (*this);
121
0
    if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
122
0
    out->format = format;
123
0
124
0
    hb_sorted_vector_t<hb_codepoint_t> new_coverage;
125
0
    + hb_zip (this+coverage, alternateSet)
126
0
    | hb_filter (glyphset, hb_first)
127
0
    | hb_filter (subset_offset_array (c, out->alternateSet, this), hb_second)
128
0
    | hb_map (hb_first)
129
0
    | hb_map (glyph_map)
130
0
    | hb_sink (new_coverage)
131
0
    ;
132
0
    out->coverage.serialize_serialize (c->serializer, new_coverage.iter ());
133
0
    return_trace (bool (new_coverage));
134
0
  }
135
};
136
137
}
138
}
139
}
140
141
#endif  /* OT_LAYOUT_GSUB_ALTERNATESUBSTFORMAT1_HH */