Coverage Report

Created: 2025-07-11 06:04

/src/harfbuzz/src/OT/Layout/GSUB/LigatureSet.hh
Line
Count
Source (jump to first uncovered line)
1
#ifndef OT_LAYOUT_GSUB_LIGATURESET_HH
2
#define OT_LAYOUT_GSUB_LIGATURESET_HH
3
4
#include "Common.hh"
5
#include "Ligature.hh"
6
7
namespace OT {
8
namespace Layout {
9
namespace GSUB_impl {
10
11
template <typename Types>
12
struct LigatureSet
13
{
14
  public:
15
  Array16OfOffset16To<Ligature<Types>>
16
                ligature;               /* Array LigatureSet tables
17
                                         * ordered by preference */
18
  
19
  DEFINE_SIZE_ARRAY (2, ligature);
20
21
  bool sanitize (hb_sanitize_context_t *c) const
22
0
  {
23
0
    TRACE_SANITIZE (this);
24
0
    return_trace (ligature.sanitize (c, this));
25
0
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::sanitize(hb_sanitize_context_t*) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::sanitize(hb_sanitize_context_t*) const
26
27
  bool intersects (const hb_set_t *glyphs) const
28
0
  {
29
0
    return
30
0
    + hb_iter (ligature)
31
0
    | hb_map (hb_add (this))
32
0
    | hb_map ([glyphs] (const Ligature<Types> &_) { return _.intersects (glyphs); })
33
0
    | hb_any
34
0
    ;
35
0
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::intersects(hb_set_t const*) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::intersects(hb_set_t const*) const
36
37
  bool intersects_lig_glyph (const hb_set_t *glyphs) const
38
0
  {
39
0
    return
40
0
    + hb_iter (ligature)
41
0
    | hb_map (hb_add (this))
42
0
    | hb_map ([glyphs] (const Ligature<Types> &_) { 
43
0
      return _.intersects_lig_glyph (glyphs) && _.intersects (glyphs);
44
0
    })
45
0
    | hb_any
46
0
    ;
47
0
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::intersects_lig_glyph(hb_set_t const*) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::intersects_lig_glyph(hb_set_t const*) const
48
49
  void closure (hb_closure_context_t *c) const
50
0
  {
51
0
    + hb_iter (ligature)
52
0
    | hb_map (hb_add (this))
53
0
    | hb_apply ([c] (const Ligature<Types> &_) { _.closure (c); })
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::closure(OT::hb_closure_context_t*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::closure(OT::hb_closure_context_t*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&) const
54
0
    ;
55
0
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::closure(OT::hb_closure_context_t*) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::closure(OT::hb_closure_context_t*) const
56
57
  void collect_glyphs (hb_collect_glyphs_context_t *c) const
58
0
  {
59
0
    + hb_iter (ligature)
60
0
    | hb_map (hb_add (this))
61
0
    | hb_apply ([c] (const Ligature<Types> &_) { _.collect_glyphs (c); })
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::collect_glyphs(OT::hb_collect_glyphs_context_t*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::collect_glyphs(OT::hb_collect_glyphs_context_t*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&) const
62
0
    ;
63
0
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::collect_glyphs(OT::hb_collect_glyphs_context_t*) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::collect_glyphs(OT::hb_collect_glyphs_context_t*) const
64
65
  bool would_apply (hb_would_apply_context_t *c) const
66
0
  {
67
0
    return
68
0
    + hb_iter (ligature)
69
0
    | hb_map (hb_add (this))
70
0
    | hb_map ([c] (const Ligature<Types> &_) { return _.would_apply (c); })
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::would_apply(OT::hb_would_apply_context_t*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::would_apply(OT::hb_would_apply_context_t*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&) const
71
0
    | hb_any
72
0
    ;
73
0
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::would_apply(OT::hb_would_apply_context_t*) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::would_apply(OT::hb_would_apply_context_t*) const
74
75
  bool apply (hb_ot_apply_context_t *c) const
76
0
  {
77
0
    TRACE_APPLY (this);
78
79
0
    unsigned int num_ligs = ligature.len;
80
81
0
#ifndef HB_NO_OT_RULESETS_FAST_PATH
82
0
    if (HB_OPTIMIZE_SIZE_VAL || num_ligs <= 4)
83
0
#endif
84
0
    {
85
0
    slow:
86
0
      for (unsigned int i = 0; i < num_ligs; i++)
87
0
      {
88
0
  const auto &lig = this+ligature.arrayZ[i];
89
0
  if (lig.apply (c)) return_trace (true);
90
0
      }
91
0
      return_trace (false);
92
0
    }
93
94
    /* This version is optimized for speed by matching the first component
95
     * of the ligature here, instead of calling into the ligation code.
96
     *
97
     * This is replicated in ChainRuleSet and RuleSet. */
98
99
0
    auto &skippy_iter = c->iter_input;
100
0
    skippy_iter.reset (c->buffer->idx);
101
0
    skippy_iter.set_match_func (match_always, nullptr);
102
0
    skippy_iter.set_glyph_data ((HBUINT16 *) nullptr);
103
0
    unsigned unsafe_to;
104
0
    hb_codepoint_t first = (unsigned) -1;
105
0
    bool matched = skippy_iter.next (&unsafe_to);
106
0
    if (likely (matched))
107
0
    {
108
0
      first = c->buffer->info[skippy_iter.idx].codepoint;
109
0
      unsafe_to = skippy_iter.idx + 1;
110
111
0
      if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx]))
112
0
      {
113
  /* Can't use the fast path if eg. the next char is a default-ignorable
114
   * or other skippable. */
115
0
        goto slow;
116
0
      }
117
0
    }
118
0
    else
119
0
      goto slow;
120
121
0
    bool unsafe_to_concat = false;
122
123
0
    for (unsigned int i = 0; i < num_ligs; i++)
124
0
    {
125
0
      const auto &lig = this+ligature.arrayZ[i];
126
0
      if (unlikely (lig.component.lenP1 <= 1) ||
127
0
    lig.component.arrayZ[0] == first)
128
0
      {
129
0
  if (lig.apply (c))
130
0
  {
131
0
    if (unsafe_to_concat)
132
0
      c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to);
133
0
    return_trace (true);
134
0
  }
135
0
      }
136
0
      else if (likely (lig.component.lenP1 > 1))
137
0
        unsafe_to_concat = true;
138
0
    }
139
0
    if (likely (unsafe_to_concat))
140
0
      c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to);
141
142
0
    return_trace (false);
143
0
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::apply(OT::hb_ot_apply_context_t*) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::apply(OT::hb_ot_apply_context_t*) const
144
145
  bool serialize (hb_serialize_context_t *c,
146
                  hb_array_t<const HBGlyphID16> ligatures,
147
                  hb_array_t<const unsigned int> component_count_list,
148
                  hb_array_t<const HBGlyphID16> &component_list /* Starting from second for each ligature */)
149
0
  {
150
0
    TRACE_SERIALIZE (this);
151
0
    if (unlikely (!c->extend_min (this))) return_trace (false);
152
0
    if (unlikely (!ligature.serialize (c, ligatures.length))) return_trace (false);
153
0
    for (unsigned int i = 0; i < ligatures.length; i++)
154
0
    {
155
0
      unsigned int component_count = (unsigned) hb_max ((int) component_count_list[i] - 1, 0);
156
0
      if (unlikely (!ligature[i].serialize_serialize (c,
157
0
                                                      ligatures[i],
158
0
                                                      component_list.sub_array (0, component_count))))
159
0
        return_trace (false);
160
0
      component_list += component_count;
161
0
    }
162
0
    return_trace (true);
163
0
  }
164
165
  bool subset (hb_subset_context_t *c, unsigned coverage_idx) const
166
0
  {
167
0
    TRACE_SUBSET (this);
168
0
    auto *out = c->serializer->start_embed (*this);
169
0
    if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
170
0
171
0
    + hb_iter (ligature)
172
0
    | hb_filter (subset_offset_array (c, out->ligature, this, coverage_idx))
173
0
    | hb_drain
174
0
    ;
175
0
176
0
    if (bool (out->ligature))
177
0
      // Ensure Coverage table is always packed after this.
178
0
      c->serializer->add_virtual_link (coverage_idx);
179
0
180
0
    return_trace (bool (out->ligature));
181
0
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::subset(hb_subset_context_t*, unsigned int) const
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::subset(hb_subset_context_t*, unsigned int) const
182
};
183
184
}
185
}
186
}
187
188
#endif  /* OT_LAYOUT_GSUB_LIGATURESET_HH */