@@ -131,9 +131,19 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m)
131131{
132132 m.global_mask = 1 ;
133133
134+ hb_tag_t required_feature_tag[2 ];
135+ unsigned int required_feature_index[2 ];
136+
134137 for (unsigned int table_index = 0 ; table_index < 2 ; table_index++) {
135138 m.chosen_script [table_index] = chosen_script[table_index];
136139 m.found_script [table_index] = found_script[table_index];
140+
141+ hb_ot_layout_language_get_required_feature (face,
142+ table_tags[table_index],
143+ script_index[table_index],
144+ language_index[table_index],
145+ &required_feature_tag[table_index],
146+ &required_feature_index[table_index]);
137147 }
138148
139149 if (!feature_infos.len )
@@ -183,13 +193,21 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m)
183193
184194 hb_bool_t found = false ;
185195 unsigned int feature_index[2 ];
186- for (unsigned int table_index = 0 ; table_index < 2 ; table_index++)
196+ for (unsigned int table_index = 0 ; table_index < 2 ; table_index++) {
197+ if (required_feature_index[table_index] != HB_OT_LAYOUT_NO_FEATURE_INDEX &&
198+ required_feature_tag[table_index] == info->tag ) {
199+ feature_index[table_index] = required_feature_index[table_index];
200+ required_feature_index[table_index] = HB_OT_LAYOUT_NO_FEATURE_INDEX;
201+ found = true ;
202+ continue ;
203+ }
187204 found |= hb_ot_layout_language_find_feature (face,
188205 table_tags[table_index],
189206 script_index[table_index],
190207 language_index[table_index],
191208 info->tag ,
192209 &feature_index[table_index]);
210+ }
193211 if (!found && !(info->flags & F_HAS_FALLBACK))
194212 continue ;
195213
@@ -229,13 +247,15 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m)
229247
230248 /* Collect lookup indices for features */
231249
232- unsigned int required_feature_index;
233- if (hb_ot_layout_language_get_required_feature_index (face,
234- table_tag,
235- script_index[table_index],
236- language_index[table_index],
237- &required_feature_index))
238- m.add_lookups (face, table_index, required_feature_index, 1 , true );
250+ /* XXX
251+ * Normally, any required feature will have been handled by the allocate-bits
252+ * loop above. However, if the feature tag was not known among the features
253+ * being applied by the shaper, then it won't have been processed yet - and
254+ * we have no basis for knowing which stage to assign it to. We arbitrarily
255+ * add its lookups here, before everything else, and hope that'll be OK.
256+ */
257+ if (required_feature_index[table_index] != HB_OT_LAYOUT_NO_FEATURE_INDEX)
258+ m.add_lookups (face, table_index, required_feature_index[table_index], 1 , true );
239259
240260 unsigned int stage_index = 0 ;
241261 unsigned int last_num_lookups = 0 ;
0 commit comments