Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2009,2010 Red Hat, Inc. |
Behdad Esfahbod | 06a44e8 | 2013-04-21 15:13:08 -0400 | [diff] [blame] | 3 | * Copyright © 2010,2011,2013 Google, Inc. |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 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 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 29 | #include "hb-ot-map.hh" |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 30 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 31 | #include "hb-ot-layout.hh" |
Behdad Esfahbod | 2265be0 | 2013-05-02 14:25:09 -0400 | [diff] [blame] | 32 | |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 33 | |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 34 | void hb_ot_map_t::collect_lookups (unsigned int table_index, hb_set_t *lookups_out) const |
Behdad Esfahbod | d2ba016 | 2010-10-12 15:35:45 -0400 | [diff] [blame] | 35 | { |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 36 | for (unsigned int i = 0; i < lookups[table_index].len; i++) |
| 37 | hb_set_add (lookups_out, lookups[table_index][i].index); |
Behdad Esfahbod | d2ba016 | 2010-10-12 15:35:45 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 40 | |
Behdad Esfahbod | 6fddf2d | 2012-11-12 17:57:24 -0800 | [diff] [blame] | 41 | hb_ot_map_builder_t::hb_ot_map_builder_t (hb_face_t *face_, |
| 42 | const hb_segment_properties_t *props_) |
| 43 | { |
| 44 | memset (this, 0, sizeof (*this)); |
| 45 | |
Behdad Esfahbod | f9abbf8 | 2018-06-02 15:30:59 -0700 | [diff] [blame] | 46 | feature_infos.init (); |
| 47 | for (unsigned int table_index = 0; table_index < 2; table_index++) |
| 48 | stages[table_index].init (); |
| 49 | |
Behdad Esfahbod | 6fddf2d | 2012-11-12 17:57:24 -0800 | [diff] [blame] | 50 | face = face_; |
| 51 | props = *props_; |
| 52 | |
| 53 | |
| 54 | /* Fetch script/language indices for GSUB/GPOS. We need these later to skip |
| 55 | * features not available in either table and not waste precious bits for them. */ |
| 56 | |
| 57 | hb_tag_t script_tags[3] = {HB_TAG_NONE, HB_TAG_NONE, HB_TAG_NONE}; |
| 58 | hb_tag_t language_tag; |
| 59 | |
| 60 | hb_ot_tags_from_script (props.script, &script_tags[0], &script_tags[1]); |
| 61 | language_tag = hb_ot_tag_from_language (props.language); |
| 62 | |
| 63 | for (unsigned int table_index = 0; table_index < 2; table_index++) { |
| 64 | hb_tag_t table_tag = table_tags[table_index]; |
Behdad Esfahbod | ea512f7 | 2015-11-26 19:22:22 -0500 | [diff] [blame] | 65 | found_script[table_index] = (bool) hb_ot_layout_table_choose_script (face, table_tag, script_tags, &script_index[table_index], &chosen_script[table_index]); |
Behdad Esfahbod | 6fddf2d | 2012-11-12 17:57:24 -0800 | [diff] [blame] | 66 | hb_ot_layout_script_find_language (face, table_tag, script_index[table_index], language_tag, &language_index[table_index]); |
| 67 | } |
| 68 | } |
Behdad Esfahbod | d2ba016 | 2010-10-12 15:35:45 -0400 | [diff] [blame] | 69 | |
Behdad Esfahbod | f9abbf8 | 2018-06-02 15:30:59 -0700 | [diff] [blame] | 70 | hb_ot_map_builder_t::~hb_ot_map_builder_t (void) |
| 71 | { |
| 72 | feature_infos.fini (); |
| 73 | for (unsigned int table_index = 0; table_index < 2; table_index++) |
| 74 | stages[table_index].fini (); |
| 75 | } |
| 76 | |
Behdad Esfahbod | f048ead | 2018-09-24 18:01:53 -0400 | [diff] [blame] | 77 | void hb_ot_map_builder_t::add_feature (hb_tag_t tag, |
| 78 | hb_ot_map_feature_flags_t flags, |
| 79 | unsigned int value) |
Behdad Esfahbod | 51881a6 | 2011-05-27 18:15:56 -0400 | [diff] [blame] | 80 | { |
| 81 | feature_info_t *info = feature_infos.push(); |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 82 | if (unlikely (!tag)) return; |
Behdad Esfahbod | 51881a6 | 2011-05-27 18:15:56 -0400 | [diff] [blame] | 83 | info->tag = tag; |
| 84 | info->seq = feature_infos.len; |
| 85 | info->max_value = value; |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 86 | info->flags = flags; |
| 87 | info->default_value = (flags & F_GLOBAL) ? value : 0; |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 88 | info->stage[0] = current_stage[0]; |
| 89 | info->stage[1] = current_stage[1]; |
| 90 | } |
| 91 | |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 92 | void |
| 93 | hb_ot_map_builder_t::add_lookups (hb_ot_map_t &m, |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 94 | unsigned int table_index, |
| 95 | unsigned int feature_index, |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 96 | unsigned int variations_index, |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 97 | hb_mask_t mask, |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 98 | bool auto_zwnj, |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 99 | bool auto_zwj, |
| 100 | bool random) |
Behdad Esfahbod | d2984a2 | 2012-04-23 17:21:14 -0400 | [diff] [blame] | 101 | { |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 102 | unsigned int lookup_indices[32]; |
| 103 | unsigned int offset, len; |
| 104 | unsigned int table_lookup_count; |
| 105 | |
| 106 | table_lookup_count = hb_ot_layout_table_get_lookup_count (face, table_tags[table_index]); |
| 107 | |
| 108 | offset = 0; |
| 109 | do { |
| 110 | len = ARRAY_LENGTH (lookup_indices); |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 111 | hb_ot_layout_feature_with_variations_get_lookups (face, |
| 112 | table_tags[table_index], |
| 113 | feature_index, |
| 114 | variations_index, |
| 115 | offset, &len, |
| 116 | lookup_indices); |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 117 | |
| 118 | for (unsigned int i = 0; i < len; i++) |
| 119 | { |
| 120 | if (lookup_indices[i] >= table_lookup_count) |
| 121 | continue; |
| 122 | hb_ot_map_t::lookup_map_t *lookup = m.lookups[table_index].push (); |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 123 | lookup->mask = mask; |
| 124 | lookup->index = lookup_indices[i]; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 125 | lookup->auto_zwnj = auto_zwnj; |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 126 | lookup->auto_zwj = auto_zwj; |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 127 | lookup->random = random; |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | offset += len; |
| 131 | } while (len == ARRAY_LENGTH (lookup_indices)); |
Behdad Esfahbod | d2984a2 | 2012-04-23 17:21:14 -0400 | [diff] [blame] | 132 | } |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 133 | |
Behdad Esfahbod | 7ceadbe | 2016-09-10 02:44:20 -0700 | [diff] [blame] | 134 | |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 135 | void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func) |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 136 | { |
Behdad Esfahbod | 8ac3c9c | 2013-04-21 15:19:38 -0400 | [diff] [blame] | 137 | stage_info_t *s = stages[table_index].push (); |
Behdad Esfahbod | f751576 | 2018-06-01 17:48:37 -0700 | [diff] [blame] | 138 | s->index = current_stage[table_index]; |
| 139 | s->pause_func = pause_func; |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 140 | |
| 141 | current_stage[table_index]++; |
Behdad Esfahbod | 51881a6 | 2011-05-27 18:15:56 -0400 | [diff] [blame] | 142 | } |
| 143 | |
Behdad Esfahbod | d2ba016 | 2010-10-12 15:35:45 -0400 | [diff] [blame] | 144 | void |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 145 | hb_ot_map_builder_t::compile (hb_ot_map_t &m, |
| 146 | const int *coords, |
| 147 | unsigned int num_coords) |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 148 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 149 | static_assert ((!(HB_GLYPH_FLAG_DEFINED & (HB_GLYPH_FLAG_DEFINED + 1))), ""); |
Behdad Esfahbod | 5287ccc | 2017-08-10 14:25:53 -0700 | [diff] [blame] | 150 | unsigned int global_bit_mask = HB_GLYPH_FLAG_DEFINED + 1; |
Behdad Esfahbod | bddeb2b | 2018-07-10 14:12:37 +0200 | [diff] [blame] | 151 | unsigned int global_bit_shift = hb_popcount (HB_GLYPH_FLAG_DEFINED); |
Behdad Esfahbod | 5287ccc | 2017-08-10 14:25:53 -0700 | [diff] [blame] | 152 | |
| 153 | m.global_mask = global_bit_mask; |
Behdad Esfahbod | 6fddf2d | 2012-11-12 17:57:24 -0800 | [diff] [blame] | 154 | |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 155 | unsigned int required_feature_index[2]; |
| 156 | hb_tag_t required_feature_tag[2]; |
| 157 | /* We default to applying required feature in stage 0. If the required |
| 158 | * feature has a tag that is known to the shaper, we apply required feature |
| 159 | * in the stage for that tag. |
| 160 | */ |
| 161 | unsigned int required_feature_stage[2] = {0, 0}; |
| 162 | |
| 163 | for (unsigned int table_index = 0; table_index < 2; table_index++) |
| 164 | { |
Behdad Esfahbod | 6fddf2d | 2012-11-12 17:57:24 -0800 | [diff] [blame] | 165 | m.chosen_script[table_index] = chosen_script[table_index]; |
Behdad Esfahbod | 851784f | 2012-11-14 16:24:05 -0800 | [diff] [blame] | 166 | m.found_script[table_index] = found_script[table_index]; |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 167 | |
| 168 | hb_ot_layout_language_get_required_feature (face, |
| 169 | table_tags[table_index], |
| 170 | script_index[table_index], |
| 171 | language_index[table_index], |
| 172 | &required_feature_index[table_index], |
| 173 | &required_feature_tag[table_index]); |
Behdad Esfahbod | 851784f | 2012-11-14 16:24:05 -0800 | [diff] [blame] | 174 | } |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 175 | |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 176 | /* Sort features and merge duplicates */ |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 177 | { |
Behdad Esfahbod | fb8cc86 | 2014-06-19 15:30:18 -0400 | [diff] [blame] | 178 | feature_infos.qsort (); |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 179 | unsigned int j = 0; |
| 180 | for (unsigned int i = 1; i < feature_infos.len; i++) |
| 181 | if (feature_infos[i].tag != feature_infos[j].tag) |
| 182 | feature_infos[++j] = feature_infos[i]; |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 183 | else { |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 184 | if (feature_infos[i].flags & F_GLOBAL) { |
| 185 | feature_infos[j].flags |= F_GLOBAL; |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 186 | feature_infos[j].max_value = feature_infos[i].max_value; |
| 187 | feature_infos[j].default_value = feature_infos[i].default_value; |
| 188 | } else { |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 189 | feature_infos[j].flags &= ~F_GLOBAL; |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 190 | feature_infos[j].max_value = MAX (feature_infos[j].max_value, feature_infos[i].max_value); |
Behdad Esfahbod | 398238a | 2013-02-15 07:40:10 -0500 | [diff] [blame] | 191 | /* Inherit default_value from j */ |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 192 | } |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 193 | feature_infos[j].flags |= (feature_infos[i].flags & F_HAS_FALLBACK); |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 194 | feature_infos[j].stage[0] = MIN (feature_infos[j].stage[0], feature_infos[i].stage[0]); |
| 195 | feature_infos[j].stage[1] = MIN (feature_infos[j].stage[1], feature_infos[i].stage[1]); |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 196 | } |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 197 | feature_infos.shrink (j + 1); |
| 198 | } |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 199 | |
| 200 | |
| 201 | /* Allocate bits now */ |
Behdad Esfahbod | 5287ccc | 2017-08-10 14:25:53 -0700 | [diff] [blame] | 202 | unsigned int next_bit = global_bit_shift + 1; |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 203 | |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 204 | for (unsigned int i = 0; i < feature_infos.len; i++) |
| 205 | { |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 206 | const feature_info_t *info = &feature_infos[i]; |
| 207 | |
| 208 | unsigned int bits_needed; |
| 209 | |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 210 | if ((info->flags & F_GLOBAL) && info->max_value == 1) |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 211 | /* Uses the global bit */ |
| 212 | bits_needed = 0; |
| 213 | else |
Behdad Esfahbod | 71c9f84 | 2018-09-10 22:37:19 +0200 | [diff] [blame] | 214 | /* Limit bits per feature. */ |
| 215 | bits_needed = MIN(HB_OT_MAP_MAX_BITS, hb_bit_storage (info->max_value)); |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 216 | |
Behdad Esfahbod | 852912f | 2010-10-13 15:34:50 -0400 | [diff] [blame] | 217 | if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t)) |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 218 | continue; /* Feature disabled, or not enough bits. */ |
| 219 | |
| 220 | |
Behdad Esfahbod | 176fd17 | 2013-10-30 17:27:24 +0000 | [diff] [blame] | 221 | hb_bool_t found = false; |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 222 | unsigned int feature_index[2]; |
| 223 | for (unsigned int table_index = 0; table_index < 2; table_index++) |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 224 | { |
| 225 | if (required_feature_tag[table_index] == info->tag) |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 226 | required_feature_stage[table_index] = info->stage[table_index]; |
Behdad Esfahbod | 731a430 | 2016-03-02 13:32:42 -0800 | [diff] [blame] | 227 | |
Behdad Esfahbod | 895fb5d | 2010-10-12 16:00:21 -0400 | [diff] [blame] | 228 | found |= hb_ot_layout_language_find_feature (face, |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 229 | table_tags[table_index], |
| 230 | script_index[table_index], |
| 231 | language_index[table_index], |
| 232 | info->tag, |
| 233 | &feature_index[table_index]); |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 234 | } |
Behdad Esfahbod | 0f98fe8 | 2015-07-23 11:52:11 +0100 | [diff] [blame] | 235 | if (!found && (info->flags & F_GLOBAL_SEARCH)) |
| 236 | { |
| 237 | for (unsigned int table_index = 0; table_index < 2; table_index++) |
| 238 | { |
| 239 | found |= hb_ot_layout_table_find_feature (face, |
| 240 | table_tags[table_index], |
| 241 | info->tag, |
| 242 | &feature_index[table_index]); |
| 243 | } |
| 244 | } |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 245 | if (!found && !(info->flags & F_HAS_FALLBACK)) |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 246 | continue; |
| 247 | |
| 248 | |
Behdad Esfahbod | 90645fb | 2011-05-27 18:13:31 -0400 | [diff] [blame] | 249 | hb_ot_map_t::feature_map_t *map = m.features.push (); |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 250 | |
| 251 | map->tag = info->tag; |
| 252 | map->index[0] = feature_index[0]; |
| 253 | map->index[1] = feature_index[1]; |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 254 | map->stage[0] = info->stage[0]; |
| 255 | map->stage[1] = info->stage[1]; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 256 | map->auto_zwnj = !(info->flags & F_MANUAL_ZWNJ); |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 257 | map->auto_zwj = !(info->flags & F_MANUAL_ZWJ); |
David Corbett | f05df64 | 2018-01-26 21:36:15 -0500 | [diff] [blame] | 258 | map->random = !!(info->flags & F_RANDOM); |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 259 | if ((info->flags & F_GLOBAL) && info->max_value == 1) { |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 260 | /* Uses the global bit */ |
Behdad Esfahbod | 5287ccc | 2017-08-10 14:25:53 -0700 | [diff] [blame] | 261 | map->shift = global_bit_shift; |
| 262 | map->mask = global_bit_mask; |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 263 | } else { |
| 264 | map->shift = next_bit; |
Behdad Esfahbod | 3331731 | 2016-08-08 17:24:04 -0700 | [diff] [blame] | 265 | map->mask = (1u << (next_bit + bits_needed)) - (1u << next_bit); |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 266 | next_bit += bits_needed; |
Behdad Esfahbod | 398238a | 2013-02-15 07:40:10 -0500 | [diff] [blame] | 267 | m.global_mask |= (info->default_value << map->shift) & map->mask; |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 268 | } |
Behdad Esfahbod | 3331731 | 2016-08-08 17:24:04 -0700 | [diff] [blame] | 269 | map->_1_mask = (1u << map->shift) & map->mask; |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 270 | map->needs_fallback = !found; |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 271 | |
| 272 | } |
Behdad Esfahbod | 6843569 | 2011-05-05 14:12:37 -0400 | [diff] [blame] | 273 | feature_infos.shrink (0); /* Done with these */ |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 274 | |
| 275 | |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 276 | add_gsub_pause (nullptr); |
| 277 | add_gpos_pause (nullptr); |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 278 | |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 279 | for (unsigned int table_index = 0; table_index < 2; table_index++) |
| 280 | { |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 281 | /* Collect lookup indices for features */ |
| 282 | |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 283 | unsigned int variations_index; |
| 284 | hb_ot_layout_table_find_feature_variations (face, |
| 285 | table_tags[table_index], |
| 286 | coords, |
| 287 | num_coords, |
| 288 | &variations_index); |
| 289 | |
Behdad Esfahbod | 8ac3c9c | 2013-04-21 15:19:38 -0400 | [diff] [blame] | 290 | unsigned int stage_index = 0; |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 291 | unsigned int last_num_lookups = 0; |
| 292 | for (unsigned stage = 0; stage < current_stage[table_index]; stage++) |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 293 | { |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 294 | if (required_feature_index[table_index] != HB_OT_LAYOUT_NO_FEATURE_INDEX && |
| 295 | required_feature_stage[table_index] == stage) |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 296 | add_lookups (m, table_index, |
Behdad Esfahbod | bde5e39 | 2016-09-10 02:43:20 -0700 | [diff] [blame] | 297 | required_feature_index[table_index], |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 298 | variations_index, |
Behdad Esfahbod | 5287ccc | 2017-08-10 14:25:53 -0700 | [diff] [blame] | 299 | global_bit_mask); |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 300 | |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 301 | for (unsigned i = 0; i < m.features.len; i++) |
| 302 | if (m.features[i].stage[table_index] == stage) |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 303 | add_lookups (m, table_index, |
Behdad Esfahbod | bde5e39 | 2016-09-10 02:43:20 -0700 | [diff] [blame] | 304 | m.features[i].index[table_index], |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 305 | variations_index, |
Behdad Esfahbod | bde5e39 | 2016-09-10 02:43:20 -0700 | [diff] [blame] | 306 | m.features[i].mask, |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 307 | m.features[i].auto_zwnj, |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 308 | m.features[i].auto_zwj, |
David Corbett | f05df64 | 2018-01-26 21:36:15 -0500 | [diff] [blame] | 309 | m.features[i].random); |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 310 | |
| 311 | /* Sort lookups and merge duplicates */ |
| 312 | if (last_num_lookups < m.lookups[table_index].len) |
| 313 | { |
Behdad Esfahbod | fb8cc86 | 2014-06-19 15:30:18 -0400 | [diff] [blame] | 314 | m.lookups[table_index].qsort (last_num_lookups, m.lookups[table_index].len); |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 315 | |
| 316 | unsigned int j = last_num_lookups; |
| 317 | for (unsigned int i = j + 1; i < m.lookups[table_index].len; i++) |
| 318 | if (m.lookups[table_index][i].index != m.lookups[table_index][j].index) |
| 319 | m.lookups[table_index][++j] = m.lookups[table_index][i]; |
| 320 | else |
Behdad Esfahbod | cfc507c | 2013-02-14 10:40:12 -0500 | [diff] [blame] | 321 | { |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 322 | m.lookups[table_index][j].mask |= m.lookups[table_index][i].mask; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 323 | m.lookups[table_index][j].auto_zwnj &= m.lookups[table_index][i].auto_zwnj; |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 324 | m.lookups[table_index][j].auto_zwj &= m.lookups[table_index][i].auto_zwj; |
Behdad Esfahbod | cfc507c | 2013-02-14 10:40:12 -0500 | [diff] [blame] | 325 | } |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 326 | m.lookups[table_index].shrink (j + 1); |
| 327 | } |
| 328 | |
| 329 | last_num_lookups = m.lookups[table_index].len; |
| 330 | |
Behdad Esfahbod | 8ac3c9c | 2013-04-21 15:19:38 -0400 | [diff] [blame] | 331 | if (stage_index < stages[table_index].len && stages[table_index][stage_index].index == stage) { |
Behdad Esfahbod | 893f57b | 2013-04-21 15:21:49 -0400 | [diff] [blame] | 332 | hb_ot_map_t::stage_map_t *stage_map = m.stages[table_index].push (); |
Behdad Esfahbod | f751576 | 2018-06-01 17:48:37 -0700 | [diff] [blame] | 333 | stage_map->last_lookup = last_num_lookups; |
| 334 | stage_map->pause_func = stages[table_index][stage_index].pause_func; |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 335 | |
Behdad Esfahbod | 8ac3c9c | 2013-04-21 15:19:38 -0400 | [diff] [blame] | 336 | stage_index++; |
Behdad Esfahbod | b70c96d | 2011-07-07 21:07:41 -0400 | [diff] [blame] | 337 | } |
Behdad Esfahbod | 5a2b0b3 | 2010-10-08 20:14:57 -0400 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | } |