/work/workdir/UnpackedTarball/harfbuzz/src/hb-ot-layout-gsub-table.hh
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2007,2008,2009,2010 Red Hat, Inc. |
3 | | * Copyright © 2010,2012,2013 Google, Inc. |
4 | | * |
5 | | * This is part of HarfBuzz, a text shaping library. |
6 | | * |
7 | | * Permission is hereby granted, without written agreement and without |
8 | | * license or royalty fees, to use, copy, modify, and distribute this |
9 | | * software and its documentation for any purpose, provided that the |
10 | | * above copyright notice and the following two paragraphs appear in |
11 | | * all copies of this software. |
12 | | * |
13 | | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
14 | | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
15 | | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
16 | | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
17 | | * DAMAGE. |
18 | | * |
19 | | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
20 | | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
21 | | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
22 | | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
23 | | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
24 | | * |
25 | | * Red Hat Author(s): Behdad Esfahbod |
26 | | * Google Author(s): Behdad Esfahbod |
27 | | */ |
28 | | |
29 | | #ifndef HB_OT_LAYOUT_GSUB_TABLE_HH |
30 | | #define HB_OT_LAYOUT_GSUB_TABLE_HH |
31 | | |
32 | | #include "OT/Layout/GSUB/GSUB.hh" |
33 | | |
34 | | namespace OT { |
35 | | namespace Layout { |
36 | | namespace GSUB_impl { |
37 | | |
38 | | // TODO(garretrieger): Move into the new layout directory. |
39 | | /* Out-of-class implementation for methods recursing */ |
40 | | |
41 | | #ifndef HB_NO_OT_LAYOUT |
42 | | /*static*/ inline bool ExtensionSubst::is_reverse () const |
43 | 0 | { |
44 | 0 | return SubstLookup::lookup_type_is_reverse (get_type ()); |
45 | 0 | } |
46 | | template <typename context_t> |
47 | | /*static*/ typename context_t::return_t SubstLookup::dispatch_recurse_func (context_t *c, unsigned int lookup_index) |
48 | 0 | { |
49 | 0 | const SubstLookup &l = c->face->table.GSUB.get_relaxed ()->table->get_lookup (lookup_index); |
50 | 0 | return l.dispatch (c); |
51 | 0 | } |
52 | | |
53 | | /*static*/ typename hb_closure_context_t::return_t SubstLookup::closure_glyphs_recurse_func (hb_closure_context_t *c, unsigned lookup_index, hb_set_t *covered_seq_indices, unsigned seq_index, unsigned end_index) |
54 | 0 | { |
55 | 0 | const SubstLookup &l = c->face->table.GSUB.get_relaxed ()->table->get_lookup (lookup_index); |
56 | 0 | if (l.may_have_non_1to1 ()) |
57 | 0 | hb_set_add_range (covered_seq_indices, seq_index, end_index); |
58 | 0 | return l.dispatch (c); |
59 | 0 | } |
60 | | |
61 | | /*static*/ hb_depend_context_t::return_t SubstLookup::depend_glyphs_recurse_func (hb_depend_context_t *c, unsigned lookup_index, hb_bit_page_t *covered_seq_indices, unsigned seq_index, unsigned end_index) |
62 | 0 | { |
63 | 0 | const SubstLookup &l = c->face->table.GSUB.get_relaxed ()->table->get_lookup (lookup_index); |
64 | 0 | /* After a non-1-to-1 lookup (expansion/contraction), subsequent lookups in the same |
65 | 0 | * contextual rule see all glyphs, not position-specific ones. This matches closure behavior. |
66 | 0 | * Mark sequence positions as covered so later lookups use the full glyph set. */ |
67 | 0 | if (l.may_have_non_1to1 ()) |
68 | 0 | covered_seq_indices->add_range (seq_index, end_index); |
69 | 0 |
|
70 | 0 | hb_depend_context_t::recurse_key_t key; |
71 | 0 | if (!c->get_recurse_key (lookup_index, &key)) |
72 | 0 | return hb_empty_t (); |
73 | 0 |
|
74 | 0 | hb_depend_context_t::return_t ret = l.dispatch (c); |
75 | 0 | c->finish_recurse (key); |
76 | 0 | return ret; |
77 | 0 | } |
78 | | |
79 | | template <> |
80 | | inline hb_closure_lookups_context_t::return_t |
81 | | SubstLookup::dispatch_recurse_func<hb_closure_lookups_context_t> (hb_closure_lookups_context_t *c, unsigned this_index) |
82 | 0 | { |
83 | 0 | const SubstLookup &l = c->face->table.GSUB.get_relaxed ()->table->get_lookup (this_index); |
84 | 0 | return l.closure_lookups (c, this_index); |
85 | 0 | } |
86 | | |
87 | | template <> |
88 | | inline bool SubstLookup::dispatch_recurse_func<hb_ot_apply_context_t> (hb_ot_apply_context_t *c, unsigned int lookup_index) |
89 | 79 | { |
90 | 79 | auto *gsub = c->face->table.GSUB.get_relaxed (); |
91 | 79 | const SubstLookup &l = gsub->table->get_lookup (lookup_index); |
92 | 79 | unsigned int saved_lookup_props = c->lookup_props; |
93 | 79 | unsigned int saved_lookup_index = c->lookup_index; |
94 | 79 | c->set_lookup_index (lookup_index); |
95 | 79 | c->set_lookup_props (l.get_props ()); |
96 | | |
97 | 79 | uint32_t stack_match_positions[8]; |
98 | 79 | hb_vector_t<uint32_t> saved_match_positions; |
99 | 79 | saved_match_positions.set_storage (stack_match_positions); |
100 | 79 | hb_swap (c->match_positions, saved_match_positions); |
101 | | |
102 | 79 | bool ret = false; |
103 | 79 | auto *accel = gsub->get_accel (lookup_index); |
104 | 79 | ret = accel && accel->apply (c, false); |
105 | | |
106 | 79 | c->set_lookup_index (saved_lookup_index); |
107 | 79 | c->set_lookup_props (saved_lookup_props); |
108 | | |
109 | 79 | hb_swap (c->match_positions, saved_match_positions); |
110 | | |
111 | 79 | return ret; |
112 | 79 | } |
113 | | #endif |
114 | | |
115 | | } /* namespace GSUB_impl */ |
116 | | } /* namespace Layout */ |
117 | | |
118 | | inline void |
119 | | GSUB_accelerator_t::depend (hb_depend_data_builder_t *builder, hb_face_t *face) const |
120 | 0 | { |
121 | 0 | if (!this->table->has_data ()) return; |
122 | 0 |
|
123 | 0 | unsigned num_features = this->table->get_feature_count (); |
124 | 0 | unsigned num_lookups = this->table->get_lookup_count (); |
125 | 0 |
|
126 | 0 | hb_vector_t<hb_tag_t> feature_tags; |
127 | 0 | if (!builder->check_success (feature_tags.resize (num_features))) |
128 | 0 | return; |
129 | 0 | this->table->get_feature_tags (0, &num_features, feature_tags.arrayZ); |
130 | 0 |
|
131 | 0 | if (!builder->init_lookup_features (num_lookups)) |
132 | 0 | return; |
133 | 0 |
|
134 | 0 | hb_vector_t<hb_tag_t> feature_query_v; |
135 | 0 | feature_query_v.resize (2); |
136 | 0 | feature_query_v[1] = 0; |
137 | 0 |
|
138 | 0 | hb_set_t seen_features; |
139 | 0 | hb_set_t feature_indexes, lookup_indexes; |
140 | 0 |
|
141 | 0 | for (auto ft : feature_tags) |
142 | 0 | { |
143 | 0 | if (seen_features.has (ft)) continue; |
144 | 0 | seen_features.add (ft); |
145 | 0 | feature_query_v[0] = ft; |
146 | 0 | feature_indexes.reset (); |
147 | 0 | hb_ot_layout_collect_features (face, HB_OT_TAG_GSUB, nullptr, nullptr, |
148 | 0 | feature_query_v.arrayZ, &feature_indexes); |
149 | 0 | lookup_indexes.reset (); |
150 | 0 | for (auto feature_index : feature_indexes) |
151 | 0 | this->table->get_feature (feature_index).add_lookup_indexes_to (&lookup_indexes); |
152 | 0 |
|
153 | 0 | for (auto lookup_index : lookup_indexes) |
154 | 0 | if (unlikely (!builder->add_lookup_feature (lookup_index, ft))) |
155 | 0 | return; |
156 | 0 |
|
157 | 0 | auto &fv = this->table->get_feature_variations (); |
158 | 0 | auto fi_count = fv.record_count (); |
159 | 0 | for (unsigned i = 0; i < fi_count; i++) |
160 | 0 | { |
161 | 0 | lookup_indexes.reset (); |
162 | 0 | for (auto feature_index : feature_indexes) |
163 | 0 | { |
164 | 0 | auto feature_ptr = fv.find_substitute (i, feature_index); |
165 | 0 | if (feature_ptr != nullptr) |
166 | 0 | feature_ptr->add_lookup_indexes_to (&lookup_indexes); |
167 | 0 | } |
168 | 0 | for (auto lookup_index : lookup_indexes) |
169 | 0 | if (unlikely (!builder->add_lookup_feature (lookup_index, ft))) |
170 | 0 | return; |
171 | 0 | } |
172 | 0 | } |
173 | 0 |
|
174 | 0 | if (unlikely (!builder->finish_lookup_features ())) |
175 | 0 | return; |
176 | 0 |
|
177 | 0 | hb_set_t all_glyphs; |
178 | 0 | all_glyphs.add_range (0, face->get_num_glyphs () - 1); |
179 | 0 |
|
180 | 0 | hb_depend_context_t c (builder, face, &all_glyphs); |
181 | 0 |
|
182 | 0 | for (unsigned i = 0; i < num_lookups; i++) |
183 | 0 | { |
184 | 0 | auto features = builder->get_lookup_features (i); |
185 | 0 | if (!features) |
186 | 0 | { |
187 | 0 | DEBUG_MSG_LEVEL (DEPEND, nullptr, 1, 0, |
188 | 0 | "Skipping lookup %u (no features)", i); |
189 | 0 | continue; |
190 | 0 | } |
191 | 0 | DEBUG_MSG_LEVEL (DEPEND, nullptr, 1, 0, |
192 | 0 | "Processing lookup %u with features:", i); |
193 | 0 | c.lookup_index = i; |
194 | 0 | c.reset_recurse_cache (); |
195 | 0 | c.lookups_seen.clear (); |
196 | 0 | c.lookups_seen.add (i); /* Seed for A→B→A cycle detection in recurse(). */ |
197 | 0 | this->table->get_lookup (i).depend (&c); |
198 | 0 | } |
199 | 0 | } |
200 | | |
201 | | } /* namespace OT */ |
202 | | |
203 | | #endif /* HB_OT_LAYOUT_GSUB_TABLE_HH */ |