Coverage Report

Created: 2025-11-11 06:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/OT/Layout/GSUB/LigatureSet.hh
Line
Count
Source
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
14.2k
  {
23
14.2k
    TRACE_SANITIZE (this);
24
14.2k
    return_trace (ligature.sanitize (c, this));
25
14.2k
  }
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::sanitize(hb_sanitize_context_t*) const
Line
Count
Source
22
13.9k
  {
23
13.9k
    TRACE_SANITIZE (this);
24
13.9k
    return_trace (ligature.sanitize (c, this));
25
13.9k
  }
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::sanitize(hb_sanitize_context_t*) const
Line
Count
Source
22
243
  {
23
243
    TRACE_SANITIZE (this);
24
243
    return_trace (ligature.sanitize (c, this));
25
243
  }
26
27
  bool intersects (const hb_set_t *glyphs) const
28
275
  {
29
275
    return
30
275
    + hb_iter (ligature)
31
275
    | hb_map (hb_add (this))
32
275
    | hb_map ([glyphs] (const Ligature<Types> &_) { return _.intersects (glyphs); })
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::intersects(hb_set_t const*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&) const
Line
Count
Source
32
258
    | hb_map ([glyphs] (const Ligature<Types> &_) { return _.intersects (glyphs); })
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::intersects(hb_set_t const*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&) const
33
275
    | hb_any
34
275
    ;
35
275
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::intersects(hb_set_t const*) const
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::intersects(hb_set_t const*) const
Line
Count
Source
28
275
  {
29
275
    return
30
275
    + hb_iter (ligature)
31
275
    | hb_map (hb_add (this))
32
275
    | hb_map ([glyphs] (const Ligature<Types> &_) { return _.intersects (glyphs); })
33
275
    | hb_any
34
275
    ;
35
275
  }
36
37
  bool intersects_lig_glyph (const hb_set_t *glyphs) const
38
562
  {
39
562
    return
40
562
    + hb_iter (ligature)
41
562
    | hb_map (hb_add (this))
42
562
    | hb_map ([glyphs] (const Ligature<Types> &_) { 
43
514
      return _.intersects_lig_glyph (glyphs) && _.intersects (glyphs);
44
514
    })
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::intersects_lig_glyph(hb_set_t const*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&) const
Line
Count
Source
42
514
    | hb_map ([glyphs] (const Ligature<Types> &_) { 
43
514
      return _.intersects_lig_glyph (glyphs) && _.intersects (glyphs);
44
514
    })
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::intersects_lig_glyph(hb_set_t const*) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::MediumTypes> const&) const
45
562
    | hb_any
46
562
    ;
47
562
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::intersects_lig_glyph(hb_set_t const*) const
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::intersects_lig_glyph(hb_set_t const*) const
Line
Count
Source
38
562
  {
39
562
    return
40
562
    + hb_iter (ligature)
41
562
    | hb_map (hb_add (this))
42
562
    | hb_map ([glyphs] (const Ligature<Types> &_) { 
43
562
      return _.intersects_lig_glyph (glyphs) && _.intersects (glyphs);
44
562
    })
45
562
    | hb_any
46
562
    ;
47
562
  }
48
49
  void closure (hb_closure_context_t *c) const
50
830
  {
51
830
    + hb_iter (ligature)
52
830
    | hb_map (hb_add (this))
53
1.63M
    | hb_apply ([c] (const Ligature<Types> &_) { _.closure (c); })
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
Line
Count
Source
53
1.63M
    | hb_apply ([c] (const Ligature<Types> &_) { _.closure (c); })
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
830
    ;
55
830
  }
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::closure(OT::hb_closure_context_t*) const
Line
Count
Source
50
830
  {
51
830
    + hb_iter (ligature)
52
830
    | hb_map (hb_add (this))
53
830
    | hb_apply ([c] (const Ligature<Types> &_) { _.closure (c); })
54
830
    ;
55
830
  }
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
  template <typename set_t>
66
  void collect_seconds (set_t &s) const
67
2.92k
  {
68
2.92k
    + hb_iter (ligature)
69
2.92k
    | hb_map (hb_add (this))
70
8.93k
    | hb_apply ([&s] (const Ligature<Types> &_) { _.collect_second (s); })
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::collect_seconds<hb_set_digest_t>(hb_set_digest_t&) const::{lambda(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::Ligature<OT::Layout::SmallTypes> const&) const
Line
Count
Source
70
8.93k
    | hb_apply ([&s] (const Ligature<Types> &_) { _.collect_second (s); })
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::collect_seconds<hb_set_digest_t>(hb_set_digest_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
2.92k
    ;
72
2.92k
  }
void OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::collect_seconds<hb_set_digest_t>(hb_set_digest_t&) const
Line
Count
Source
67
2.92k
  {
68
2.92k
    + hb_iter (ligature)
69
2.92k
    | hb_map (hb_add (this))
70
2.92k
    | hb_apply ([&s] (const Ligature<Types> &_) { _.collect_second (s); })
71
2.92k
    ;
72
2.92k
  }
Unexecuted instantiation: void OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::collect_seconds<hb_set_digest_t>(hb_set_digest_t&) const
73
74
  bool would_apply (hb_would_apply_context_t *c) const
75
0
  {
76
0
    return
77
0
    + hb_iter (ligature)
78
0
    | hb_map (hb_add (this))
79
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
80
0
    | hb_any
81
0
    ;
82
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
83
84
  bool apply (hb_ot_apply_context_t *c, const hb_set_digest_t *seconds = nullptr) const
85
1.43k
  {
86
1.43k
    TRACE_APPLY (this);
87
88
1.43k
    unsigned int num_ligs = ligature.len;
89
90
1.43k
#ifndef HB_NO_OT_RULESETS_FAST_PATH
91
1.43k
    if (HB_OPTIMIZE_SIZE_VAL || num_ligs <= 1)
92
342
#endif
93
342
    {
94
484
    slow:
95
1.22k
      for (unsigned int i = 0; i < num_ligs; i++)
96
895
      {
97
895
  const auto &lig = this+ligature.arrayZ[i];
98
895
  if (lig.apply (c)) return_trace (true);
99
895
      }
100
484
      return_trace (false);
101
484
    }
102
103
    /* This version is optimized for speed by matching the second component
104
     * of the ligature here, instead of calling into the ligation code.
105
     *
106
     * This is replicated in ChainRuleSet and RuleSet. */
107
108
1.09k
    auto &skippy_iter = c->iter_input;
109
1.09k
    skippy_iter.reset (c->buffer->idx);
110
1.09k
    skippy_iter.set_match_func (match_always, nullptr);
111
1.09k
    skippy_iter.set_glyph_data ((HBUINT16 *) nullptr);
112
1.09k
    unsigned unsafe_to;
113
1.09k
    hb_codepoint_t second = (unsigned) -1;
114
1.09k
    bool matched = skippy_iter.next (&unsafe_to);
115
1.09k
    if (likely (matched))
116
965
    {
117
965
      second = c->buffer->info[skippy_iter.idx].codepoint;
118
965
      unsafe_to = skippy_iter.idx + 1;
119
120
965
      if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx]))
121
17
      {
122
  /* Can't use the fast path if eg. the next char is a default-ignorable
123
   * or other skippable. */
124
17
        goto slow;
125
17
      }
126
965
    }
127
125
    else
128
125
      goto slow;
129
130
948
    if (seconds && !seconds->may_have (second))
131
137
      return_trace (false);
132
811
    bool unsafe_to_concat = false;
133
2.78k
    for (unsigned int i = 0; i < num_ligs; i++)
134
2.44k
    {
135
2.44k
      const auto &lig = this+ligature.arrayZ[i];
136
2.44k
      if (unlikely (lig.component.lenP1 <= 1) ||
137
1.68k
    lig.component.arrayZ[0] == second)
138
1.69k
      {
139
1.69k
  if (lig.apply (c))
140
472
  {
141
472
    if (unsafe_to_concat)
142
54
      c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to);
143
472
    return_trace (true);
144
472
  }
145
1.69k
      }
146
742
      else if (likely (lig.component.lenP1 > 1))
147
742
        unsafe_to_concat = true;
148
2.44k
    }
149
339
    if (likely (unsafe_to_concat))
150
291
      c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to);
