/src/harfbuzz/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef OT_LAYOUT_GSUB_REVERSECHAINSINGLESUBSTFORMAT1_HH |
2 | | #define OT_LAYOUT_GSUB_REVERSECHAINSINGLESUBSTFORMAT1_HH |
3 | | |
4 | | #include "Common.hh" |
5 | | |
6 | | namespace OT { |
7 | | namespace Layout { |
8 | | namespace GSUB_impl { |
9 | | |
10 | | struct ReverseChainSingleSubstFormat1 |
11 | | { |
12 | | protected: |
13 | | HBUINT16 format; /* Format identifier--format = 1 */ |
14 | | Offset16To<Coverage> |
15 | | coverage; /* Offset to Coverage table--from |
16 | | * beginning of table */ |
17 | | Array16OfOffset16To<Coverage> |
18 | | backtrack; /* Array of coverage tables |
19 | | * in backtracking sequence, in glyph |
20 | | * sequence order */ |
21 | | Array16OfOffset16To<Coverage> |
22 | | lookaheadX; /* Array of coverage tables |
23 | | * in lookahead sequence, in glyph |
24 | | * sequence order */ |
25 | | Array16Of<HBGlyphID16> |
26 | | substituteX; /* Array of substitute |
27 | | * GlyphIDs--ordered by Coverage Index */ |
28 | | public: |
29 | | DEFINE_SIZE_MIN (10); |
30 | | |
31 | | bool sanitize (hb_sanitize_context_t *c) const |
32 | 0 | { |
33 | 0 | TRACE_SANITIZE (this); |
34 | 0 | if (!(coverage.sanitize (c, this) && backtrack.sanitize (c, this))) |
35 | 0 | return_trace (false); |
36 | 0 | const auto &lookahead = StructAfter<decltype (lookaheadX)> (backtrack); |
37 | 0 | if (!lookahead.sanitize (c, this)) |
38 | 0 | return_trace (false); |
39 | 0 | const auto &substitute = StructAfter<decltype (substituteX)> (lookahead); |
40 | 0 | return_trace (substitute.sanitize (c)); |
41 | 0 | } |
42 | | |
43 | | bool intersects (const hb_set_t *glyphs) const |
44 | 0 | { |
45 | 0 | if (!(this+coverage).intersects (glyphs)) |
46 | 0 | return false; |
47 | | |
48 | 0 | const auto &lookahead = StructAfter<decltype (lookaheadX)> (backtrack); |
49 | |
|
50 | 0 | unsigned int count; |
51 | |
|
52 | 0 | count = backtrack.len; |
53 | 0 | for (unsigned int i = 0; i < count; i++) |
54 | 0 | if (!(this+backtrack[i]).intersects (glyphs)) |
55 | 0 | return false; |
56 | | |
57 | 0 | count = lookahead.len; |
58 | 0 | for (unsigned int i = 0; i < count; i++) |
59 | 0 | if (!(this+lookahead[i]).intersects (glyphs)) |
60 | 0 | return false; |
61 | | |
62 | 0 | return true; |
63 | 0 | } |
64 | | |
65 | | bool may_have_non_1to1 () const |
66 | 0 | { return false; } |
67 | | |
68 | | void closure (hb_closure_context_t *c) const |
69 | 0 | { |
70 | 0 | if (!intersects (c->glyphs)) return; |
71 | | |
72 | 0 | const auto &lookahead = StructAfter<decltype (lookaheadX)> (backtrack); |
73 | 0 | const auto &substitute = StructAfter<decltype (substituteX)> (lookahead); |
74 | |
|
75 | 0 | + hb_zip (this+coverage, substitute) |
76 | 0 | | hb_filter (c->parent_active_glyphs (), hb_first) |
77 | 0 | | hb_map (hb_second) |
78 | 0 | | hb_sink (c->output) |
79 | 0 | ; |
80 | 0 | } |
81 | | |
82 | 0 | void closure_lookups (hb_closure_lookups_context_t *c) const {} |
83 | | |
84 | | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
85 | 0 | { |
86 | 0 | if (unlikely (!(this+coverage).collect_coverage (c->input))) return; |
87 | | |
88 | 0 | unsigned int count; |
89 | |
|
90 | 0 | count = backtrack.len; |
91 | 0 | for (unsigned int i = 0; i < count; i++) |
92 | 0 | if (unlikely (!(this+backtrack[i]).collect_coverage (c->before))) return; |
93 | | |
94 | 0 | const auto &lookahead = StructAfter<decltype (lookaheadX)> (backtrack); |
95 | 0 | count = lookahead.len; |
96 | 0 | for (unsigned int i = 0; i < count; i++) |
97 | 0 | if (unlikely (!(this+lookahead[i]).collect_coverage (c->after))) return; |
98 | | |
99 | 0 | const auto &substitute = StructAfter<decltype (substituteX)> (lookahead); |
100 | 0 | count = substitute.len; |
101 | 0 | c->output->add_array (substitute.arrayZ, substitute.len); |
102 | 0 | } |
103 | | |
104 | 0 | const Coverage &get_coverage () const { return this+coverage; } |
105 | | |
106 | | bool would_apply (hb_would_apply_context_t *c) const |
107 | 0 | { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } |
108 | | |
109 | | bool apply (hb_ot_apply_context_t *c) const |
110 | 0 | { |
111 | 0 | TRACE_APPLY (this); |
112 | 0 | if (unlikely (c->nesting_level_left != HB_MAX_NESTING_LEVEL)) |
113 | 0 | return_trace (false); /* No chaining to this type */ |
114 | | |
115 | 0 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur ().codepoint); |
116 | 0 | if (likely (index == NOT_COVERED)) return_trace (false); |
117 | | |
118 | 0 | const auto &lookahead = StructAfter<decltype (lookaheadX)> (backtrack); |
119 | 0 | const auto &substitute = StructAfter<decltype (substituteX)> (lookahead); |
120 | |
|
121 | 0 | if (unlikely (index >= substitute.len)) return_trace (false); |
122 | | |
123 | 0 | unsigned int start_index = 0, end_index = 0; |
124 | 0 | if (match_backtrack (c, |
125 | 0 | backtrack.len, (HBUINT16 *) backtrack.arrayZ, |
126 | 0 | match_coverage, this, |
127 | 0 | &start_index) && |
128 | 0 | match_lookahead (c, |
129 | 0 | lookahead.len, (HBUINT16 *) lookahead.arrayZ, |
130 | 0 | match_coverage, this, |
131 | 0 | c->buffer->idx + 1, &end_index)) |
132 | 0 | { |
133 | 0 | c->buffer->unsafe_to_break_from_outbuffer (start_index, end_index); |
134 | |
|
135 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
136 | 0 | { |
137 | 0 | c->buffer->message (c->font, |
138 | 0 | "replacing glyph at %u (reverse chaining substitution)", |
139 | 0 | c->buffer->idx); |
140 | 0 | } |
141 | |
|
142 | 0 | c->replace_glyph_inplace (substitute[index]); |
143 | |
|
144 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
145 | 0 | { |
146 | 0 | c->buffer->message (c->font, |
147 | 0 | "replaced glyph at %u (reverse chaining substitution)", |
148 | 0 | c->buffer->idx); |
149 | 0 | } |
150 | | |
151 | | /* Note: We DON'T decrease buffer->idx. The main loop does it |
152 | | * for us. This is useful for preventing surprises if someone |
153 | | * calls us through a Context lookup. */ |
154 | 0 | return_trace (true); |
155 | 0 | } |
156 | 0 | else |
157 | 0 | { |
158 | 0 | c->buffer->unsafe_to_concat_from_outbuffer (start_index, end_index); |
159 | 0 | return_trace (false); |
160 | 0 | } |
161 | 0 | } |
162 | | |
163 | | template<typename Iterator, |
164 | | hb_requires (hb_is_iterator (Iterator))> |
165 | | bool serialize_coverage_offset_array (hb_subset_context_t *c, Iterator it) const |
166 | 0 | { |
167 | 0 | TRACE_SERIALIZE (this); |
168 | 0 | auto *out = c->serializer->start_embed<Array16OfOffset16To<Coverage>> (); |
169 | 0 |
|
170 | 0 | if (unlikely (!c->serializer->allocate_size<HBUINT16> (HBUINT16::static_size))) |
171 | 0 | return_trace (false); |
172 | 0 |
|
173 | 0 | for (auto& offset : it) { |
174 | 0 | auto *o = out->serialize_append (c->serializer); |
175 | 0 | if (unlikely (!o) || !o->serialize_subset (c, offset, this)) |
176 | 0 | return_trace (false); |
177 | 0 | } |
178 | 0 |
|
179 | 0 | return_trace (true); |
180 | 0 | } |
181 | | |
182 | | template<typename Iterator, typename BacktrackIterator, typename LookaheadIterator, |
183 | | hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_pair_t)), |
184 | | hb_requires (hb_is_iterator (BacktrackIterator)), |
185 | | hb_requires (hb_is_iterator (LookaheadIterator))> |
186 | | bool serialize (hb_subset_context_t *c, |
187 | | Iterator coverage_subst_iter, |
188 | | BacktrackIterator backtrack_iter, |
189 | | LookaheadIterator lookahead_iter) const |
190 | 0 | { |
191 | 0 | TRACE_SERIALIZE (this); |
192 | 0 |
|
193 | 0 | auto *out = c->serializer->start_embed (this); |
194 | 0 | if (unlikely (!c->serializer->embed (this->format))) return_trace (false); |
195 | 0 | if (unlikely (!c->serializer->embed (this->coverage))) return_trace (false); |
196 | 0 |
|
197 | 0 | if (!serialize_coverage_offset_array (c, backtrack_iter)) return_trace (false); |
198 | 0 | if (!serialize_coverage_offset_array (c, lookahead_iter)) return_trace (false); |
199 | 0 |
|
200 | 0 | auto *substitute_out = c->serializer->start_embed<Array16Of<HBGlyphID16>> (); |
201 | 0 | auto substitutes = |
202 | 0 | + coverage_subst_iter |
203 | 0 | | hb_map (hb_second) |
204 | 0 | ; |
205 | 0 |
|
206 | 0 | auto glyphs = |
207 | 0 | + coverage_subst_iter |
208 | 0 | | hb_map_retains_sorting (hb_first) |
209 | 0 | ; |
210 | 0 | if (unlikely (! c->serializer->check_success (substitute_out->serialize (c->serializer, substitutes)))) |
211 | 0 | return_trace (false); |
212 | 0 |
|
213 | 0 | if (unlikely (!out->coverage.serialize_serialize (c->serializer, glyphs))) |
214 | 0 | return_trace (false); |
215 | 0 | return_trace (true); |
216 | 0 | } Unexecuted instantiation: hb-ot-face.cc:bool OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::serialize<hb_map_iter_t<hb_filter_iter_t<hb_filter_iter_t<hb_zip_iter_t<OT::Layout::Common::Coverage::iter_t, hb_array_t<OT::HBGlyphID16 const> >, hb_set_t const&, $_5 const&, (void*)0>, hb_set_t const&, $_6 const&, (void*)0>, OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, OT::HBGlyphID16 const&>)#1}, (hb_function_sortedness_t)1, (void*)0>, hb_array_t<OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const>, OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const, (void*)0, (void*)0, (void*)0>(hb_subset_context_t*, hb_map_iter_t<hb_filter_iter_t<hb_filter_iter_t<hb_zip_iter_t<OT::Layout::Common::Coverage::iter_t, hb_array_t<OT::HBGlyphID16 const> >, hb_set_t const&, $_5 const&, (void*)0>, hb_set_t const&, $_6 const&, (void*)0>, OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, OT::HBGlyphID16 const&>)#1}, (hb_function_sortedness_t)1, (void*)0>, hb_array_t<OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const>, OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const) const Unexecuted instantiation: hb-ot-layout.cc:bool OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::serialize<hb_map_iter_t<hb_filter_iter_t<hb_filter_iter_t<hb_zip_iter_t<OT::Layout::Common::Coverage::iter_t, hb_array_t<OT::HBGlyphID16 const> >, hb_set_t const&, $_5 const&, (void*)0>, hb_set_t const&, $_6 const&, (void*)0>, OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, OT::HBGlyphID16 const&>)#1}, (hb_function_sortedness_t)1, (void*)0>, hb_array_t<OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const>, OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const, (void*)0, (void*)0, (void*)0>(hb_subset_context_t*, hb_map_iter_t<hb_filter_iter_t<hb_filter_iter_t<hb_zip_iter_t<OT::Layout::Common::Coverage::iter_t, hb_array_t<OT::HBGlyphID16 const> >, hb_set_t const&, $_5 const&, (void*)0>, hb_set_t const&, $_6 const&, (void*)0>, OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, OT::HBGlyphID16 const&>)#1}, (hb_function_sortedness_t)1, (void*)0>, hb_array_t<OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const>, OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const) const Unexecuted instantiation: hb-ot-shaper-arabic.cc:bool OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::serialize<hb_map_iter_t<hb_filter_iter_t<hb_filter_iter_t<hb_zip_iter_t<OT::Layout::Common::Coverage::iter_t, hb_array_t<OT::HBGlyphID16 const> >, hb_set_t const&, $_5 const&, (void*)0>, hb_set_t const&, $_6 const&, (void*)0>, OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, OT::HBGlyphID16 const&>)#1}, (hb_function_sortedness_t)1, (void*)0>, hb_array_t<OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const>, OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const, (void*)0, (void*)0, (void*)0>(hb_subset_context_t*, hb_map_iter_t<hb_filter_iter_t<hb_filter_iter_t<hb_zip_iter_t<OT::Layout::Common::Coverage::iter_t, hb_array_t<OT::HBGlyphID16 const> >, hb_set_t const&, $_5 const&, (void*)0>, hb_set_t const&, $_6 const&, (void*)0>, OT::Layout::GSUB_impl::ReverseChainSingleSubstFormat1::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, OT::HBGlyphID16 const&>)#1}, (hb_function_sortedness_t)1, (void*)0>, hb_array_t<OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const>, OT::OffsetTo<OT::Layout::Common::Coverage, OT::IntType<unsigned short, 2u>, true> const) const |
217 | | |
218 | | bool subset (hb_subset_context_t *c) const |
219 | 0 | { |
220 | 0 | TRACE_SUBSET (this); |
221 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
222 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
223 | 0 |
|
224 | 0 | const auto &lookahead = StructAfter<decltype (lookaheadX)> (backtrack); |
225 | 0 | const auto &substitute = StructAfter<decltype (substituteX)> (lookahead); |
226 | 0 |
|
227 | 0 | auto it = |
228 | 0 | + hb_zip (this+coverage, substitute) |
229 | 0 | | hb_filter (glyphset, hb_first) |
230 | 0 | | hb_filter (glyphset, hb_second) |
231 | 0 | | hb_map_retains_sorting ([&] (hb_pair_t<hb_codepoint_t, const HBGlyphID16 &> p) -> hb_codepoint_pair_t |
232 | 0 | { return hb_pair (glyph_map[p.first], glyph_map[p.second]); }) |
233 | 0 | ; |
234 | 0 |
|
235 | 0 | return_trace (bool (it) && serialize (c, it, backtrack.iter (), lookahead.iter ())); |
236 | 0 | } |
237 | | }; |
238 | | |
239 | | } |
240 | | } |
241 | | } |
242 | | |
243 | | #endif /* HB_OT_LAYOUT_GSUB_REVERSECHAINSINGLESUBSTFORMAT1_HH */ |