/src/harfbuzz/src/OT/Layout/GSUB/LigatureSubstFormat1.hh
Line | Count | Source |
1 | | #ifndef OT_LAYOUT_GSUB_LIGATURESUBSTFORMAT1_HH |
2 | | #define OT_LAYOUT_GSUB_LIGATURESUBSTFORMAT1_HH |
3 | | |
4 | | #include "Common.hh" |
5 | | #include "LigatureSet.hh" |
6 | | |
7 | | namespace OT { |
8 | | namespace Layout { |
9 | | namespace GSUB_impl { |
10 | | |
11 | | template <typename Types> |
12 | | struct LigatureSubstFormat1_2 |
13 | | { |
14 | | protected: |
15 | | HBUINT16 format; /* Format identifier--format = 1 */ |
16 | | typename Types::template LOffsetTo<Coverage> |
17 | | coverage; /* Offset to Coverage table--from |
18 | | * beginning of Substitution table */ |
19 | | typename Types::template ArrayOf<typename Types::template OffsetTo<LigatureSet<Types>>> |
20 | | ligatureSet; /* Array LigatureSet tables |
21 | | * ordered by Coverage Index */ |
22 | | public: |
23 | | DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + Types::HBUINT::static_size, ligatureSet); |
24 | | |
25 | | bool sanitize (hb_sanitize_context_t *c) const |
26 | 146 | { |
27 | 146 | TRACE_SANITIZE (this); |
28 | 146 | return_trace (coverage.sanitize (c, this) && ligatureSet.sanitize (c, this)); |
29 | 146 | } OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::sanitize(hb_sanitize_context_t*) const Line | Count | Source | 26 | 146 | { | 27 | 146 | TRACE_SANITIZE (this); | 28 | 146 | return_trace (coverage.sanitize (c, this) && ligatureSet.sanitize (c, this)); | 29 | 146 | } |
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::sanitize(hb_sanitize_context_t*) const |
30 | | |
31 | | bool intersects (const hb_set_t *glyphs) const |
32 | 0 | { |
33 | 0 | return |
34 | 0 | + hb_zip (this+coverage, ligatureSet) |
35 | 0 | | hb_filter (*glyphs, hb_first) |
36 | 0 | | hb_map (hb_second) |
37 | 0 | | hb_map ([this, glyphs] (const typename Types::template OffsetTo<LigatureSet<Types>> &_) |
38 | 0 | { return (this+_).intersects (glyphs); }) |
39 | 0 | | hb_any |
40 | 0 | ; |
41 | 0 | } Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::intersects(hb_set_t const*) const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::intersects(hb_set_t const*) const |
42 | | |
43 | | bool may_have_non_1to1 () const |
44 | 0 | { return true; }Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::may_have_non_1to1() const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::may_have_non_1to1() const |
45 | | |
46 | | void depend (hb_depend_context_t *c) const |
47 | 0 | { |
48 | 0 | + hb_zip (this+coverage, ligatureSet) |
49 | 0 | | hb_filter (c->parent_active_glyphs (), hb_first) |
50 | 0 | | hb_apply ([&] (const hb_pair_t<hb_codepoint_t, const typename Types::template OffsetTo<LigatureSet<Types>>&> &_) |
51 | 0 | { |
52 | 0 | const LigatureSet<Types>& ls = this+_.second; |
53 | 0 | ls.depend (c, _.first); |
54 | 0 | }) |
55 | 0 | ; |
56 | 0 | } Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::depend(OT::hb_depend_context_t*) const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::depend(OT::hb_depend_context_t*) const |
57 | | |
58 | | void closure (hb_closure_context_t *c) const |
59 | 0 | { |
60 | 0 | + hb_zip (this+coverage, ligatureSet) |
61 | 0 | | hb_filter (c->parent_active_glyphs (), hb_first) |
62 | 0 | | hb_map (hb_second) |
63 | 0 | | hb_map (hb_add (this)) |
64 | 0 | | hb_apply ([c] (const LigatureSet<Types> &_) { _.closure (c); })Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::closure(OT::hb_closure_context_t*) const::{lambda(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes> const&) constUnexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::closure(OT::hb_closure_context_t*) const::{lambda(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes> const&) const |
65 | 0 | ; |
66 | |
|
67 | 0 | } Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::closure(OT::hb_closure_context_t*) const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::closure(OT::hb_closure_context_t*) const |
68 | | |
69 | 0 | void closure_lookups (hb_closure_lookups_context_t *c) const {}Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::closure_lookups(OT::hb_closure_lookups_context_t*) const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::closure_lookups(OT::hb_closure_lookups_context_t*) const |
70 | | |
71 | | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
72 | 0 | { |
73 | 0 | if (unlikely (!(this+coverage).collect_coverage (c->input))) return; |
74 | | |
75 | 0 | + hb_zip (this+coverage, ligatureSet) |
76 | 0 | | hb_map (hb_second) |
77 | 0 | | hb_map (hb_add (this)) |
78 | 0 | | hb_apply ([c] (const LigatureSet<Types> &_) { _.collect_glyphs (c); })Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::collect_glyphs(OT::hb_collect_glyphs_context_t*) const::{lambda(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes> const&) constUnexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::collect_glyphs(OT::hb_collect_glyphs_context_t*) const::{lambda(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes> const&) const |
79 | 0 | ; |
80 | 0 | } Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::collect_glyphs(OT::hb_collect_glyphs_context_t*) const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::collect_glyphs(OT::hb_collect_glyphs_context_t*) const |
81 | | |
82 | | void collect_second_glyphs (hb_set_digest_t *digest) const |
83 | 11 | { |
84 | 11 | + hb_iter (ligatureSet) |
85 | 11 | | hb_map (hb_add (this)) |
86 | 11 | | hb_apply ([digest] (const LigatureSet<Types> &_) { _.collect_seconds (*digest); })OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::collect_second_glyphs(hb_set_digest_t*) const::{lambda(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes> const&) constLine | Count | Source | 86 | 11 | | hb_apply ([digest] (const LigatureSet<Types> &_) { _.collect_seconds (*digest); }) |
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::collect_second_glyphs(hb_set_digest_t*) const::{lambda(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes> const&) const |
87 | 11 | ; |
88 | 11 | } OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::collect_second_glyphs(hb_set_digest_t*) const Line | Count | Source | 83 | 11 | { | 84 | 11 | + hb_iter (ligatureSet) | 85 | 11 | | hb_map (hb_add (this)) | 86 | 11 | | hb_apply ([digest] (const LigatureSet<Types> &_) { _.collect_seconds (*digest); }) | 87 | 11 | ; | 88 | 11 | } |
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::collect_second_glyphs(hb_set_digest_t*) const |
89 | | |
90 | 11 | const Coverage &get_coverage () const { return this+coverage; }OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::get_coverage() const Line | Count | Source | 90 | 11 | const Coverage &get_coverage () const { return this+coverage; } |
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::get_coverage() const |
91 | | |
92 | | bool would_apply (hb_would_apply_context_t *c) const |
93 | 0 | { |
94 | 0 | unsigned int index = (this+coverage).get_coverage (c->glyphs[0]); |
95 | 0 | if (likely (index == NOT_COVERED)) return false; |
96 | | |
97 | 0 | const auto &lig_set = this+ligatureSet[index]; |
98 | 0 | return lig_set.would_apply (c); |
99 | 0 | } Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::would_apply(OT::hb_would_apply_context_t*) const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::would_apply(OT::hb_would_apply_context_t*) const |
100 | | |
101 | | struct external_cache_t |
102 | | { |
103 | | hb_ot_layout_mapping_cache_t coverage; |
104 | | hb_set_digest_t seconds; |
105 | | }; |
106 | | void *external_cache_create () const |
107 | 11 | { |
108 | 11 | external_cache_t *cache = (external_cache_t *) hb_malloc (sizeof (external_cache_t)); |
109 | 11 | if (likely (cache)) |
110 | 11 | { |
111 | 11 | cache->coverage.clear (); |
112 | | |
113 | 11 | cache->seconds.init (); |
114 | 11 | + hb_iter (ligatureSet) |
115 | 11 | | hb_map (hb_add (this)) |
116 | 11 | | hb_apply ([cache] (const LigatureSet<Types> &_) { _.collect_seconds (cache->seconds); })OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::external_cache_create() const::{lambda(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::SmallTypes> const&) constLine | Count | Source | 116 | 11 | | hb_apply ([cache] (const LigatureSet<Types> &_) { _.collect_seconds (cache->seconds); }) |
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::external_cache_create() const::{lambda(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes> const&)#1}::operator()(OT::Layout::GSUB_impl::LigatureSet<OT::Layout::MediumTypes> const&) const |
117 | 11 | ; |
118 | 11 | } |
119 | 11 | return cache; |
120 | 11 | } OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::external_cache_create() const Line | Count | Source | 107 | 11 | { | 108 | 11 | external_cache_t *cache = (external_cache_t *) hb_malloc (sizeof (external_cache_t)); | 109 | 11 | if (likely (cache)) | 110 | 11 | { | 111 | 11 | cache->coverage.clear (); | 112 | | | 113 | 11 | cache->seconds.init (); | 114 | 11 | + hb_iter (ligatureSet) | 115 | 11 | | hb_map (hb_add (this)) | 116 | 11 | | hb_apply ([cache] (const LigatureSet<Types> &_) { _.collect_seconds (cache->seconds); }) | 117 | 11 | ; | 118 | 11 | } | 119 | 11 | return cache; | 120 | 11 | } |
Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::external_cache_create() const |
121 | | |
122 | | bool apply (hb_ot_apply_context_t *c, void *external_cache) const |
123 | 0 | { |
124 | 0 | TRACE_APPLY (this); |
125 | 0 | hb_buffer_t *buffer = c->buffer; |
126 | |
|
127 | 0 | #ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE |
128 | 0 | external_cache_t *cache = (external_cache_t *) external_cache; |
129 | 0 | const hb_set_digest_t *seconds = cache ? &cache->seconds : nullptr; |
130 | 0 | unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint, cache ? &cache->coverage : nullptr); |
131 | | #else |
132 | | const hb_set_digest_t *seconds = nullptr; |
133 | | unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint); |
134 | | #endif |
135 | 0 | if (index == NOT_COVERED) return_trace (false); |
136 | | |
137 | 0 | const auto &lig_set = this+ligatureSet[index]; |
138 | 0 | return_trace (lig_set.apply (c, seconds)); |
139 | 0 | } Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::apply(OT::hb_ot_apply_context_t*, void*) const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::apply(OT::hb_ot_apply_context_t*, void*) const |
140 | | |
141 | | template <typename GlyphID> |
142 | | bool serialize (hb_serialize_context_t *c, |
143 | | hb_sorted_array_t<GlyphID> first_glyphs, |
144 | | hb_array_t<const unsigned int> ligature_per_first_glyph_count_list, |
145 | | hb_array_t<GlyphID> ligatures_list, |
146 | | hb_array_t<const unsigned int> component_count_list, |
147 | | hb_array_t<GlyphID> component_list /* Starting from second for each ligature */) |
148 | 0 | { |
149 | 0 | TRACE_SERIALIZE (this); |
150 | 0 | if (unlikely (!c->extend_min (this))) return_trace (false); |
151 | 0 | if (unlikely (!ligatureSet.serialize (c, first_glyphs.length))) return_trace (false); |
152 | 0 | for (unsigned int i = 0; i < first_glyphs.length; i++) |
153 | 0 | { |
154 | 0 | unsigned int ligature_count = ligature_per_first_glyph_count_list[i]; |
155 | 0 | if (unlikely (!ligatureSet[i] |
156 | 0 | .serialize_serialize (c, |
157 | 0 | ligatures_list.sub_array (0, ligature_count), |
158 | 0 | component_count_list.sub_array (0, ligature_count), |
159 | 0 | component_list))) return_trace (false); |
160 | 0 | ligatures_list += ligature_count; |
161 | 0 | component_count_list += ligature_count; |
162 | 0 | } |
163 | 0 | return_trace (coverage.serialize_serialize (c, first_glyphs)); |
164 | 0 | } |
165 | | |
166 | | bool subset (hb_subset_context_t *c) const |
167 | 0 | { |
168 | 0 | TRACE_SUBSET (this); |
169 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
170 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
171 | 0 |
|
172 | 0 | auto *out = c->serializer->start_embed (*this); |
173 | 0 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
174 | 0 | out->format = format; |
175 | 0 |
|
176 | 0 | // Due to a bug in some older versions of windows 7 the Coverage table must be |
177 | 0 | // packed after the LigatureSet and Ligature tables, so serialize Coverage first |
178 | 0 | // which places it last in the packed order. |
179 | 0 | hb_set_t new_coverage; |
180 | 0 | + hb_zip (this+coverage, hb_iter (ligatureSet) | hb_map (hb_add (this))) |
181 | 0 | | hb_filter (glyphset, hb_first) |
182 | 0 | | hb_filter ([&] (const LigatureSet<Types>& _) { |
183 | 0 | return _.intersects_lig_glyph (&glyphset); |
184 | 0 | }, hb_second) |
185 | 0 | | hb_map (hb_first) |
186 | 0 | | hb_sink (new_coverage); |
187 | 0 |
|
188 | 0 | if (!c->serializer->push<Coverage> () |
189 | 0 | ->serialize (c->serializer, |
190 | 0 | + new_coverage.iter () | hb_map_retains_sorting (glyph_map))) |
191 | 0 | { |
192 | 0 | c->serializer->pop_discard (); |
193 | 0 | return_trace (false); |
194 | 0 | } |
195 | 0 |
|
196 | 0 | unsigned coverage_idx = c->serializer->pop_pack (); |
197 | 0 | c->serializer->add_link (out->coverage, coverage_idx); |
198 | 0 |
|
199 | 0 | + hb_zip (this+coverage, ligatureSet) |
200 | 0 | | hb_filter (new_coverage, hb_first) |
201 | 0 | | hb_map (hb_second) |
202 | 0 | // to ensure that the repacker always orders the coverage table after the LigatureSet |
203 | 0 | // and LigatureSubtable's they will be linked to the Coverage table via a virtual link |
204 | 0 | // the coverage table object idx is passed down to facilitate this. |
205 | 0 | | hb_apply (subset_offset_array (c, out->ligatureSet, this, coverage_idx)) |
206 | 0 | ; |
207 | 0 |
|
208 | 0 | return_trace (bool (new_coverage)); |
209 | 0 | } Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::SmallTypes>::subset(hb_subset_context_t*) const Unexecuted instantiation: OT::Layout::GSUB_impl::LigatureSubstFormat1_2<OT::Layout::MediumTypes>::subset(hb_subset_context_t*) const |
210 | | }; |
211 | | |
212 | | } |
213 | | } |
214 | | } |
215 | | |
216 | | #endif /* OT_LAYOUT_GSUB_LIGATURESUBSTFORMAT1_HH */ |