151
152
339
    return_trace (false);
153
811
  }
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::apply(OT::hb_ot_apply_context_t*, hb_set_digest_t const*) const
Line
Count
Source
85
1.43k
  {
86
1.43k
    TRACE_APPLY (this);
87
88
1.43k
    unsigned int num_ligs = ligature.len;
89
90
1.43k
#ifndef HB_NO_OT_RULESETS_FAST_PATH
91
1.43k
    if (HB_OPTIMIZE_SIZE_VAL || num_ligs <= 1)
92
342
#endif
93
342
    {
94
484
    slow:
95
1.22k
      for (unsigned int i = 0; i < num_ligs; i++)
96
895
      {
97
895
  const auto &lig = this+ligature.arrayZ[i];
98
895
  if (lig.apply (c)) return_trace (true);
99
895
      }
100
484
      return_trace (false);
101
484
    }
102
103
    /* This version is optimized for speed by matching the second component
104
     * of the ligature here, instead of calling into the ligation code.
105
     *
106
     * This is replicated in ChainRuleSet and RuleSet. */
107
108
1.09k
    auto &skippy_iter = c->iter_input;
109
1.09k
    skippy_iter.reset (c->buffer->idx);
110
1.09k
    skippy_iter.set_match_func (match_always, nullptr);
111
1.09k
    skippy_iter.set_glyph_data ((HBUINT16 *) nullptr);
112
1.09k
    unsigned unsafe_to;
113
1.09k
    hb_codepoint_t second = (unsigned) -1;
114
1.09k
    bool matched = skippy_iter.next (&unsafe_to);
115
1.09k
    if (likely (matched))
116
965
    {
117
965
      second = c->buffer->info[skippy_iter.idx].codepoint;
118
965
      unsafe_to = skippy_iter.idx + 1;
119
120
965
      if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx]))
