68 {
69 feature_info_t *info = feature_infos.push();
70 if (unlikely (!info)) return;
71 if (unlikely (!tag)) return;
72 info->tag = tag;
73 info->seq = feature_infos.len;
74 info->max_value = value;
75 info->flags = flags;
76 info->default_value = (flags & F_GLOBAL) ? value : 0;
77 info->stage[0] = current_stage[0];
78 info->stage[1] = current_stage[1];
79 }
80
81 void
82 hb_ot_map_builder_t::add_lookups (hb_ot_map_t &m,
83 hb_face_t *face,
84 unsigned int table_index,
85 unsigned int feature_index,
86 unsigned int variations_index,
87 hb_mask_t mask,
88 bool auto_zwj)
89 {
90 unsigned int lookup_indices[32];
91 unsigned int offset, len;
92 unsigned int table_lookup_count;
93
94 table_lookup_count = hb_ot_layout_table_get_lookup_count (face, table_tags[table_index]);
95
96 offset = 0;
97 do {
98 len = ARRAY_LENGTH (lookup_indices);
99 hb_ot_layout_feature_with_variations_get_lookups (face,
100 table_tags[table_index],
101 feature_index,
102 variations_index,
103 offset, &len,
104 lookup_indices);
105
106 for (unsigned int i = 0; i < len; i++)
107 {
108 if (lookup_indices[i] >= table_lookup_count)
109 continue;
110 hb_ot_map_t::lookup_map_t *lookup = m.lookups[table_index].push ();
111 if (unlikely (!lookup))
112 return;
113 lookup->mask = mask;
114 lookup->index = lookup_indices[i];
115 lookup->auto_zwj = auto_zwj;
116 }
117
118 offset += len;
119 } while (len == ARRAY_LENGTH (lookup_indices));
120 }
121
122
123 void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func)
124 {
125 stage_info_t *s = stages[table_index].push ();
126 if (likely (s)) {
127 s->index = current_stage[table_index];
128 s->pause_func = pause_func;
129 }
130
131 current_stage[table_index]++;
132 }
133
134 void
135 hb_ot_map_builder_t::compile (hb_ot_map_t &m,
136 const int *coords,
137 unsigned int num_coords)
138 {
139 m.global_mask = 1;
140
141 unsigned int required_feature_index[2];
142 hb_tag_t required_feature_tag[2];
143 /* We default to applying required feature in stage 0. If the required
144 * feature has a tag that is known to the shaper, we apply required feature
145 * in the stage for that tag.
146 */
147 unsigned int required_feature_stage[2] = {0, 0};
148
149 for (unsigned int table_index = 0; table_index < 2; table_index++)
150 {
151 m.chosen_script[table_index] = chosen_script[table_index];
152 m.found_script[table_index] = found_script[table_index];
153
154 hb_ot_layout_language_get_required_feature (face,
155 table_tags[table_index],
156 script_index[table_index],
157 language_index[table_index],
158 &required_feature_index[table_index],
159 &required_feature_tag[table_index]);
171 feature_infos[++j] = feature_infos[i];
172 else {
173 if (feature_infos[i].flags & F_GLOBAL) {
174 feature_infos[j].flags |= F_GLOBAL;
175 feature_infos[j].max_value = feature_infos[i].max_value;
176 feature_infos[j].default_value = feature_infos[i].default_value;
177 } else {
178 feature_infos[j].flags &= ~F_GLOBAL;
179 feature_infos[j].max_value = MAX (feature_infos[j].max_value, feature_infos[i].max_value);
180 /* Inherit default_value from j */
181 }
182 feature_infos[j].flags |= (feature_infos[i].flags & F_HAS_FALLBACK);
183 feature_infos[j].stage[0] = MIN (feature_infos[j].stage[0], feature_infos[i].stage[0]);
184 feature_infos[j].stage[1] = MIN (feature_infos[j].stage[1], feature_infos[i].stage[1]);
185 }
186 feature_infos.shrink (j + 1);
187 }
188
189
190 /* Allocate bits now */
191 unsigned int next_bit = 1;
192 for (unsigned int i = 0; i < feature_infos.len; i++)
193 {
194 const feature_info_t *info = &feature_infos[i];
195
196 unsigned int bits_needed;
197
198 if ((info->flags & F_GLOBAL) && info->max_value == 1)
199 /* Uses the global bit */
200 bits_needed = 0;
201 else
202 /* Limit to 8 bits per feature. */
203 bits_needed = MIN(8u, _hb_bit_storage (info->max_value));
204
205 if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t))
206 continue; /* Feature disabled, or not enough bits. */
207
208
209 hb_bool_t found = false;
210 unsigned int feature_index[2];
211 for (unsigned int table_index = 0; table_index < 2; table_index++)
226 {
227 found |= hb_ot_layout_table_find_feature (face,
228 table_tags[table_index],
229 info->tag,
230 &feature_index[table_index]);
231 }
232 }
233 if (!found && !(info->flags & F_HAS_FALLBACK))
234 continue;
235
236
237 hb_ot_map_t::feature_map_t *map = m.features.push ();
238 if (unlikely (!map))
239 break;
240
241 map->tag = info->tag;
242 map->index[0] = feature_index[0];
243 map->index[1] = feature_index[1];
244 map->stage[0] = info->stage[0];
245 map->stage[1] = info->stage[1];
246 map->auto_zwj = !(info->flags & F_MANUAL_ZWJ);
247 if ((info->flags & F_GLOBAL) && info->max_value == 1) {
248 /* Uses the global bit */
249 map->shift = 0;
250 map->mask = 1;
251 } else {
252 map->shift = next_bit;
253 map->mask = (1u << (next_bit + bits_needed)) - (1u << next_bit);
254 next_bit += bits_needed;
255 m.global_mask |= (info->default_value << map->shift) & map->mask;
256 }
257 map->_1_mask = (1u << map->shift) & map->mask;
258 map->needs_fallback = !found;
259
260 }
261 feature_infos.shrink (0); /* Done with these */
262
263
264 add_gsub_pause (NULL);
265 add_gpos_pause (NULL);
266
267 for (unsigned int table_index = 0; table_index < 2; table_index++)
268 {
269 /* Collect lookup indices for features */
270
271 unsigned int variations_index;
272 hb_ot_layout_table_find_feature_variations (face,
273 table_tags[table_index],
274 coords,
275 num_coords,
276 &variations_index);
277
278 unsigned int stage_index = 0;
279 unsigned int last_num_lookups = 0;
280 for (unsigned stage = 0; stage < current_stage[table_index]; stage++)
281 {
282 if (required_feature_index[table_index] != HB_OT_LAYOUT_NO_FEATURE_INDEX &&
283 required_feature_stage[table_index] == stage)
284 add_lookups (m, face, table_index,
285 required_feature_index[table_index],
286 variations_index,
287 1 /* mask */,
288 true /* auto_zwj */);
289
290 for (unsigned i = 0; i < m.features.len; i++)
291 if (m.features[i].stage[table_index] == stage)
292 add_lookups (m, face, table_index,
293 m.features[i].index[table_index],
294 variations_index,
295 m.features[i].mask,
296 m.features[i].auto_zwj);
297
298 /* Sort lookups and merge duplicates */
299 if (last_num_lookups < m.lookups[table_index].len)
300 {
301 m.lookups[table_index].qsort (last_num_lookups, m.lookups[table_index].len);
302
303 unsigned int j = last_num_lookups;
304 for (unsigned int i = j + 1; i < m.lookups[table_index].len; i++)
305 if (m.lookups[table_index][i].index != m.lookups[table_index][j].index)
306 m.lookups[table_index][++j] = m.lookups[table_index][i];
307 else
308 {
309 m.lookups[table_index][j].mask |= m.lookups[table_index][i].mask;
310 m.lookups[table_index][j].auto_zwj &= m.lookups[table_index][i].auto_zwj;
311 }
312 m.lookups[table_index].shrink (j + 1);
313 }
314
315 last_num_lookups = m.lookups[table_index].len;
316
317 if (stage_index < stages[table_index].len && stages[table_index][stage_index].index == stage) {
318 hb_ot_map_t::stage_map_t *stage_map = m.stages[table_index].push ();
319 if (likely (stage_map)) {
320 stage_map->last_lookup = last_num_lookups;
321 stage_map->pause_func = stages[table_index][stage_index].pause_func;
322 }
323
324 stage_index++;
325 }
326 }
327 }
328 }
|
68 {
69 feature_info_t *info = feature_infos.push();
70 if (unlikely (!info)) return;
71 if (unlikely (!tag)) return;
72 info->tag = tag;
73 info->seq = feature_infos.len;
74 info->max_value = value;
75 info->flags = flags;
76 info->default_value = (flags & F_GLOBAL) ? value : 0;
77 info->stage[0] = current_stage[0];
78 info->stage[1] = current_stage[1];
79 }
80
81 void
82 hb_ot_map_builder_t::add_lookups (hb_ot_map_t &m,
83 hb_face_t *face,
84 unsigned int table_index,
85 unsigned int feature_index,
86 unsigned int variations_index,
87 hb_mask_t mask,
88 bool auto_zwnj,
89 bool auto_zwj)
90 {
91 unsigned int lookup_indices[32];
92 unsigned int offset, len;
93 unsigned int table_lookup_count;
94
95 table_lookup_count = hb_ot_layout_table_get_lookup_count (face, table_tags[table_index]);
96
97 offset = 0;
98 do {
99 len = ARRAY_LENGTH (lookup_indices);
100 hb_ot_layout_feature_with_variations_get_lookups (face,
101 table_tags[table_index],
102 feature_index,
103 variations_index,
104 offset, &len,
105 lookup_indices);
106
107 for (unsigned int i = 0; i < len; i++)
108 {
109 if (lookup_indices[i] >= table_lookup_count)
110 continue;
111 hb_ot_map_t::lookup_map_t *lookup = m.lookups[table_index].push ();
112 if (unlikely (!lookup))
113 return;
114 lookup->mask = mask;
115 lookup->index = lookup_indices[i];
116 lookup->auto_zwnj = auto_zwnj;
117 lookup->auto_zwj = auto_zwj;
118 }
119
120 offset += len;
121 } while (len == ARRAY_LENGTH (lookup_indices));
122 }
123
124
125 void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func)
126 {
127 stage_info_t *s = stages[table_index].push ();
128 if (likely (s)) {
129 s->index = current_stage[table_index];
130 s->pause_func = pause_func;
131 }
132
133 current_stage[table_index]++;
134 }
135
136 void
137 hb_ot_map_builder_t::compile (hb_ot_map_t &m,
138 const int *coords,
139 unsigned int num_coords)
140 {
141 static_assert ((!(HB_GLYPH_FLAG_DEFINED & (HB_GLYPH_FLAG_DEFINED + 1))), "");
142 unsigned int global_bit_mask = HB_GLYPH_FLAG_DEFINED + 1;
143 unsigned int global_bit_shift = _hb_popcount32 (HB_GLYPH_FLAG_DEFINED);
144
145 m.global_mask = global_bit_mask;
146
147 unsigned int required_feature_index[2];
148 hb_tag_t required_feature_tag[2];
149 /* We default to applying required feature in stage 0. If the required
150 * feature has a tag that is known to the shaper, we apply required feature
151 * in the stage for that tag.
152 */
153 unsigned int required_feature_stage[2] = {0, 0};
154
155 for (unsigned int table_index = 0; table_index < 2; table_index++)
156 {
157 m.chosen_script[table_index] = chosen_script[table_index];
158 m.found_script[table_index] = found_script[table_index];
159
160 hb_ot_layout_language_get_required_feature (face,
161 table_tags[table_index],
162 script_index[table_index],
163 language_index[table_index],
164 &required_feature_index[table_index],
165 &required_feature_tag[table_index]);
177 feature_infos[++j] = feature_infos[i];
178 else {
179 if (feature_infos[i].flags & F_GLOBAL) {
180 feature_infos[j].flags |= F_GLOBAL;
181 feature_infos[j].max_value = feature_infos[i].max_value;
182 feature_infos[j].default_value = feature_infos[i].default_value;
183 } else {
184 feature_infos[j].flags &= ~F_GLOBAL;
185 feature_infos[j].max_value = MAX (feature_infos[j].max_value, feature_infos[i].max_value);
186 /* Inherit default_value from j */
187 }
188 feature_infos[j].flags |= (feature_infos[i].flags & F_HAS_FALLBACK);
189 feature_infos[j].stage[0] = MIN (feature_infos[j].stage[0], feature_infos[i].stage[0]);
190 feature_infos[j].stage[1] = MIN (feature_infos[j].stage[1], feature_infos[i].stage[1]);
191 }
192 feature_infos.shrink (j + 1);
193 }
194
195
196 /* Allocate bits now */
197 unsigned int next_bit = global_bit_shift + 1;
198
199 for (unsigned int i = 0; i < feature_infos.len; i++)
200 {
201 const feature_info_t *info = &feature_infos[i];
202
203 unsigned int bits_needed;
204
205 if ((info->flags & F_GLOBAL) && info->max_value == 1)
206 /* Uses the global bit */
207 bits_needed = 0;
208 else
209 /* Limit to 8 bits per feature. */
210 bits_needed = MIN(8u, _hb_bit_storage (info->max_value));
211
212 if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t))
213 continue; /* Feature disabled, or not enough bits. */
214
215
216 hb_bool_t found = false;
217 unsigned int feature_index[2];
218 for (unsigned int table_index = 0; table_index < 2; table_index++)
233 {
234 found |= hb_ot_layout_table_find_feature (face,
235 table_tags[table_index],
236 info->tag,
237 &feature_index[table_index]);
238 }
239 }
240 if (!found && !(info->flags & F_HAS_FALLBACK))
241 continue;
242
243
244 hb_ot_map_t::feature_map_t *map = m.features.push ();
245 if (unlikely (!map))
246 break;
247
248 map->tag = info->tag;
249 map->index[0] = feature_index[0];
250 map->index[1] = feature_index[1];
251 map->stage[0] = info->stage[0];
252 map->stage[1] = info->stage[1];
253 map->auto_zwnj = !(info->flags & F_MANUAL_ZWNJ);
254 map->auto_zwj = !(info->flags & F_MANUAL_ZWJ);
255 if ((info->flags & F_GLOBAL) && info->max_value == 1) {
256 /* Uses the global bit */
257 map->shift = global_bit_shift;
258 map->mask = global_bit_mask;
259 } else {
260 map->shift = next_bit;
261 map->mask = (1u << (next_bit + bits_needed)) - (1u << next_bit);
262 next_bit += bits_needed;
263 m.global_mask |= (info->default_value << map->shift) & map->mask;
264 }
265 map->_1_mask = (1u << map->shift) & map->mask;
266 map->needs_fallback = !found;
267
268 }
269 feature_infos.shrink (0); /* Done with these */
270
271
272 add_gsub_pause (nullptr);
273 add_gpos_pause (nullptr);
274
275 for (unsigned int table_index = 0; table_index < 2; table_index++)
276 {
277 /* Collect lookup indices for features */
278
279 unsigned int variations_index;
280 hb_ot_layout_table_find_feature_variations (face,
281 table_tags[table_index],
282 coords,
283 num_coords,
284 &variations_index);
285
286 unsigned int stage_index = 0;
287 unsigned int last_num_lookups = 0;
288 for (unsigned stage = 0; stage < current_stage[table_index]; stage++)
289 {
290 if (required_feature_index[table_index] != HB_OT_LAYOUT_NO_FEATURE_INDEX &&
291 required_feature_stage[table_index] == stage)
292 add_lookups (m, face, table_index,
293 required_feature_index[table_index],
294 variations_index,
295 global_bit_mask);
296
297 for (unsigned i = 0; i < m.features.len; i++)
298 if (m.features[i].stage[table_index] == stage)
299 add_lookups (m, face, table_index,
300 m.features[i].index[table_index],
301 variations_index,
302 m.features[i].mask,
303 m.features[i].auto_zwnj,
304 m.features[i].auto_zwj);
305
306 /* Sort lookups and merge duplicates */
307 if (last_num_lookups < m.lookups[table_index].len)
308 {
309 m.lookups[table_index].qsort (last_num_lookups, m.lookups[table_index].len);
310
311 unsigned int j = last_num_lookups;
312 for (unsigned int i = j + 1; i < m.lookups[table_index].len; i++)
313 if (m.lookups[table_index][i].index != m.lookups[table_index][j].index)
314 m.lookups[table_index][++j] = m.lookups[table_index][i];
315 else
316 {
317 m.lookups[table_index][j].mask |= m.lookups[table_index][i].mask;
318 m.lookups[table_index][j].auto_zwnj &= m.lookups[table_index][i].auto_zwnj;
319 m.lookups[table_index][j].auto_zwj &= m.lookups[table_index][i].auto_zwj;
320 }
321 m.lookups[table_index].shrink (j + 1);
322 }
323
324 last_num_lookups = m.lookups[table_index].len;
325
326 if (stage_index < stages[table_index].len && stages[table_index][stage_index].index == stage) {
327 hb_ot_map_t::stage_map_t *stage_map = m.stages[table_index].push ();
328 if (likely (stage_map)) {
329 stage_map->last_lookup = last_num_lookups;
330 stage_map->pause_func = stages[table_index][stage_index].pause_func;
331 }
332
333 stage_index++;
334 }
335 }
336 }
337 }
|