/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.18k | { |
27 | 2.18k | TRACE_SANITIZE (this); |
28 | 2.18k | return_trace (coverage.sanitize (c, this) && substitute.sanitize (c)); |
29 | 2.18k | } |
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 closure (hb_closure_context_t *c) const |
38 | 0 | { |
39 | 0 | auto &cov = this+coverage; |
40 | 0 | auto &glyph_set = c->parent_active_glyphs (); |
41 | |
|
42 | 0 | if (substitute.len > glyph_set.get_population () * 4) |
43 | 0 | { |
44 | 0 | for (auto g : glyph_set) |
45 | 0 | { |
46 | 0 | unsigned i = cov.get_coverage (g); |
47 | 0 | if (i == NOT_COVERED || i >= substitute.len) |
48 | 0 | continue; |
49 | 0 | c->output->add (substitute.arrayZ[i]); |
50 | 0 | } |
51 | |
|
52 | 0 | return; |
53 | 0 | } |
54 | | |
55 | 0 | + hb_zip (cov, substitute) |
56 | 0 | | hb_filter (glyph_set, hb_first) |
57 | 0 | | hb_map (hb_second) |
58 | 0 | | hb_sink (c->output) |
59 | 0 | ; |
60 | 0 | } |
61 | | |
62 | 0 | void closure_lookups (hb_closure_lookups_context_t *c) const {} |
63 | | |
64 | | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
65 | 0 | { |
66 | 0 | if (unlikely (!(this+coverage).collect_coverage (c->input))) return; |
67 | 0 | + hb_zip (this+coverage, substitute) |
68 | 0 | | hb_map (hb_second) |
69 | 0 | | hb_sink (c->output) |
70 | 0 | ; |
71 | 0 | } |
72 | | |
73 | 18 | const Coverage &get_coverage () const { return this+coverage; } |
74 | | |
75 | | bool would_apply (hb_would_apply_context_t *c) const |
76 | 0 | { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } |
77 | | |
78 | | unsigned |
79 | | get_glyph_alternates (hb_codepoint_t glyph_id, |
80 | | unsigned start_offset, |
81 | | unsigned *alternate_count /* IN/OUT. May be NULL. */, |
82 | | hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const |
83 | 0 | { |
84 | 0 | unsigned int index = (this+coverage).get_coverage (glyph_id); |
85 | 0 | if (likely (index == NOT_COVERED)) |
86 | 0 | { |
87 | 0 | if (alternate_count) |
88 | 0 | *alternate_count = 0; |
89 | 0 | return 0; |
90 | 0 | } |
91 | | |
92 | 0 | if (alternate_count && *alternate_count) |
93 | 0 | { |
94 | 0 | glyph_id = substitute[index]; |
95 | |
|
96 | 0 | *alternate_glyphs = glyph_id; |
97 | 0 | *alternate_count = 1; |
98 | 0 | } |
99 | |
|
100 | 0 | return 1; |
101 | 0 | } |
102 | | |
103 | | void |
104 | | collect_glyph_alternates (hb_map_t *alternate_count /* IN/OUT */, |
105 | | hb_map_t *alternate_glyphs /* IN/OUT */) const |
106 | 0 | { |
107 | 0 | + hb_zip (this+coverage, substitute) |
108 | 0 | | hb_apply ([&] (const hb_pair_t<hb_codepoint_t, hb_codepoint_t> &p) -> void |
109 | 0 | { _hb_collect_glyph_alternates_add (p.first, p.second, |
110 | 0 | alternate_count, alternate_glyphs); }) |
111 | 0 | ; |
112 | 0 | } |
113 | | |
114 | | bool apply (hb_ot_apply_context_t *c) const |
115 | 0 | { |
116 | 0 | TRACE_APPLY (this); |
117 | 0 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
118 | 0 | if (index == NOT_COVERED) return_trace (false); |
119 | | |
120 | 0 | if (unlikely (index >= substitute.len)) return_trace (false); |
121 | | |
122 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
123 | 0 | { |
124 | 0 | c->buffer->sync_so_far (); |
125 | 0 | c->buffer->message (c->font, |
126 | 0 | "replacing glyph at %u (single substitution)", |
127 | 0 | c->buffer->idx); |
128 | 0 | } |
129 | |
|
130 | 0 | c->replace_glyph (substitute[index]); |
131 | |
|
132 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
133 | 0 | { |
134 | 0 | c->buffer->message (c->font, |
135 | 0 | "replaced glyph at %u (single substitution)", |
136 | 0 | c->buffer->idx - 1u); |
137 | 0 | } |
138 | |
|
139 | 0 | return_trace (true); |
140 | 0 | } |
141 | | |
142 | | template<typename Iterator, |
143 | | hb_requires (hb_is_sorted_source_of (Iterator, |
144 | | hb_codepoint_pair_t))> |
145 | | bool serialize (hb_serialize_context_t *c, |
146 | | Iterator it) |
147 | 0 | { |
148 | 0 | TRACE_SERIALIZE (this); |
149 | 0 | auto substitutes = |
150 | 0 | + it |
151 | 0 | | hb_map (hb_second) |
152 | 0 | ; |
153 | 0 | auto glyphs = |
154 | 0 | + it |
155 | 0 | | hb_map_retains_sorting (hb_first) |
156 | 0 | ; |
157 | 0 | if (unlikely (!c->extend_min (this))) return_trace (false); |
158 | 0 | if (unlikely (!substitute.serialize (c, substitutes))) return_trace (false); |
159 | 0 | if (unlikely (!coverage.serialize_serialize (c, glyphs))) return_trace (false); |
160 | 0 | return_trace (true); |
161 | 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_ |
162 | | |
163 | | bool subset (hb_subset_context_t *c) const |
164 | 0 | { |
165 | 0 | TRACE_SUBSET (this); |
166 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
167 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
168 | 0 |
|
169 | 0 | auto it = |
170 | 0 | + hb_zip (this+coverage, substitute) |
171 | 0 | | hb_filter (glyphset, hb_first) |
172 | 0 | | hb_filter (glyphset, hb_second) |
173 | 0 | | hb_map_retains_sorting ([&] (hb_pair_t<hb_codepoint_t, const typename Types::HBGlyphID &> p) -> hb_codepoint_pair_t |
174 | 0 | { return hb_pair (glyph_map[p.first], glyph_map[p.second]); }) |
175 | 0 | ; |
176 | 0 |
|
177 | 0 | bool ret = bool (it); |
178 | 0 | SingleSubst_serialize (c->serializer, it); |
179 | 0 | return_trace (ret); |
180 | 0 | } |
181 | | }; |
182 | | |
183 | | } |
184 | | } |
185 | | } |
186 | | |
187 | | #endif /* OT_LAYOUT_GSUB_SINGLESUBSTFORMAT2_HH */ |