/src/harfbuzz/src/OT/Layout/GSUB/SingleSubstFormat1.hh
Line | Count | Source |
1 | | #ifndef OT_LAYOUT_GSUB_SINGLESUBSTFORMAT1_HH |
2 | | #define OT_LAYOUT_GSUB_SINGLESUBSTFORMAT1_HH |
3 | | |
4 | | #include "Common.hh" |
5 | | |
6 | | namespace OT { |
7 | | namespace Layout { |
8 | | namespace GSUB_impl { |
9 | | |
10 | | template <typename Types> |
11 | | struct SingleSubstFormat1_3 |
12 | | { |
13 | | protected: |
14 | | HBUINT16 format; /* Format identifier--format = 1 */ |
15 | | typename Types::template OffsetTo<Coverage> |
16 | | coverage; /* Offset to Coverage table--from |
17 | | * beginning of Substitution table */ |
18 | | typename Types::HBUINT |
19 | | deltaGlyphID; /* Add to original GlyphID to get |
20 | | * substitute GlyphID, modulo 0x10000 */ |
21 | | |
22 | | public: |
23 | | DEFINE_SIZE_STATIC (2 + 2 * Types::size); |
24 | | |
25 | | bool sanitize (hb_sanitize_context_t *c) const |
26 | 33 | { |
27 | 33 | TRACE_SANITIZE (this); |
28 | 33 | return_trace (c->check_struct (this) && |
29 | 33 | coverage.sanitize (c, this) && |
30 | | /* The coverage table may use a range to represent a set |
31 | | * of glyphs, which means a small number of bytes can |
32 | | * generate a large glyph set. Manually modify the |
33 | | * sanitizer max ops to take this into account. |
34 | | * |
35 | | * Note: This check *must* be right after coverage sanitize. */ |
36 | 33 | c->check_ops ((this + coverage).get_population () >> 1)); |
37 | 33 | } |
38 | | |
39 | | hb_codepoint_t get_mask () const |
40 | 0 | { return (1 << (8 * Types::size)) - 1; } |
41 | | |
42 | | bool intersects (const hb_set_t *glyphs) const |
43 | 0 | { return (this+coverage).intersects (glyphs); } |
44 | | |
45 | | bool may_have_non_1to1 () const |
46 | 0 | { return false; } |
47 | | |
48 | | void closure (hb_closure_context_t *c) const |
49 | 0 | { |
50 | 0 | hb_codepoint_t d = deltaGlyphID; |
51 | 0 | hb_codepoint_t mask = get_mask (); |
52 | | |
53 | | /* Help fuzzer avoid this function as much. */ |
54 | 0 | unsigned pop = (this+coverage).get_population (); |
55 | 0 | if (pop >= mask) |
56 | 0 | return; |
57 | | |
58 | 0 | hb_set_t intersection; |
59 | 0 | (this+coverage).intersect_set (c->parent_active_glyphs (), intersection); |
60 | | |
61 | | /* In degenerate fuzzer-found fonts, but not real fonts, |
62 | | * this table can keep adding new glyphs in each round of closure. |
63 | | * Refuse to close-over, if it maps glyph range to overlapping range. */ |
64 | 0 | hb_codepoint_t min_before = intersection.get_min (); |
65 | 0 | hb_codepoint_t max_before = intersection.get_max (); |
66 | 0 | hb_codepoint_t min_after = (min_before + d) & mask; |
67 | 0 | hb_codepoint_t max_after = (max_before + d) & mask; |
68 | 0 | if (intersection.get_population () == max_before - min_before + 1 && |
69 | 0 | ((min_before <= min_after && min_after <= max_before) || |
70 | 0 | (min_before <= max_after && max_after <= max_before))) |
71 | 0 | return; |
72 | | |
73 | 0 | + hb_iter (intersection) |
74 | 0 | | hb_map ([d, mask] (hb_codepoint_t g) { return (g + d) & mask; }) |
75 | 0 | | hb_sink (c->output) |
76 | 0 | ; |
77 | 0 | } |
78 | | |
79 | 0 | void closure_lookups (hb_closure_lookups_context_t *c) const {} |
80 | | |
81 | | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
82 | 0 | { |
83 | 0 | if (unlikely (!(this+coverage).collect_coverage (c->input))) return; |
84 | 0 | hb_codepoint_t d = deltaGlyphID; |
85 | 0 | hb_codepoint_t mask = get_mask (); |
86 | |
|
87 | 0 | + hb_iter (this+coverage) |
88 | 0 | | hb_map ([d, mask] (hb_codepoint_t g) { return (g + d) & mask; }) |
89 | 0 | | hb_sink (c->output) |
90 | 0 | ; |
91 | 0 | } |
92 | | |
93 | 0 | const Coverage &get_coverage () const { return this+coverage; } |
94 | | |
95 | | bool would_apply (hb_would_apply_context_t *c) const |
96 | 0 | { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } |
97 | | |
98 | | unsigned |
99 | | get_glyph_alternates (hb_codepoint_t glyph_id, |
100 | | unsigned start_offset, |
101 | | unsigned *alternate_count /* IN/OUT. May be NULL. */, |
102 | | hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const |
103 | 0 | { |
104 | 0 | unsigned int index = (this+coverage).get_coverage (glyph_id); |
105 | 0 | if (likely (index == NOT_COVERED)) |
106 | 0 | { |
107 | 0 | if (alternate_count) |
108 | 0 | *alternate_count = 0; |
109 | 0 | return 0; |
110 | 0 | } |
111 | | |
112 | 0 | if (alternate_count && *alternate_count) |
113 | 0 | { |
114 | 0 | hb_codepoint_t d = deltaGlyphID; |
115 | 0 | hb_codepoint_t mask = get_mask (); |
116 | |
|
117 | 0 | glyph_id = (glyph_id + d) & mask; |
118 | |
|
119 | 0 | *alternate_glyphs = glyph_id; |
120 | 0 | *alternate_count = 1; |
121 | 0 | } |
122 | |
|
123 | 0 | return 1; |
124 | 0 | } |
125 | | |
126 | | void |
127 | | collect_glyph_alternates (hb_map_t *alternate_count /* IN/OUT */, |
128 | | hb_map_t *alternate_glyphs /* IN/OUT */) const |
129 | 0 | { |
130 | 0 | hb_codepoint_t d = deltaGlyphID; |
131 | 0 | hb_codepoint_t mask = get_mask (); |
132 | |
|
133 | 0 | + hb_iter (this+coverage) |
134 | 0 | | hb_map ([d, mask] (hb_codepoint_t g) { return hb_pair (g, (g + d) & mask); }) |
135 | 0 | | hb_apply ([&] (const hb_pair_t<hb_codepoint_t, hb_codepoint_t> &p) -> void |
136 | 0 | { _hb_collect_glyph_alternates_add (p.first, p.second, |
137 | 0 | alternate_count, alternate_glyphs); }) |
138 | 0 | ; |
139 | 0 | } |
140 | | |
141 | | bool apply (hb_ot_apply_context_t *c) const |
142 | 0 | { |
143 | 0 | TRACE_APPLY (this); |
144 | 0 | hb_codepoint_t glyph_id = c->buffer->cur().codepoint; |
145 | 0 | unsigned int index = (this+coverage).get_coverage (glyph_id); |
146 | 0 | if (index == NOT_COVERED) return_trace (false); |
147 | | |
148 | 0 | hb_codepoint_t d = deltaGlyphID; |
149 | 0 | hb_codepoint_t mask = get_mask (); |
150 | |
|
151 | 0 | glyph_id = (glyph_id + d) & mask; |
152 | |
|
153 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
154 | 0 | { |
155 | 0 | c->buffer->sync_so_far (); |
156 | 0 | c->buffer->message (c->font, |
157 | 0 | "replacing glyph at %u (single substitution)", |
158 | 0 | c->buffer->idx); |
159 | 0 | } |
160 | |
|
161 | 0 | c->replace_glyph (glyph_id); |
162 | |
|
163 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
164 | 0 | { |
165 | 0 | c->buffer->message (c->font, |
166 | 0 | "replaced glyph at %u (single substitution)", |
167 | 0 | c->buffer->idx - 1u); |
168 | 0 | } |
169 | |
|
170 | 0 | return_trace (true); |
171 | 0 | } |
172 | | |
173 | | template<typename Iterator, |
174 | | hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_t))> |
175 | | bool serialize (hb_serialize_context_t *c, |
176 | | Iterator glyphs, |
177 | | unsigned delta) |
178 | 0 | { |
179 | 0 | TRACE_SERIALIZE (this); |
180 | 0 | if (unlikely (!c->extend_min (this))) return_trace (false); |
181 | 0 | if (unlikely (!coverage.serialize_serialize (c, glyphs))) return_trace (false); |
182 | 0 | c->check_assign (deltaGlyphID, delta, HB_SERIALIZE_ERROR_INT_OVERFLOW); |
183 | 0 | return_trace (true); |
184 | 0 | } Unexecuted instantiation: hb-ot-face.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tIS6_I16hb_filter_iter_tIS6_IN23hb_bit_set_invertible_t6iter_tEZNKS4_6subsetEP19hb_subset_context_tEUljE_L24hb_function_sortedness_t1ELPv0EERK8hb_set_tRK3$_7LSE_0EEZNKS4_6subsetESB_EUl9hb_pair_tIjjEE_LSD_1ELSE_0EERK3$_6LSD_1ELSE_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrSW_18is_sorted_iteratorEvE4typeELSE_0EEEbP22hb_serialize_context_tSW_j Unexecuted instantiation: hb-ot-face.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tIS6_I16hb_filter_iter_tIS7_I13hb_zip_iter_tINS0_6Common8Coverage6iter_tE10hb_array_tIKNS_11HBGlyphID16EEERK8hb_set_tRK3$_6LPv0EESJ_RK3$_7LSN_0EEZNKS1_20SingleSubstFormat2_4IS3_E6subsetEP19hb_subset_context_tEUl9hb_pair_tIjRSE_EE_L24hb_function_sortedness_t1ELSN_0EESM_LS11_1ELSN_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrS15_18is_sorted_iteratorEvE4typeELSN_0EEEbP22hb_serialize_context_tS15_j Unexecuted instantiation: hb-aat-layout.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tIS6_I16hb_filter_iter_tIS6_IN23hb_bit_set_invertible_t6iter_tEZNKS4_6subsetEP19hb_subset_context_tEUljE_L24hb_function_sortedness_t1ELPv0EERK8hb_set_tRK3$_7LSE_0EEZNKS4_6subsetESB_EUl9hb_pair_tIjjEE_LSD_1ELSE_0EERK3$_6LSD_1ELSE_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrSW_18is_sorted_iteratorEvE4typeELSE_0EEEbP22hb_serialize_context_tSW_j Unexecuted instantiation: hb-aat-layout.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tIS6_I16hb_filter_iter_tIS7_I13hb_zip_iter_tINS0_6Common8Coverage6iter_tE10hb_array_tIKNS_11HBGlyphID16EEERK8hb_set_tRK3$_6LPv0EESJ_RK3$_7LSN_0EEZNKS1_20SingleSubstFormat2_4IS3_E6subsetEP19hb_subset_context_tEUl9hb_pair_tIjRSE_EE_L24hb_function_sortedness_t1ELSN_0EESM_LS11_1ELSN_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrS15_18is_sorted_iteratorEvE4typeELSN_0EEEbP22hb_serialize_context_tS15_j Unexecuted instantiation: hb-ot-layout.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tIS6_I16hb_filter_iter_tIS6_IN23hb_bit_set_invertible_t6iter_tEZNKS4_6subsetEP19hb_subset_context_tEUljE_L24hb_function_sortedness_t1ELPv0EERK8hb_set_tRK3$_7LSE_0EEZNKS4_6subsetESB_EUl9hb_pair_tIjjEE_LSD_1ELSE_0EERK3$_6LSD_1ELSE_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrSW_18is_sorted_iteratorEvE4typeELSE_0EEEbP22hb_serialize_context_tSW_j Unexecuted instantiation: hb-ot-layout.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tIS6_I16hb_filter_iter_tIS7_I13hb_zip_iter_tINS0_6Common8Coverage6iter_tE10hb_array_tIKNS_11HBGlyphID16EEERK8hb_set_tRK3$_6LPv0EESJ_RK3$_7LSN_0EEZNKS1_20SingleSubstFormat2_4IS3_E6subsetEP19hb_subset_context_tEUl9hb_pair_tIjRSE_EE_L24hb_function_sortedness_t1ELSN_0EESM_LS11_1ELSN_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrS15_18is_sorted_iteratorEvE4typeELSN_0EEEbP22hb_serialize_context_tS15_j Unexecuted instantiation: hb-ot-shaper-arabic.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tI13hb_zip_iter_tI17hb_sorted_array_tINS_11HBGlyphID16EE10hb_array_tIS9_EERK3$_6L24hb_function_sortedness_t1ELPv0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrSL_18is_sorted_iteratorEvE4typeELSI_0EEEbP22hb_serialize_context_tSL_j Unexecuted instantiation: hb-ot-shaper-arabic.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tIS6_I16hb_filter_iter_tIS6_IN23hb_bit_set_invertible_t6iter_tEZNKS4_6subsetEP19hb_subset_context_tEUljE_L24hb_function_sortedness_t1ELPv0EERK8hb_set_tRK3$_7LSE_0EEZNKS4_6subsetESB_EUl9hb_pair_tIjjEE_LSD_1ELSE_0EERK3$_6LSD_1ELSE_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrSW_18is_sorted_iteratorEvE4typeELSE_0EEEbP22hb_serialize_context_tSW_j Unexecuted instantiation: hb-ot-shaper-arabic.cc:_ZN2OT6Layout9GSUB_impl20SingleSubstFormat1_3INS0_10SmallTypesEE9serializeI13hb_map_iter_tIS6_I16hb_filter_iter_tIS7_I13hb_zip_iter_tINS0_6Common8Coverage6iter_tE10hb_array_tIKNS_11HBGlyphID16EEERK8hb_set_tRK3$_6LPv0EESJ_RK3$_7LSN_0EEZNKS1_20SingleSubstFormat2_4IS3_E6subsetEP19hb_subset_context_tEUl9hb_pair_tIjRSE_EE_L24hb_function_sortedness_t1ELSN_0EESM_LS11_1ELSN_0EETnPN12hb_enable_ifIXaasr15hb_is_source_ofIT_jEE5valuesrS15_18is_sorted_iteratorEvE4typeELSN_0EEEbP22hb_serialize_context_tS15_j |
185 | | |
186 | | bool subset (hb_subset_context_t *c) const |
187 | 0 | { |
188 | 0 | TRACE_SUBSET (this); |
189 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
190 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
191 | 0 |
|
192 | 0 | hb_codepoint_t d = deltaGlyphID; |
193 | 0 | hb_codepoint_t mask = get_mask (); |
194 | 0 |
|
195 | 0 | hb_set_t intersection; |
196 | 0 | (this+coverage).intersect_set (glyphset, intersection); |
197 | 0 |
|
198 | 0 | auto it = |
199 | 0 | + hb_iter (intersection) |
200 | 0 | | hb_map_retains_sorting ([d, mask] (hb_codepoint_t g) { |
201 | 0 | return hb_codepoint_pair_t (g, |
202 | 0 | (g + d) & mask); }) |
203 | 0 | | hb_filter (glyphset, hb_second) |
204 | 0 | | hb_map_retains_sorting ([&] (hb_codepoint_pair_t p) -> hb_codepoint_pair_t |
205 | 0 | { return hb_pair (glyph_map[p.first], glyph_map[p.second]); }) |
206 | 0 | ; |
207 | 0 |
|
208 | 0 | bool ret = bool (it); |
209 | 0 | SingleSubst_serialize (c->serializer, it); |
210 | 0 | return_trace (ret); |
211 | 0 | } |
212 | | }; |
213 | | |
214 | | } |
215 | | } |
216 | | } |
217 | | |
218 | | |
219 | | #endif /* OT_LAYOUT_GSUB_SINGLESUBSTFORMAT1_HH */ |