121
17
      {
122
  /* Can't use the fast path if eg. the next char is a default-ignorable
123
   * or other skippable. */
124
17
        goto slow;
125
17
      }
126
965
    }
127
125
    else
128
125
      goto slow;
129
130
948
    if (seconds && !seconds->may_have (second))
131
137
      return_trace (false);
132
811
    bool unsafe_to_concat = false;
133
2.78k
    for (unsigned int i = 0; i < num_ligs; i++)
134
2.44k
    {
135
2.44k
      const auto &lig = this+ligature.arrayZ[i];
136
2.44k
      if (unlikely (lig.component.lenP1 <= 1) ||
137
1.68k
    lig.component.arrayZ[0] == second)
138
1.69k
      {
139
1.69k
  if (lig.apply (c))
140
472
  {
141
472
    if (unsafe_to_concat)
142
54
      c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to);
143
472
    return_trace (true);
144
472
  }
145
1.69k
      }
146
742
      else if (likely (lig.component.lenP1 > 1))
147
742
        unsafe_to_concat = true;
148
2.44k
    }
149
339
    if (likely (unsafe_to_concat))
150
291
      c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to);
151
152
339
    return_trace (false);
153
811
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::apply(OT::hb_ot_apply_context_t*, hb_set_digest_t const*) const
154
155
  bool serialize (hb_serialize_context_t *c,
156
                  hb_array_t<const HBGlyphID16> ligatures,
157
                  hb_array_t<const unsigned int> component_count_list,
158
                  hb_array_t<const HBGlyphID16> &component_list /* Starting from second for each ligature */)
159
2.77k
  {
160
2.77k
    TRACE_SERIALIZE (this);
161
2.77k
    if (unlikely (!c->extend_min (this))) return_trace (false);
162
2.77k
    if (unlikely (!ligature.serialize (c, ligatures.length))) return_trace (false);
163
11.2k
    for (unsigned int i = 0; i < ligatures.length; i++)
164
8.45k
    {
165
8.45k
      unsigned int component_count = (unsigned) hb_max ((int) component_count_list[i] - 1, 0);
166
8.45k
      if (unlikely (!ligature[i].serialize_serialize (c,
167
8.45k
                                                      ligatures[i],
168
8.45k
                                                      component_list.sub_array (0, component_count))))
169
21
        return_trace (false);
170
8.43k
      component_list += component_count;
171
8.43k
    }
172
2.77k
    return_trace (true);
173
2.77k
  }
174
175
  bool subset (hb_subset_context_t *c, unsigned coverage_idx) const
176
517
  {
177
517
    TRACE_SUBSET (this);
178
517
    auto *out = c->serializer->start_embed (*this);
179
517
    if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
180
181
517
    + hb_iter (ligature)
182
517
    | hb_filter (subset_offset_array (c, out->ligature, this, coverage_idx))
183
517
    | hb_drain
184
517
    ;
185
186
517
    if (bool (out->ligature))
187
      // Ensure Coverage table is always packed after this.
188
457
      c->serializer->add_virtual_link (coverage_idx);
189
190
517
    return_trace (bool (out->ligature));
191
517
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::subset(hb_subset_context_t*, unsigned int) const
OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes>::subset(hb_subset_context_t*, unsigned int) const
Line
Count
Source
176
517
  {
177
517
    TRACE_SUBSET (this);
178
517
    auto *out = c->serializer->start_embed (*this);
179
517
    if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
180
181
517
    + hb_iter (ligature)
182
517
    | hb_filter (subset_offset_array (c, out->ligature, this, coverage_idx))
183
517
    | hb_drain
184
517
    ;
185
186
517
    if (bool (out->ligature))
187
      // Ensure Coverage table is always packed after this.
188
457
      c->serializer->add_virtual_link (coverage_idx);
189
190
517
    return_trace (bool (out->ligature));
191
517
  }
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes>::subset(hb_subset_context_t*, unsigned int) const
192
};
193
194
}
195
}
196
}
197
198
#endif  /* OT_LAYOUT_GSUB_LIGATURESET_HH */