blob: f085c78ff8f000ac81cd0abc2195348b7bc5f74e [file] [log] [blame]
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -04001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2009,2010 Red Hat, Inc.
Behdad Esfahbod06a44e82013-04-21 15:13:08 -04003 * Copyright © 2010,2011,2013 Google, Inc.
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -04004 *
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
Behdad Esfahbodbb4bbe62019-06-26 13:29:58 -070029#include "hb.hh"
30
31#ifndef HB_NO_OT_SHAPE
32
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070033#include "hb-ot-map.hh"
Behdad Esfahbodcc842872018-11-12 18:48:10 -050034#include "hb-ot-shape.hh"
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070035#include "hb-ot-layout.hh"
Behdad Esfahbod2265be02013-05-02 14:25:09 -040036
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -040037
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -070038void hb_ot_map_t::collect_lookups (unsigned int table_index, hb_set_t *lookups_out) const
Behdad Esfahbodd2ba0162010-10-12 15:35:45 -040039{
Behdad Esfahbod474a1202018-12-21 18:46:51 -050040 for (unsigned int i = 0; i < lookups[table_index].length; i++)
Ebrahim Byagowic7621cf2019-10-08 13:24:26 +033041 lookups_out->add (lookups[table_index][i].index);
Behdad Esfahbodd2ba0162010-10-12 15:35:45 -040042}
43
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -070044
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -080045hb_ot_map_builder_t::hb_ot_map_builder_t (hb_face_t *face_,
46 const hb_segment_properties_t *props_)
47{
48 memset (this, 0, sizeof (*this));
49
Behdad Esfahbodf9abbf82018-06-02 15:30:59 -070050 feature_infos.init ();
51 for (unsigned int table_index = 0; table_index < 2; table_index++)
52 stages[table_index].init ();
53
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -080054 face = face_;
55 props = *props_;
56
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -080057 /* Fetch script/language indices for GSUB/GPOS. We need these later to skip
58 * features not available in either table and not waste precious bits for them. */
59
David Corbett91067712017-12-08 11:21:14 -050060 unsigned int script_count = HB_OT_MAX_TAGS_PER_SCRIPT;
61 unsigned int language_count = HB_OT_MAX_TAGS_PER_LANGUAGE;
62 hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT];
63 hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE];
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -080064
Behdad Esfahbod10da9fd2021-08-23 23:32:02 -060065 hb_ot_tags_from_script_and_language (props.script,
66 props.language,
67 &script_count,
68 script_tags,
69 &language_count,
70 language_tags);
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -080071
Behdad Esfahbod10da9fd2021-08-23 23:32:02 -060072 for (unsigned int table_index = 0; table_index < 2; table_index++)
73 {
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -080074 hb_tag_t table_tag = table_tags[table_index];
Behdad Esfahbod10da9fd2021-08-23 23:32:02 -060075 found_script[table_index] = (bool) hb_ot_layout_table_select_script (face,
76 table_tag,
77 script_count,
78 script_tags,
79 &script_index[table_index],
80 &chosen_script[table_index]);
81 hb_ot_layout_script_select_language (face,
82 table_tag,
83 script_index[table_index],
84 language_count,
85 language_tags,
86 &language_index[table_index]);
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -080087 }
88}
Behdad Esfahbodd2ba0162010-10-12 15:35:45 -040089
Ebrahim Byagowie4120082018-12-17 21:31:01 +033090hb_ot_map_builder_t::~hb_ot_map_builder_t ()
Behdad Esfahbodf9abbf82018-06-02 15:30:59 -070091{
92 feature_infos.fini ();
93 for (unsigned int table_index = 0; table_index < 2; table_index++)
94 stages[table_index].fini ();
95}
96
Behdad Esfahbodf048ead2018-09-24 18:01:53 -040097void hb_ot_map_builder_t::add_feature (hb_tag_t tag,
98 hb_ot_map_feature_flags_t flags,
99 unsigned int value)
Behdad Esfahbod51881a62011-05-27 18:15:56 -0400100{
Jonathan Kewda132932014-04-27 14:05:24 +0100101 if (unlikely (!tag)) return;
Behdad Esfahbod8be0e5f2018-10-23 13:39:50 -0700102 feature_info_t *info = feature_infos.push();
Behdad Esfahbod51881a62011-05-27 18:15:56 -0400103 info->tag = tag;
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500104 info->seq = feature_infos.length;
Behdad Esfahbod51881a62011-05-27 18:15:56 -0400105 info->max_value = value;
Behdad Esfahbodec544862013-02-14 11:25:10 -0500106 info->flags = flags;
107 info->default_value = (flags & F_GLOBAL) ? value : 0;
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400108 info->stage[0] = current_stage[0];
109 info->stage[1] = current_stage[1];
110}
111
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700112void
113hb_ot_map_builder_t::add_lookups (hb_ot_map_t &m,
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700114 unsigned int table_index,
115 unsigned int feature_index,
Behdad Esfahbod72ada4f2016-09-10 03:57:24 -0700116 unsigned int variations_index,
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700117 hb_mask_t mask,
Behdad Esfahbodcdf1fd02017-07-14 12:43:34 +0100118 bool auto_zwnj,
David Corbettc2a75e02018-01-25 14:22:03 -0500119 bool auto_zwj,
Behdad Esfahbod044d7a02022-03-28 12:38:56 -0600120 bool random,
121 bool per_syllable)
Behdad Esfahbodd2984a22012-04-23 17:21:14 -0400122{
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700123 unsigned int lookup_indices[32];
124 unsigned int offset, len;
125 unsigned int table_lookup_count;
126
127 table_lookup_count = hb_ot_layout_table_get_lookup_count (face, table_tags[table_index]);
128
129 offset = 0;
130 do {
131 len = ARRAY_LENGTH (lookup_indices);
Behdad Esfahbod72ada4f2016-09-10 03:57:24 -0700132 hb_ot_layout_feature_with_variations_get_lookups (face,
133 table_tags[table_index],
134 feature_index,
135 variations_index,
136 offset, &len,
137 lookup_indices);
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700138
139 for (unsigned int i = 0; i < len; i++)
140 {
141 if (lookup_indices[i] >= table_lookup_count)
142 continue;
143 hb_ot_map_t::lookup_map_t *lookup = m.lookups[table_index].push ();
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700144 lookup->mask = mask;
145 lookup->index = lookup_indices[i];
Behdad Esfahbodcdf1fd02017-07-14 12:43:34 +0100146 lookup->auto_zwnj = auto_zwnj;
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700147 lookup->auto_zwj = auto_zwj;
David Corbettc2a75e02018-01-25 14:22:03 -0500148 lookup->random = random;
Behdad Esfahbod044d7a02022-03-28 12:38:56 -0600149 lookup->per_syllable = per_syllable;
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700150 }
151
152 offset += len;
153 } while (len == ARRAY_LENGTH (lookup_indices));
Behdad Esfahbodd2984a22012-04-23 17:21:14 -0400154}
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400155
Behdad Esfahbod7ceadbe2016-09-10 02:44:20 -0700156
Behdad Esfahbod3e38c0f2012-08-02 09:44:18 -0400157void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func)
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400158{
Behdad Esfahbod8ac3c9c2013-04-21 15:19:38 -0400159 stage_info_t *s = stages[table_index].push ();
Behdad Esfahbodf7515762018-06-01 17:48:37 -0700160 s->index = current_stage[table_index];
161 s->pause_func = pause_func;
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400162
163 current_stage[table_index]++;
Behdad Esfahbod51881a62011-05-27 18:15:56 -0400164}
165
Behdad Esfahbodd2ba0162010-10-12 15:35:45 -0400166void
Behdad Esfahbodcc842872018-11-12 18:48:10 -0500167hb_ot_map_builder_t::compile (hb_ot_map_t &m,
168 const hb_ot_shape_plan_key_t &key)
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400169{
Behdad Esfahboda150baf2021-08-04 11:53:27 -0600170 unsigned int global_bit_shift = 8 * sizeof (hb_mask_t) - 1;
171 unsigned int global_bit_mask = 1u << global_bit_shift;
Behdad Esfahbod5287ccc2017-08-10 14:25:53 -0700172
173 m.global_mask = global_bit_mask;
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -0800174
Jonathan Kewda132932014-04-27 14:05:24 +0100175 unsigned int required_feature_index[2];
176 hb_tag_t required_feature_tag[2];
177 /* We default to applying required feature in stage 0. If the required
178 * feature has a tag that is known to the shaper, we apply required feature
179 * in the stage for that tag.
180 */
181 unsigned int required_feature_stage[2] = {0, 0};
182
183 for (unsigned int table_index = 0; table_index < 2; table_index++)
184 {
Behdad Esfahbod6fddf2d2012-11-12 17:57:24 -0800185 m.chosen_script[table_index] = chosen_script[table_index];
Behdad Esfahbod851784f2012-11-14 16:24:05 -0800186 m.found_script[table_index] = found_script[table_index];
Jonathan Kewda132932014-04-27 14:05:24 +0100187
188 hb_ot_layout_language_get_required_feature (face,
189 table_tags[table_index],
190 script_index[table_index],
191 language_index[table_index],
192 &required_feature_index[table_index],
193 &required_feature_tag[table_index]);
Behdad Esfahbod851784f2012-11-14 16:24:05 -0800194 }
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400195
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400196 /* Sort features and merge duplicates */
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500197 if (feature_infos.length)
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400198 {
Behdad Esfahbodfb8cc862014-06-19 15:30:18 -0400199 feature_infos.qsort ();
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400200 unsigned int j = 0;
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500201 for (unsigned int i = 1; i < feature_infos.length; i++)
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400202 if (feature_infos[i].tag != feature_infos[j].tag)
203 feature_infos[++j] = feature_infos[i];
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400204 else {
Behdad Esfahbodec544862013-02-14 11:25:10 -0500205 if (feature_infos[i].flags & F_GLOBAL) {
206 feature_infos[j].flags |= F_GLOBAL;
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400207 feature_infos[j].max_value = feature_infos[i].max_value;
208 feature_infos[j].default_value = feature_infos[i].default_value;
209 } else {
Ebrahim Byagowibbe87802019-09-18 22:22:01 +0430210 if (feature_infos[j].flags & F_GLOBAL)
211 feature_infos[j].flags ^= F_GLOBAL;
Behdad Esfahbod41248cc2019-05-07 20:54:31 -0700212 feature_infos[j].max_value = hb_max (feature_infos[j].max_value, feature_infos[i].max_value);
Behdad Esfahbod398238a2013-02-15 07:40:10 -0500213 /* Inherit default_value from j */
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400214 }
Behdad Esfahbodec544862013-02-14 11:25:10 -0500215 feature_infos[j].flags |= (feature_infos[i].flags & F_HAS_FALLBACK);
Behdad Esfahbod41248cc2019-05-07 20:54:31 -0700216 feature_infos[j].stage[0] = hb_min (feature_infos[j].stage[0], feature_infos[i].stage[0]);
217 feature_infos[j].stage[1] = hb_min (feature_infos[j].stage[1], feature_infos[i].stage[1]);
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400218 }
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400219 feature_infos.shrink (j + 1);
220 }
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400221
222
223 /* Allocate bits now */
Behdad Esfahboda150baf2021-08-04 11:53:27 -0600224 static_assert ((!(HB_GLYPH_FLAG_DEFINED & (HB_GLYPH_FLAG_DEFINED + 1))), "");
225 unsigned int next_bit = hb_popcount (HB_GLYPH_FLAG_DEFINED) + 1;
Behdad Esfahbod40bd7e92016-05-02 14:47:45 +0200226
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500227 for (unsigned int i = 0; i < feature_infos.length; i++)
Jonathan Kewda132932014-04-27 14:05:24 +0100228 {
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400229 const feature_info_t *info = &feature_infos[i];
230
231 unsigned int bits_needed;
232
Behdad Esfahbodec544862013-02-14 11:25:10 -0500233 if ((info->flags & F_GLOBAL) && info->max_value == 1)
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400234 /* Uses the global bit */
235 bits_needed = 0;
236 else
Behdad Esfahbod71c9f842018-09-10 22:37:19 +0200237 /* Limit bits per feature. */
Behdad Esfahbod41248cc2019-05-07 20:54:31 -0700238 bits_needed = hb_min (HB_OT_MAP_MAX_BITS, hb_bit_storage (info->max_value));
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400239
Behdad Esfahboda150baf2021-08-04 11:53:27 -0600240 if (!info->max_value || next_bit + bits_needed >= global_bit_shift)
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400241 continue; /* Feature disabled, or not enough bits. */
242
243
Behdad Esfahbod518e6e02019-04-18 12:21:25 -0400244 bool found = false;
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400245 unsigned int feature_index[2];
246 for (unsigned int table_index = 0; table_index < 2; table_index++)
Jonathan Kewda132932014-04-27 14:05:24 +0100247 {
248 if (required_feature_tag[table_index] == info->tag)
Jonathan Kewda132932014-04-27 14:05:24 +0100249 required_feature_stage[table_index] = info->stage[table_index];
Behdad Esfahbod731a4302016-03-02 13:32:42 -0800250
Behdad Esfahbod42f4bd62019-04-18 19:04:59 -0400251 found |= (bool) hb_ot_layout_language_find_feature (face,
252 table_tags[table_index],
253 script_index[table_index],
254 language_index[table_index],
255 info->tag,
256 &feature_index[table_index]);
Jonathan Kewda132932014-04-27 14:05:24 +0100257 }
Behdad Esfahbod0f98fe82015-07-23 11:52:11 +0100258 if (!found && (info->flags & F_GLOBAL_SEARCH))
259 {
260 for (unsigned int table_index = 0; table_index < 2; table_index++)
261 {
Behdad Esfahbod42f4bd62019-04-18 19:04:59 -0400262 found |= (bool) hb_ot_layout_table_find_feature (face,
263 table_tags[table_index],
264 info->tag,
265 &feature_index[table_index]);
Behdad Esfahbod0f98fe82015-07-23 11:52:11 +0100266 }
267 }
Behdad Esfahbodec544862013-02-14 11:25:10 -0500268 if (!found && !(info->flags & F_HAS_FALLBACK))
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400269 continue;
270
271
Behdad Esfahbod90645fb2011-05-27 18:13:31 -0400272 hb_ot_map_t::feature_map_t *map = m.features.push ();
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400273
274 map->tag = info->tag;
275 map->index[0] = feature_index[0];
276 map->index[1] = feature_index[1];
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400277 map->stage[0] = info->stage[0];
278 map->stage[1] = info->stage[1];
Behdad Esfahbodcdf1fd02017-07-14 12:43:34 +0100279 map->auto_zwnj = !(info->flags & F_MANUAL_ZWNJ);
Behdad Esfahboda8cf7b42013-03-19 05:53:26 -0400280 map->auto_zwj = !(info->flags & F_MANUAL_ZWJ);
David Corbettf05df642018-01-26 21:36:15 -0500281 map->random = !!(info->flags & F_RANDOM);
Behdad Esfahbod044d7a02022-03-28 12:38:56 -0600282 map->per_syllable = !!(info->flags & F_PER_SYLLABLE);
Behdad Esfahbodec544862013-02-14 11:25:10 -0500283 if ((info->flags & F_GLOBAL) && info->max_value == 1) {
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400284 /* Uses the global bit */
Behdad Esfahbod5287ccc2017-08-10 14:25:53 -0700285 map->shift = global_bit_shift;
286 map->mask = global_bit_mask;
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400287 } else {
288 map->shift = next_bit;
Behdad Esfahbod33317312016-08-08 17:24:04 -0700289 map->mask = (1u << (next_bit + bits_needed)) - (1u << next_bit);
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400290 next_bit += bits_needed;
Behdad Esfahbod398238a2013-02-15 07:40:10 -0500291 m.global_mask |= (info->default_value << map->shift) & map->mask;
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400292 }
Behdad Esfahbod33317312016-08-08 17:24:04 -0700293 map->_1_mask = (1u << map->shift) & map->mask;
Behdad Esfahbodfabd3112012-09-05 22:19:28 -0400294 map->needs_fallback = !found;
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400295 }
Behdad Esfahbod68435692011-05-05 14:12:37 -0400296 feature_infos.shrink (0); /* Done with these */
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400297
298
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200299 add_gsub_pause (nullptr);
300 add_gpos_pause (nullptr);
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400301
Jonathan Kewda132932014-04-27 14:05:24 +0100302 for (unsigned int table_index = 0; table_index < 2; table_index++)
303 {
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400304 /* Collect lookup indices for features */
305
Behdad Esfahbod8ac3c9c2013-04-21 15:19:38 -0400306 unsigned int stage_index = 0;
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400307 unsigned int last_num_lookups = 0;
308 for (unsigned stage = 0; stage < current_stage[table_index]; stage++)
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400309 {
Jonathan Kewda132932014-04-27 14:05:24 +0100310 if (required_feature_index[table_index] != HB_OT_LAYOUT_NO_FEATURE_INDEX &&
311 required_feature_stage[table_index] == stage)
Behdad Esfahbod12757b62018-01-26 18:14:05 -0800312 add_lookups (m, table_index,
Behdad Esfahbodbde5e392016-09-10 02:43:20 -0700313 required_feature_index[table_index],
Behdad Esfahbodcc842872018-11-12 18:48:10 -0500314 key.variations_index[table_index],
Behdad Esfahbod5287ccc2017-08-10 14:25:53 -0700315 global_bit_mask);
Jonathan Kewda132932014-04-27 14:05:24 +0100316
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500317 for (unsigned i = 0; i < m.features.length; i++)
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430318 if (m.features[i].stage[table_index] == stage)
Behdad Esfahbod12757b62018-01-26 18:14:05 -0800319 add_lookups (m, table_index,
Behdad Esfahbodbde5e392016-09-10 02:43:20 -0700320 m.features[i].index[table_index],
Behdad Esfahbodcc842872018-11-12 18:48:10 -0500321 key.variations_index[table_index],
Behdad Esfahbodbde5e392016-09-10 02:43:20 -0700322 m.features[i].mask,
Behdad Esfahbodcdf1fd02017-07-14 12:43:34 +0100323 m.features[i].auto_zwnj,
David Corbettc2a75e02018-01-25 14:22:03 -0500324 m.features[i].auto_zwj,
Behdad Esfahbod044d7a02022-03-28 12:38:56 -0600325 m.features[i].random,
326 m.features[i].per_syllable);
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400327
328 /* Sort lookups and merge duplicates */
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500329 if (last_num_lookups < m.lookups[table_index].length)
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400330 {
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500331 m.lookups[table_index].qsort (last_num_lookups, m.lookups[table_index].length);
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400332
333 unsigned int j = last_num_lookups;
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500334 for (unsigned int i = j + 1; i < m.lookups[table_index].length; i++)
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400335 if (m.lookups[table_index][i].index != m.lookups[table_index][j].index)
336 m.lookups[table_index][++j] = m.lookups[table_index][i];
337 else
Behdad Esfahbodcfc507c2013-02-14 10:40:12 -0500338 {
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400339 m.lookups[table_index][j].mask |= m.lookups[table_index][i].mask;
Behdad Esfahbodcdf1fd02017-07-14 12:43:34 +0100340 m.lookups[table_index][j].auto_zwnj &= m.lookups[table_index][i].auto_zwnj;
Behdad Esfahboda8cf7b42013-03-19 05:53:26 -0400341 m.lookups[table_index][j].auto_zwj &= m.lookups[table_index][i].auto_zwj;
Behdad Esfahbodcfc507c2013-02-14 10:40:12 -0500342 }
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400343 m.lookups[table_index].shrink (j + 1);
344 }
345
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500346 last_num_lookups = m.lookups[table_index].length;
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400347
Behdad Esfahbod474a1202018-12-21 18:46:51 -0500348 if (stage_index < stages[table_index].length && stages[table_index][stage_index].index == stage) {
Behdad Esfahbod893f57b2013-04-21 15:21:49 -0400349 hb_ot_map_t::stage_map_t *stage_map = m.stages[table_index].push ();
Behdad Esfahbodf7515762018-06-01 17:48:37 -0700350 stage_map->last_lookup = last_num_lookups;
351 stage_map->pause_func = stages[table_index][stage_index].pause_func;
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400352
Behdad Esfahbod8ac3c9c2013-04-21 15:19:38 -0400353 stage_index++;
Behdad Esfahbodb70c96d2011-07-07 21:07:41 -0400354 }
Behdad Esfahbod5a2b0b32010-10-08 20:14:57 -0400355 }
356 }
357}
Behdad Esfahbodbb4bbe62019-06-26 13:29:58 -0700358
359
360#endif