/src/harfbuzz/src/OT/Layout/GSUB/SingleSubstFormat2.hh
Line | Count | Source |
1 | | #ifndef OT_LAYOUT_GSUB_SINGLESUBSTFORMAT2_HH |
2 | | #define OT_LAYOUT_GSUB_SINGLESUBSTFORMAT2_HH |
3 | | |
4 | | #include "Common.hh" |
5 | | |
6 | | namespace OT { |
7 | | namespace Layout { |
8 | | namespace GSUB_impl { |
9 | | |
10 | | template <typename Types> |
11 | | struct SingleSubstFormat2_4 |
12 | | { |
13 | | protected: |
14 | | HBUINT16 format; /* Format identifier--format = 2 */ |
15 | | typename Types::template OffsetTo<Coverage> |
16 | | coverage; /* Offset to Coverage table--from |
17 | | * beginning of Substitution table */ |
18 | | Array16Of<typename Types::HBGlyphID> |
19 | | substitute; /* Array of substitute |
20 | | * GlyphIDs--ordered by Coverage Index */ |
21 | | |
22 | | public: |
23 | | DEFINE_SIZE_ARRAY (4 + Types::size, substitute); |
24 | | |
25 | | bool sanitize (hb_sanitize_context_t *c) const |
26 | 2.10k | { |
27 | 2.10k | TRACE_SANITIZE (this); |
28 | 2.10k | return_trace (coverage.sanitize (c, this) && substitute.sanitize (c)); |
29 | 2.10k | } |
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 depend (hb_depend_context_t *c) const |
38 | 0 | { |
39 | 0 | auto &cov = this+coverage; |
40 | 0 | auto &glyph_set = c->parent_active_glyphs (); |
41 | 0 |
|
42 | 0 | // Filter by active glyphs like closure does |
43 | 0 | if (substitute.len > glyph_set.get_population () * 4) |
44 | 0 | { |
45 | 0 | for (auto g : glyph_set) |
46 | 0 | { |
47 | 0 | unsigned i = cov.get_coverage (g); |
48 | 0 | if (i == NOT_COVERED || i >= substitute.len) |
49 | 0 | continue; |
50 | 0 | c->depend_data->add_gsub_lookup (g, c->lookup_index, substitute.arrayZ[i]); |
51 | 0 | } |
52 | 0 |
|
53 | 0 | return; |
54 | 0 | } |
55 | 0 |
|
56 | 0 | + hb_zip (cov, substitute) |
57 | 0 | | hb_filter (glyph_set, hb_first) |
58 | 0 | | hb_apply ([&] (const hb_codepoint_pair_t &_) { c->depend_data->add_gsub_lookup (_.first, c->lookup_index, _.second); }) |
59 | 0 | ; |
60 | 0 | } |
61 | | |
62 | | void closure (hb_closure_context_t *c) const |
63 | 0 | { |
64 | 0 | auto &cov = this+coverage; |
65 | 0 | auto &glyph_set = c->parent_active_glyphs (); |
66 | |
|
67 | 0 | if (substitute.len > glyph_set.get_population () * 4) |
68 | 0 | { |
69 | 0 | for (auto g : glyph_set) |
70 | 0 | { |
71 | 0 | unsigned i = cov.get_coverage (g); |
72 | 0 | if (i == NOT_COVERED || i >= substitute.len) |
73 | 0 | continue; |
74 | 0 | c->output->add (substitute.arrayZ[i]); |
75 | 0 | } |
76 | |
|
77 | 0 | return; |
78 | 0 | } |
79 | | |
80 | 0 | + hb_zip (cov, substitute) |
81 | 0 | | hb_filter (glyph_set, hb_first) |
82 | 0 | | hb_map (hb_second) |
83 | 0 | | hb_sink (c->output) |
84 | 0 | ; |
85 | 0 | } |
86 | | |
87 | 0 | void closure_lookups (hb_closure_lookups_context_t *c) const {} |
88 | | |
89 | | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
90 | 0 | { |
91 | 0 | if (unlikely (!(this+coverage).collect_coverage (c->input))) return; |
92 | 0 | + hb_zip (this+coverage, substitute) |
93 | 0 | | hb_map (hb_second) |
94 | 0 | | hb_sink (c->output) |
95 | 0 | ; |
96 | 0 | } |
97 | | |
98 | 0 | const Coverage &get_coverage () const { return this+coverage; } |
99 | | |
100 | | bool would_apply (hb_would_apply_context_t *c) const |
101 | 0 | { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } |
102 | | |
103 | | unsigned |
104 | | get_glyph_alternates (hb_codepoint_t glyph_id, |
105 | | unsigned start_offset, |
106 | | unsigned *alternate_count /* IN/OUT. May be NULL. */, |
107 | | hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const |
108 | 0 | { |
109 | 0 | unsigned int index = (this+coverage).get_coverage (glyph_id); |
110 | 0 | if (likely (index == NOT_COVERED)) |
111 | 0 | { |
112 | 0 | if (alternate_count) |
113 | 0 | *alternate_count = 0; |
114 | 0 | return 0; |
115 | 0 | } |
116 | | |
117 | 0 | if (alternate_count && *alternate_count && alternate_glyphs) |
118 | 0 | { |
119 | 0 | glyph_id = substitute[index]; |
120 | |
|
121 | 0 | *alternate_glyphs = glyph_id; |
122 | 0 | *alternate_count = 1; |
123 | 0 | } |
124 | |
|
125 | 0 | return 1; |
126 | 0 | } |
127 | | |
128 | | void |
129 | | collect_glyph_alternates (hb_map_t *alternate_count /* IN/OUT */, |
130 | | hb_map_t *alternate_glyphs /* IN/OUT */) const |
131 | 0 | { |
132 | 0 | + hb_zip (this+coverage, substitute) |
133 | 0 | | hb_apply ([&] (const hb_pair_t<hb_codepoint_t, hb_codepoint_t> &p) -> void |
134 | 0 | { _hb_collect_glyph_alternates_add (p.first, p.second, |
135 | 0 | alternate_count, alternate_glyphs); }) |
136 | 0 | ; |
137 | 0 | } |
138 | | |
139 | | bool apply (hb_ot_apply_context_t *c) const |
140 | 0 | { |
141 | 0 | TRACE_APPLY (this); |
142 | 0 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
143 | 0 | if (index == NOT_COVERED) return_trace (false); |
144 | | |
145 | 0 | if (unlikely (index >= substitute.len)) return_trace (false); |
146 | | |
147 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
148 | 0 | { |
149 | 0 | c->buffer->sync_so_far (); |
150 | 0 | c->buffer->message (c->font, |
151 | 0 | "replacing glyph at %u (single substitution)", |
152 | 0 | c->buffer->idx); |
153 | 0 | } |
154 | |
|
155 | 0 | c->replace_glyph (substitute[index]); |
156 | |
|
157 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
158 | 0 | { |
159 | 0 | c->buffer->message (c->font, |
160 | 0 | "replaced glyph at %u (single substitution)", |
161 | 0 | c->buffer->idx - 1u); |
162 | 0 | } |
163 | |
|
164 | 0 | return_trace (true); |
165 | 0 | } |
166 | | |
167 | | template<typename Iterator, |
168 | | hb_requires (hb_is_sorted_source_of (Iterator, |
169 | | hb_codepoint_pair_t))> |
170 | | bool serialize (hb_serialize_context_t *c, |
171 | | Iterator it) |
172 | 0 | { |
173 | 0 | TRACE_SERIALIZE (this); |
174 | 0 | auto substitutes = |
175 | 0 | + it |
176 | 0 | | hb_map (hb_second) |
177 | 0 | ; |
178 | 0 | auto glyphs = |
179 | 0 | + it |
180 | 0 | | hb_map_retains_sorting (hb_first) |
181 | 0 | ; |
182 | 0 | if (unlikely (!c->extend_min (this))) return_trace (false); |
183 | 0 | if (unlikely (!substitute.serialize (c, substitutes))) return_trace (false); |
184 | 0 | if (unlikely (!coverage.serialize_serialize (c, glyphs))) return_trace (false); |
185 | 0 | return_trace (true); |
186 | 0 | } Unexecuted instantiation: hb-ot-face.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_map_iter_tI16hb_filter_iter_tIS6_IN23hb_bit_set_invertible_t6iter_tEZNKS1_20SingleSubstFormat1_3IS3_E6subsetEP19hb_subset_context_tEUljE_L24hb_function_sortedness_t1ELPv0EERK8hb_set_tRK3$_7LSG_0EEZNKSB_6subsetESD_EUl9hb_pair_tIjjEE_LSF_1ELSG_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_SQ_EE5valuesrSU_18is_sorted_iteratorEvE4typeELSG_0EEEbP22hb_serialize_context_tSU_ Unexecuted instantiation: hb-ot-face.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_map_iter_tI16hb_filter_iter_tIS7_I13hb_zip_iter_tINS0_6Common8Coverage6iter_tE10hb_array_tIKNS_11HBGlyphID16EEERK8hb_set_tRK3$_6LPv0EESJ_RK3$_7LSN_0EEZNKS4_6subsetEP19hb_subset_context_tEUl9hb_pair_tIjRSE_EE_L24hb_function_sortedness_t1ELSN_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_SV_IjjEEE5valuesrS12_18is_sorted_iteratorEvE4typeELSN_0EEEbP22hb_serialize_context_tS12_ Unexecuted instantiation: hb-aat-layout.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_map_iter_tI16hb_filter_iter_tIS6_IN23hb_bit_set_invertible_t6iter_tEZNKS1_20SingleSubstFormat1_3IS3_E6subsetEP19hb_subset_context_tEUljE_L24hb_function_sortedness_t1ELPv0EERK8hb_set_tRK3$_7LSG_0EEZNKSB_6subsetESD_EUl9hb_pair_tIjjEE_LSF_1ELSG_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_SQ_EE5valuesrSU_18is_sorted_iteratorEvE4typeELSG_0EEEbP22hb_serialize_context_tSU_ Unexecuted instantiation: hb-aat-layout.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_map_iter_tI16hb_filter_iter_tIS7_I13hb_zip_iter_tINS0_6Common8Coverage6iter_tE10hb_array_tIKNS_11HBGlyphID16EEERK8hb_set_tRK3$_6LPv0EESJ_RK3$_7LSN_0EEZNKS4_6subsetEP19hb_subset_context_tEUl9hb_pair_tIjRSE_EE_L24hb_function_sortedness_t1ELSN_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_SV_IjjEEE5valuesrS12_18is_sorted_iteratorEvE4typeELSN_0EEEbP22hb_serialize_context_tS12_ Unexecuted instantiation: hb-ot-layout.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_map_iter_tI16hb_filter_iter_tIS6_IN23hb_bit_set_invertible_t6iter_tEZNKS1_20SingleSubstFormat1_3IS3_E6subsetEP19hb_subset_context_tEUljE_L24hb_function_sortedness_t1ELPv0EERK8hb_set_tRK3$_7LSG_0EEZNKSB_6subsetESD_EUl9hb_pair_tIjjEE_LSF_1ELSG_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_SQ_EE5valuesrSU_18is_sorted_iteratorEvE4typeELSG_0EEEbP22hb_serialize_context_tSU_ Unexecuted instantiation: hb-ot-layout.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_map_iter_tI16hb_filter_iter_tIS7_I13hb_zip_iter_tINS0_6Common8Coverage6iter_tE10hb_array_tIKNS_11HBGlyphID16EEERK8hb_set_tRK3$_6LPv0EESJ_RK3$_7LSN_0EEZNKS4_6subsetEP19hb_subset_context_tEUl9hb_pair_tIjRSE_EE_L24hb_function_sortedness_t1ELSN_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_SV_IjjEEE5valuesrS12_18is_sorted_iteratorEvE4typeELSN_0EEEbP22hb_serialize_context_tS12_ Unexecuted instantiation: _ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_zip_iter_tI17hb_sorted_array_tINS_11HBGlyphID16EE10hb_array_tIS8_EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_9hb_pair_tIjjEEE5valuesrSE_18is_sorted_iteratorEvE4typeELPv0EEEbP22hb_serialize_context_tSE_ Unexecuted instantiation: hb-ot-shaper-arabic.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_map_iter_tI16hb_filter_iter_tIS6_IN23hb_bit_set_invertible_t6iter_tEZNKS1_20SingleSubstFormat1_3IS3_E6subsetEP19hb_subset_context_tEUljE_L24hb_function_sortedness_t1ELPv0EERK8hb_set_tRK3$_7LSG_0EEZNKSB_6subsetESD_EUl9hb_pair_tIjjEE_LSF_1ELSG_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_SQ_EE5valuesrSU_18is_sorted_iteratorEvE4typeELSG_0EEEbP22hb_serialize_context_tSU_ Unexecuted instantiation: hb-ot-shaper-arabic.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat2_4INS0_10SmallTypesEE9serializeI13hb_map_iter_tI16hb_filter_iter_tIS7_I13hb_zip_iter_tINS0_6Common8Coverage6iter_tE10hb_array_tIKNS_11HBGlyphID16EEERK8hb_set_tRK3$_6LPv0EESJ_RK3$_7LSN_0EEZNKS4_6subsetEP19hb_subset_context_tEUl9hb_pair_tIjRSE_EE_L24hb_function_sortedness_t1ELSN_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_SV_IjjEEE5valuesrS12_18is_sorted_iteratorEvE4typeELSN_0EEEbP22hb_serialize_context_tS12_ |
187 | | |
188 | | bool subset (hb_subset_context_t *c) const |
189 | 0 | { |
190 | 0 | TRACE_SUBSET (this); |
191 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
192 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
193 | 0 |
|
194 | 0 | auto it = |
195 | 0 | + hb_zip (this+coverage, substitute) |
196 | 0 | | hb_filter (glyphset, hb_first) |
197 | 0 | | hb_filter (glyphset, hb_second) |
198 | 0 | | hb_map_retains_sorting ([&] (hb_pair_t<hb_codepoint_t, const typename Types::HBGlyphID &> p) -> hb_codepoint_pair_t |
199 | 0 | { return hb_pair (glyph_map[p.first], glyph_map[p.second]); }) |
200 | 0 | ; |
201 | 0 |
|
202 | 0 | bool ret = bool (it); |
203 | 0 | SingleSubst_serialize (c->serializer, it); |
204 | 0 | return_trace (ret); |
205 | 0 | } |
206 | | }; |
207 | | |
208 | | } |
209 | | } |
210 | | } |
211 | | |
212 | | #endif /* OT_LAYOUT_GSUB_SINGLESUBSTFORMAT2_HH */ |