/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 | | Array16Of<typename Types::template OffsetTo<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 | 482 | { |
23 | 482 | TRACE_SANITIZE (this); |
24 | 482 | return_trace (ligature.sanitize (c, this)); |
25 | 482 | } |
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 | } |
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 | } |
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); }) |
54 | 0 | ; |
55 | 0 | } |
56 | | |
57 | | void depend (hb_depend_context_t *c, hb_codepoint_t first) const |
58 | 0 | { |
59 | 0 | + hb_iter (ligature) |
60 | 0 | | hb_map (hb_add (this)) |
61 | 0 | | hb_apply ([&] (const Ligature<Types> &_) { _.depend (c, first); }) |
62 | 0 | ; |
63 | 0 | } |
64 | | |
65 | | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
66 | 0 | { |
67 | 0 | + hb_iter (ligature) |
68 | 0 | | hb_map (hb_add (this)) |
69 | 0 | | hb_apply ([c] (const Ligature<Types> &_) { _.collect_glyphs (c); }) |
70 | 0 | ; |
71 | 0 | } |
72 | | |
73 | | template <typename set_t> |
74 | | void collect_seconds (set_t &s) const |
75 | 30 | { |
76 | 30 | + hb_iter (ligature) |
77 | 30 | | hb_map (hb_add (this)) |
78 | 150 | | hb_apply ([&s] (const Ligature<Types> &_) { _.collect_second (s); }) |
79 | 30 | ; |
80 | 30 | } |
81 | | |
82 | | bool would_apply (hb_would_apply_context_t *c) const |
83 | 0 | { |
84 | 0 | return |
85 | 0 | + hb_iter (ligature) |
86 | 0 | | hb_map (hb_add (this)) |
87 | 0 | | hb_map ([c] (const Ligature<Types> &_) { return _.would_apply (c); }) |
88 | 0 | | hb_any |
89 | 0 | ; |
90 | 0 | } |
91 | | |
92 | | bool apply (hb_ot_apply_context_t *c, const hb_set_digest_t *seconds = nullptr) const |
93 | 0 | { |
94 | 0 | TRACE_APPLY (this); |
95 | |
|
96 | 0 | unsigned int num_ligs = ligature.len; |
97 | |
|
98 | 0 | #ifndef HB_NO_OT_RULESETS_FAST_PATH |
99 | 0 | if (HB_OPTIMIZE_SIZE_VAL || num_ligs <= 1) |
100 | 0 | #endif |
101 | 0 | { |
102 | 0 | slow: |
103 | 0 | for (unsigned int i = 0; i < num_ligs; i++) |
104 | 0 | { |
105 | 0 | const auto &lig = this+ligature.arrayZ[i]; |
106 | 0 | if (lig.apply (c)) return_trace (true); |
107 | 0 | } |
108 | 0 | return_trace (false); |
109 | 0 | } |
110 | | |
111 | | /* This version is optimized for speed by matching the second component |
112 | | * of the ligature here, instead of calling into the ligation code. |
113 | | * |
114 | | * This is replicated in ChainRuleSet and RuleSet. */ |
115 | | |
116 | 0 | auto &skippy_iter = c->iter_context; |
117 | 0 | skippy_iter.reset (c->buffer->idx); |
118 | 0 | skippy_iter.set_match_func (match_always, nullptr); |
119 | 0 | skippy_iter.set_glyph_data ((HBUINT16 *) nullptr); |
120 | 0 | unsigned unsafe_to; |
121 | 0 | hb_codepoint_t second = (unsigned) -1; |
122 | 0 | bool matched = skippy_iter.next (&unsafe_to); |
123 | 0 | if (likely (matched)) |
124 | 0 | { |
125 | 0 | second = c->buffer->info[skippy_iter.idx].codepoint; |
126 | 0 | unsafe_to = skippy_iter.idx + 1; |
127 | |
|
128 | 0 | if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx])) |
129 | 0 | { |
130 | | /* Can't use the fast path if eg. the next char is a default-ignorable |
131 | | * or other skippable. */ |
132 | 0 | goto slow; |
133 | 0 | } |
134 | 0 | } |
135 | 0 | else |
136 | 0 | goto slow; |
137 | | |
138 | 0 | if (seconds && !seconds->may_have (second)) |
139 | 0 | { |
140 | 0 | c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to); |
141 | 0 | return_trace (false); |
142 | 0 | } |
143 | 0 | bool unsafe_to_concat = false; |
144 | 0 | for (unsigned int i = 0; i < num_ligs; i++) |
145 | 0 | { |
146 | 0 | const auto &lig = this+ligature.arrayZ[i]; |
147 | 0 | if (unlikely (lig.component.lenP1 <= 1) || |
148 | 0 | lig.component.arrayZ[0] == second) |
149 | 0 | { |
150 | 0 | if (lig.apply (c)) |
151 | 0 | { |
152 | 0 | if (unsafe_to_concat) |
153 | 0 | c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to); |
154 | 0 | return_trace (true); |
155 | 0 | } |
156 | 0 | } |
157 | 0 | else if (likely (lig.component.lenP1 > 1)) |
158 | 0 | unsafe_to_concat = true; |
159 | 0 | } |
160 | 0 | if (likely (unsafe_to_concat)) |
161 | 0 | c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to); |
162 | |
|
163 | 0 | return_trace (false); |
164 | 0 | } |
165 | | |
166 | | template <typename GlyphID> |
167 | | bool serialize (hb_serialize_context_t *c, |
168 | | hb_array_t<GlyphID> ligatures, |
169 | | hb_array_t<const unsigned int> component_count_list, |
170 | | hb_array_t<GlyphID> &component_list /* Starting from second for each ligature */) |
171 | 0 | { |
172 | 0 | TRACE_SERIALIZE (this); |
173 | 0 | if (unlikely (!c->extend_min (this))) return_trace (false); |
174 | 0 | if (unlikely (!ligature.serialize (c, ligatures.length))) return_trace (false); |
175 | 0 | for (unsigned int i = 0; i < ligatures.length; i++) |
176 | 0 | { |
177 | 0 | unsigned int component_count = (unsigned) hb_max ((int) component_count_list[i] - 1, 0); |
178 | 0 | if (unlikely (!ligature[i].serialize_serialize (c, |
179 | 0 | ligatures[i], |
180 | 0 | component_list.sub_array (0, component_count)))) |
181 | 0 | return_trace (false); |
182 | 0 | component_list += component_count; |
183 | 0 | } |
184 | 0 | return_trace (true); |
185 | 0 | } |
186 | | |
187 | | bool subset (hb_subset_context_t *c, unsigned coverage_idx) const |
188 | 0 | { |
189 | 0 | TRACE_SUBSET (this); |
190 | 0 | auto *out = c->serializer->start_embed (*this); |
191 | 0 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
192 | 0 |
|
193 | 0 | + hb_iter (ligature) |
194 | 0 | | hb_filter (subset_offset_array (c, out->ligature, this, coverage_idx)) |
195 | 0 | | hb_drain |
196 | 0 | ; |
197 | 0 |
|
198 | 0 | if (bool (out->ligature)) |
199 | 0 | // Ensure Coverage table is always packed after this. |
200 | 0 | c->serializer->add_virtual_link (coverage_idx); |
201 | 0 |
|
202 | 0 | return_trace (bool (out->ligature)); |
203 | 0 | } |
204 | | }; |
205 | | |
206 | | } |
207 | | } |
208 | | } |
209 | | |
210 | | #endif /* OT_LAYOUT_GSUB_LIGATURESET_HH */ |