Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2007,2008,2009,2010 Red Hat, Inc. |
Behdad Esfahbod | 5b93e8d | 2012-04-23 22:26:13 -0400 | [diff] [blame] | 3 | * Copyright © 2010,2012 Google, Inc. |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 4 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 5 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 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 |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 27 | */ |
| 28 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 29 | #ifndef HB_OT_LAYOUT_GSUBGPOS_HH |
| 30 | #define HB_OT_LAYOUT_GSUBGPOS_HH |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 31 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 32 | #include "hb.hh" |
| 33 | #include "hb-buffer.hh" |
| 34 | #include "hb-map.hh" |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 35 | #include "hb-set.hh" |
Behdad Esfahbod | 71c9f84 | 2018-09-10 22:37:19 +0200 | [diff] [blame] | 36 | #include "hb-ot-map.hh" |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 37 | #include "hb-ot-layout-common.hh" |
| 38 | #include "hb-ot-layout-gdef-table.hh" |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 39 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 40 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 41 | namespace OT { |
| 42 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 43 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 44 | struct hb_intersects_context_t : |
Behdad Esfahbod | 8d0a90a | 2020-06-18 16:53:54 -0700 | [diff] [blame] | 45 | hb_dispatch_context_t<hb_intersects_context_t, bool> |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 46 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 47 | template <typename T> |
Behdad Esfahbod | c14efb8 | 2019-05-05 09:54:58 -0700 | [diff] [blame] | 48 | return_t dispatch (const T &obj) { return obj.intersects (this->glyphs); } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 49 | static return_t default_return_value () { return false; } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 50 | bool stop_sublookup_iteration (return_t r) const { return r; } |
| 51 | |
| 52 | const hb_set_t *glyphs; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 53 | |
| 54 | hb_intersects_context_t (const hb_set_t *glyphs_) : |
Behdad Esfahbod | 70d6696 | 2020-06-18 17:09:39 -0700 | [diff] [blame] | 55 | glyphs (glyphs_) {} |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Behdad Esfahbod | 77a1a2b | 2015-10-09 12:20:58 -0400 | [diff] [blame] | 58 | struct hb_closure_context_t : |
Behdad Esfahbod | 25aec02 | 2020-06-18 16:58:01 -0700 | [diff] [blame] | 59 | hb_dispatch_context_t<hb_closure_context_t> |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 60 | { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 61 | typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); |
| 62 | template <typename T> |
Behdad Esfahbod | 7df3ecf | 2019-05-10 20:43:26 -0700 | [diff] [blame] | 63 | return_t dispatch (const T &obj) { obj.closure (this); return hb_empty_t (); } |
| 64 | static return_t default_return_value () { return hb_empty_t (); } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 65 | void recurse (unsigned int lookup_index) |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 66 | { |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 67 | if (unlikely (nesting_level_left == 0 || !recurse_func)) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 68 | return; |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 69 | |
| 70 | nesting_level_left--; |
| 71 | recurse_func (this, lookup_index); |
| 72 | nesting_level_left++; |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Garret Rieger | 4ad686b | 2020-03-25 23:32:28 -0700 | [diff] [blame] | 75 | bool lookup_limit_exceeded () |
Ebrahim Byagowi | 1a48278 | 2020-03-26 11:15:09 +0430 | [diff] [blame] | 76 | { return lookup_count > HB_MAX_LOOKUP_INDICES; } |
Garret Rieger | 4ad686b | 2020-03-25 23:32:28 -0700 | [diff] [blame] | 77 | |
Behdad Esfahbod | ba0ea56 | 2018-06-11 23:24:41 -0400 | [diff] [blame] | 78 | bool should_visit_lookup (unsigned int lookup_index) |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 79 | { |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 80 | if (lookup_count++ > HB_MAX_LOOKUP_INDICES) |
| 81 | return false; |
| 82 | |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 83 | if (is_lookup_done (lookup_index)) |
| 84 | return false; |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 85 | |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 86 | done_lookups->set (lookup_index, glyphs->get_population ()); |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | bool is_lookup_done (unsigned int lookup_index) |
| 91 | { |
Garret Rieger | 1e4fe10 | 2020-08-12 13:06:37 -0700 | [diff] [blame] | 92 | if (done_lookups->in_error ()) |
| 93 | return true; |
| 94 | |
Behdad Esfahbod | c38bd40 | 2018-07-24 09:43:27 -0700 | [diff] [blame] | 95 | /* Have we visited this lookup with the current set of glyphs? */ |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 96 | return done_lookups->get (lookup_index) == glyphs->get_population (); |
| 97 | } |
| 98 | |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 99 | hb_face_t *face; |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 100 | hb_set_t *glyphs; |
Behdad Esfahbod | ede1a71 | 2019-01-09 10:45:53 -0800 | [diff] [blame] | 101 | hb_set_t output[1]; |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 102 | recurse_func_t recurse_func; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 103 | unsigned int nesting_level_left; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 104 | |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 105 | hb_closure_context_t (hb_face_t *face_, |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 106 | hb_set_t *glyphs_, |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 107 | hb_map_t *done_lookups_, |
| 108 | unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) : |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 109 | face (face_), |
| 110 | glyphs (glyphs_), |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 111 | recurse_func (nullptr), |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 112 | nesting_level_left (nesting_level_left_), |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 113 | done_lookups (done_lookups_), |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 114 | lookup_count (0) |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 115 | {} |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 116 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 117 | ~hb_closure_context_t () { flush (); } |
Behdad Esfahbod | c38bd40 | 2018-07-24 09:43:27 -0700 | [diff] [blame] | 118 | |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 119 | void set_recurse_func (recurse_func_t func) { recurse_func = func; } |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 120 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 121 | void flush () |
Behdad Esfahbod | c38bd40 | 2018-07-24 09:43:27 -0700 | [diff] [blame] | 122 | { |
Michiharu Ariza | ff5223b | 2020-02-23 15:53:21 -0800 | [diff] [blame] | 123 | hb_set_del_range (output, face->get_num_glyphs (), hb_set_get_max (output)); /* Remove invalid glyphs. */ |
Behdad Esfahbod | ede1a71 | 2019-01-09 10:45:53 -0800 | [diff] [blame] | 124 | hb_set_union (glyphs, output); |
| 125 | hb_set_clear (output); |
Behdad Esfahbod | c38bd40 | 2018-07-24 09:43:27 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 128 | private: |
| 129 | hb_map_t *done_lookups; |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 130 | unsigned int lookup_count; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 131 | }; |
| 132 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 133 | struct hb_closure_lookups_context_t : |
Behdad Esfahbod | 25aec02 | 2020-06-18 16:58:01 -0700 | [diff] [blame] | 134 | hb_dispatch_context_t<hb_closure_lookups_context_t> |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 135 | { |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 136 | typedef return_t (*recurse_func_t) (hb_closure_lookups_context_t *c, unsigned lookup_index); |
| 137 | template <typename T> |
| 138 | return_t dispatch (const T &obj) { obj.closure_lookups (this); return hb_empty_t (); } |
| 139 | static return_t default_return_value () { return hb_empty_t (); } |
| 140 | void recurse (unsigned lookup_index) |
| 141 | { |
| 142 | if (unlikely (nesting_level_left == 0 || !recurse_func)) |
| 143 | return; |
| 144 | |
| 145 | /* Return if new lookup was recursed to before. */ |
| 146 | if (is_lookup_visited (lookup_index)) |
| 147 | return; |
| 148 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 149 | nesting_level_left--; |
| 150 | recurse_func (this, lookup_index); |
| 151 | nesting_level_left++; |
| 152 | } |
| 153 | |
| 154 | void set_lookup_visited (unsigned lookup_index) |
| 155 | { visited_lookups->add (lookup_index); } |
| 156 | |
| 157 | void set_lookup_inactive (unsigned lookup_index) |
| 158 | { inactive_lookups->add (lookup_index); } |
| 159 | |
Garret Rieger | 4ad686b | 2020-03-25 23:32:28 -0700 | [diff] [blame] | 160 | bool lookup_limit_exceeded () |
Ebrahim Byagowi | 1a48278 | 2020-03-26 11:15:09 +0430 | [diff] [blame] | 161 | { return lookup_count > HB_MAX_LOOKUP_INDICES; } |
Garret Rieger | 4ad686b | 2020-03-25 23:32:28 -0700 | [diff] [blame] | 162 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 163 | bool is_lookup_visited (unsigned lookup_index) |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 164 | { |
| 165 | if (lookup_count++ > HB_MAX_LOOKUP_INDICES) |
| 166 | return true; |
| 167 | |
Garret Rieger | 9562239 | 2020-08-12 13:01:22 -0700 | [diff] [blame] | 168 | if (visited_lookups->in_error ()) |
| 169 | return true; |
| 170 | |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 171 | return visited_lookups->has (lookup_index); |
| 172 | } |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 173 | |
| 174 | hb_face_t *face; |
| 175 | const hb_set_t *glyphs; |
| 176 | recurse_func_t recurse_func; |
| 177 | unsigned int nesting_level_left; |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 178 | |
| 179 | hb_closure_lookups_context_t (hb_face_t *face_, |
| 180 | const hb_set_t *glyphs_, |
| 181 | hb_set_t *visited_lookups_, |
| 182 | hb_set_t *inactive_lookups_, |
| 183 | unsigned nesting_level_left_ = HB_MAX_NESTING_LEVEL) : |
| 184 | face (face_), |
| 185 | glyphs (glyphs_), |
| 186 | recurse_func (nullptr), |
| 187 | nesting_level_left (nesting_level_left_), |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 188 | visited_lookups (visited_lookups_), |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 189 | inactive_lookups (inactive_lookups_), |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 190 | lookup_count (0) {} |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 191 | |
| 192 | void set_recurse_func (recurse_func_t func) { recurse_func = func; } |
| 193 | |
| 194 | private: |
| 195 | hb_set_t *visited_lookups; |
| 196 | hb_set_t *inactive_lookups; |
Garret Rieger | 834a224 | 2020-03-12 03:02:36 -0700 | [diff] [blame] | 197 | unsigned int lookup_count; |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 198 | }; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 199 | |
Behdad Esfahbod | 77a1a2b | 2015-10-09 12:20:58 -0400 | [diff] [blame] | 200 | struct hb_would_apply_context_t : |
Behdad Esfahbod | 8d0a90a | 2020-06-18 16:53:54 -0700 | [diff] [blame] | 201 | hb_dispatch_context_t<hb_would_apply_context_t, bool> |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 202 | { |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 203 | template <typename T> |
Behdad Esfahbod | c14efb8 | 2019-05-05 09:54:58 -0700 | [diff] [blame] | 204 | return_t dispatch (const T &obj) { return obj.would_apply (this); } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 205 | static return_t default_return_value () { return false; } |
Behdad Esfahbod | 7b912c1 | 2013-01-04 01:25:27 -0600 | [diff] [blame] | 206 | bool stop_sublookup_iteration (return_t r) const { return r; } |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 207 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 208 | hb_face_t *face; |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 209 | const hb_codepoint_t *glyphs; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 210 | unsigned int len; |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 211 | bool zero_context; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 212 | |
| 213 | hb_would_apply_context_t (hb_face_t *face_, |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 214 | const hb_codepoint_t *glyphs_, |
| 215 | unsigned int len_, |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 216 | bool zero_context_) : |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 217 | face (face_), |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 218 | glyphs (glyphs_), |
| 219 | len (len_), |
Behdad Esfahbod | 70d6696 | 2020-06-18 17:09:39 -0700 | [diff] [blame] | 220 | zero_context (zero_context_) {} |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 221 | }; |
| 222 | |
Behdad Esfahbod | 77a1a2b | 2015-10-09 12:20:58 -0400 | [diff] [blame] | 223 | struct hb_collect_glyphs_context_t : |
Behdad Esfahbod | 25aec02 | 2020-06-18 16:58:01 -0700 | [diff] [blame] | 224 | hb_dispatch_context_t<hb_collect_glyphs_context_t> |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 225 | { |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 226 | typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index); |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 227 | template <typename T> |
Behdad Esfahbod | 7df3ecf | 2019-05-10 20:43:26 -0700 | [diff] [blame] | 228 | return_t dispatch (const T &obj) { obj.collect_glyphs (this); return hb_empty_t (); } |
| 229 | static return_t default_return_value () { return hb_empty_t (); } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 230 | void recurse (unsigned int lookup_index) |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 231 | { |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 232 | if (unlikely (nesting_level_left == 0 || !recurse_func)) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 233 | return; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 234 | |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 235 | /* Note that GPOS sets recurse_func to nullptr already, so it doesn't get |
Behdad Esfahbod | 1bcfa06 | 2012-12-04 16:58:09 -0500 | [diff] [blame] | 236 | * past the previous check. For GSUB, we only want to collect the output |
Behdad Esfahbod | 76ea563 | 2013-05-04 16:01:20 -0400 | [diff] [blame] | 237 | * glyphs in the recursion. If output is not requested, we can go home now. |
| 238 | * |
| 239 | * Note further, that the above is not exactly correct. A recursed lookup |
| 240 | * is allowed to match input that is not matched in the context, but that's |
| 241 | * not how most fonts are built. It's possible to relax that and recurse |
| 242 | * with all sets here if it proves to be an issue. |
| 243 | */ |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 244 | |
| 245 | if (output == hb_set_get_empty ()) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 246 | return; |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 247 | |
Behdad Esfahbod | fde3e4a | 2014-10-29 11:23:08 -0700 | [diff] [blame] | 248 | /* Return if new lookup was recursed to before. */ |
Behdad Esfahbod | 8b9d9b7 | 2017-10-22 17:48:06 -0400 | [diff] [blame] | 249 | if (recursed_lookups->has (lookup_index)) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 250 | return; |
Behdad Esfahbod | fde3e4a | 2014-10-29 11:23:08 -0700 | [diff] [blame] | 251 | |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 252 | hb_set_t *old_before = before; |
| 253 | hb_set_t *old_input = input; |
| 254 | hb_set_t *old_after = after; |
| 255 | before = input = after = hb_set_get_empty (); |
Behdad Esfahbod | 1bcfa06 | 2012-12-04 16:58:09 -0500 | [diff] [blame] | 256 | |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 257 | nesting_level_left--; |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 258 | recurse_func (this, lookup_index); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 259 | nesting_level_left++; |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 260 | |
| 261 | before = old_before; |
| 262 | input = old_input; |
| 263 | after = old_after; |
| 264 | |
Behdad Esfahbod | 8b9d9b7 | 2017-10-22 17:48:06 -0400 | [diff] [blame] | 265 | recursed_lookups->add (lookup_index); |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 266 | } |
| 267 | |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 268 | hb_face_t *face; |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 269 | hb_set_t *before; |
| 270 | hb_set_t *input; |
| 271 | hb_set_t *after; |
| 272 | hb_set_t *output; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 273 | recurse_func_t recurse_func; |
Behdad Esfahbod | 8b9d9b7 | 2017-10-22 17:48:06 -0400 | [diff] [blame] | 274 | hb_set_t *recursed_lookups; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 275 | unsigned int nesting_level_left; |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 276 | |
| 277 | hb_collect_glyphs_context_t (hb_face_t *face_, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 278 | hb_set_t *glyphs_before, /* OUT. May be NULL */ |
| 279 | hb_set_t *glyphs_input, /* OUT. May be NULL */ |
| 280 | hb_set_t *glyphs_after, /* OUT. May be NULL */ |
| 281 | hb_set_t *glyphs_output, /* OUT. May be NULL */ |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 282 | unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) : |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 283 | face (face_), |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 284 | before (glyphs_before ? glyphs_before : hb_set_get_empty ()), |
| 285 | input (glyphs_input ? glyphs_input : hb_set_get_empty ()), |
| 286 | after (glyphs_after ? glyphs_after : hb_set_get_empty ()), |
| 287 | output (glyphs_output ? glyphs_output : hb_set_get_empty ()), |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 288 | recurse_func (nullptr), |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 289 | recursed_lookups (hb_set_create ()), |
Behdad Esfahbod | 70d6696 | 2020-06-18 17:09:39 -0700 | [diff] [blame] | 290 | nesting_level_left (nesting_level_left_) {} |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 291 | ~hb_collect_glyphs_context_t () { hb_set_destroy (recursed_lookups); } |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 292 | |
| 293 | void set_recurse_func (recurse_func_t func) { recurse_func = func; } |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | |
| 297 | |
Behdad Esfahbod | 8e36ccf | 2015-02-17 19:15:34 +0300 | [diff] [blame] | 298 | template <typename set_t> |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 299 | struct hb_collect_coverage_context_t : |
Behdad Esfahbod | 8d0a90a | 2020-06-18 16:53:54 -0700 | [diff] [blame] | 300 | hb_dispatch_context_t<hb_collect_coverage_context_t<set_t>, const Coverage &> |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 301 | { |
Behdad Esfahbod | dc492d7 | 2020-06-18 17:03:05 -0700 | [diff] [blame] | 302 | typedef const Coverage &return_t; // Stoopid that we have to dupe this here. |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 303 | template <typename T> |
Behdad Esfahbod | c14efb8 | 2019-05-05 09:54:58 -0700 | [diff] [blame] | 304 | return_t dispatch (const T &obj) { return obj.get_coverage (); } |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 305 | static return_t default_return_value () { return Null (Coverage); } |
Behdad Esfahbod | 8e36ccf | 2015-02-17 19:15:34 +0300 | [diff] [blame] | 306 | bool stop_sublookup_iteration (return_t r) const |
| 307 | { |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 308 | r.collect_coverage (set); |
Behdad Esfahbod | 8e36ccf | 2015-02-17 19:15:34 +0300 | [diff] [blame] | 309 | return false; |
| 310 | } |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 311 | |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 312 | hb_collect_coverage_context_t (set_t *set_) : |
Behdad Esfahbod | 70d6696 | 2020-06-18 17:09:39 -0700 | [diff] [blame] | 313 | set (set_) {} |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 314 | |
Behdad Esfahbod | 8e36ccf | 2015-02-17 19:15:34 +0300 | [diff] [blame] | 315 | set_t *set; |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 319 | struct hb_ot_apply_context_t : |
| 320 | hb_dispatch_context_t<hb_ot_apply_context_t, bool, HB_DEBUG_APPLY> |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 321 | { |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 322 | struct matcher_t |
| 323 | { |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 324 | matcher_t () : |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 325 | lookup_props (0), |
Behdad Esfahbod | cfc507c | 2013-02-14 10:40:12 -0500 | [diff] [blame] | 326 | ignore_zwnj (false), |
| 327 | ignore_zwj (false), |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 328 | mask (-1), |
| 329 | #define arg1(arg) (arg) /* Remove the macro to see why it's needed! */ |
| 330 | syllable arg1(0), |
| 331 | #undef arg1 |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 332 | match_func (nullptr), |
Ebrahim Byagowi | f7a08cd | 2018-10-30 11:29:09 +0330 | [diff] [blame] | 333 | match_data (nullptr) {} |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 334 | |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 335 | typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 336 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 337 | void set_ignore_zwnj (bool ignore_zwnj_) { ignore_zwnj = ignore_zwnj_; } |
| 338 | void set_ignore_zwj (bool ignore_zwj_) { ignore_zwj = ignore_zwj_; } |
| 339 | void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; } |
| 340 | void set_mask (hb_mask_t mask_) { mask = mask_; } |
| 341 | void set_syllable (uint8_t syllable_) { syllable = syllable_; } |
| 342 | void set_match_func (match_func_t match_func_, |
Ebrahim Byagowi | d0e2add | 2020-07-18 22:14:52 +0430 | [diff] [blame] | 343 | const void *match_data_) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 344 | { match_func = match_func_; match_data = match_data_; } |
| 345 | |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 346 | enum may_match_t { |
| 347 | MATCH_NO, |
| 348 | MATCH_YES, |
| 349 | MATCH_MAYBE |
| 350 | }; |
| 351 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 352 | may_match_t may_match (const hb_glyph_info_t &info, |
Behdad Esfahbod | 085793d | 2019-04-24 10:15:59 -0400 | [diff] [blame] | 353 | const HBUINT16 *glyph_data) const |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 354 | { |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 355 | if (!(info.mask & mask) || |
| 356 | (syllable && syllable != info.syllable ())) |
| 357 | return MATCH_NO; |
| 358 | |
| 359 | if (match_func) |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 360 | return match_func (info.codepoint, *glyph_data, match_data) ? MATCH_YES : MATCH_NO; |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 361 | |
| 362 | return MATCH_MAYBE; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | enum may_skip_t { |
| 366 | SKIP_NO, |
| 367 | SKIP_YES, |
| 368 | SKIP_MAYBE |
| 369 | }; |
| 370 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 371 | may_skip_t may_skip (const hb_ot_apply_context_t *c, |
| 372 | const hb_glyph_info_t &info) const |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 373 | { |
Behdad Esfahbod | b98c5db | 2014-07-16 13:44:01 -0400 | [diff] [blame] | 374 | if (!c->check_glyph_property (&info, lookup_props)) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 375 | return SKIP_YES; |
| 376 | |
Khaled Hosny | 06cfe3f | 2017-05-17 21:32:47 +0300 | [diff] [blame] | 377 | if (unlikely (_hb_glyph_info_is_default_ignorable_and_not_hidden (&info) && |
Behdad Esfahbod | 0b45479 | 2013-02-14 10:46:52 -0500 | [diff] [blame] | 378 | (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info)) && |
Behdad Esfahbod | 4ba796b | 2015-07-22 17:41:31 +0100 | [diff] [blame] | 379 | (ignore_zwj || !_hb_glyph_info_is_zwj (&info)))) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 380 | return SKIP_MAYBE; |
| 381 | |
| 382 | return SKIP_NO; |
| 383 | } |
| 384 | |
| 385 | protected: |
| 386 | unsigned int lookup_props; |
| 387 | bool ignore_zwnj; |
Behdad Esfahbod | 0b45479 | 2013-02-14 10:46:52 -0500 | [diff] [blame] | 388 | bool ignore_zwj; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 389 | hb_mask_t mask; |
| 390 | uint8_t syllable; |
| 391 | match_func_t match_func; |
| 392 | const void *match_data; |
| 393 | }; |
| 394 | |
Behdad Esfahbod | 6962669 | 2015-01-29 13:08:41 +0100 | [diff] [blame] | 395 | struct skipping_iterator_t |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 396 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 397 | void init (hb_ot_apply_context_t *c_, bool context_match = false) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 398 | { |
Behdad Esfahbod | 514564f | 2015-01-29 13:48:48 +0100 | [diff] [blame] | 399 | c = c_; |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 400 | match_glyph_data = nullptr; |
| 401 | matcher.set_match_func (nullptr, nullptr); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 402 | matcher.set_lookup_props (c->lookup_props); |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 403 | /* Ignore ZWNJ if we are matching GPOS, or matching GSUB context and asked to. */ |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 404 | matcher.set_ignore_zwnj (c->table_index == 1 || (context_match && c->auto_zwnj)); |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 405 | /* Ignore ZWJ if we are matching context, or asked to. */ |
| 406 | matcher.set_ignore_zwj (context_match || c->auto_zwj); |
Behdad Esfahbod | 514564f | 2015-01-29 13:48:48 +0100 | [diff] [blame] | 407 | matcher.set_mask (context_match ? -1 : c->lookup_mask); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 408 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 409 | void set_lookup_props (unsigned int lookup_props) |
Behdad Esfahbod | 514564f | 2015-01-29 13:48:48 +0100 | [diff] [blame] | 410 | { |
| 411 | matcher.set_lookup_props (lookup_props); |
| 412 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 413 | void set_match_func (matcher_t::match_func_t match_func_, |
| 414 | const void *match_data_, |
| 415 | const HBUINT16 glyph_data[]) |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 416 | { |
Behdad Esfahbod | 4a6b1ee | 2015-10-21 11:20:55 -0200 | [diff] [blame] | 417 | matcher.set_match_func (match_func_, match_data_); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 418 | match_glyph_data = glyph_data; |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 419 | } |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 420 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 421 | void reset (unsigned int start_index_, |
Ebrahim Byagowi | 08428a1 | 2020-04-24 23:45:17 +0430 | [diff] [blame] | 422 | unsigned int num_items_) |
Behdad Esfahbod | b051be5 | 2015-01-29 13:40:39 +0100 | [diff] [blame] | 423 | { |
| 424 | idx = start_index_; |
| 425 | num_items = num_items_; |
| 426 | end = c->buffer->len; |
| 427 | matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0); |
| 428 | } |
| 429 | |
Ebrahim Byagowi | 64a45be | 2019-11-09 12:25:33 +0330 | [diff] [blame] | 430 | void reject () |
| 431 | { |
| 432 | num_items++; |
| 433 | if (match_glyph_data) match_glyph_data--; |
| 434 | } |
Behdad Esfahbod | 6962669 | 2015-01-29 13:08:41 +0100 | [diff] [blame] | 435 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 436 | matcher_t::may_skip_t |
| 437 | may_skip (const hb_glyph_info_t &info) const |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 438 | { return matcher.may_skip (c, info); } |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 439 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 440 | bool next () |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 441 | { |
Behdad Esfahbod | 506ffeb | 2012-01-18 16:07:53 -0500 | [diff] [blame] | 442 | assert (num_items > 0); |
Behdad Esfahbod | 37d13ac | 2015-01-29 11:38:01 +0100 | [diff] [blame] | 443 | while (idx + num_items < end) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 444 | { |
Behdad Esfahbod | a4a48fe | 2012-01-17 18:08:41 -0500 | [diff] [blame] | 445 | idx++; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 446 | const hb_glyph_info_t &info = c->buffer->info[idx]; |
| 447 | |
Behdad Esfahbod | ff93ac8 | 2013-02-21 14:51:40 -0500 | [diff] [blame] | 448 | matcher_t::may_skip_t skip = matcher.may_skip (c, info); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 449 | if (unlikely (skip == matcher_t::SKIP_YES)) |
| 450 | continue; |
| 451 | |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 452 | matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data); |
Behdad Esfahbod | 722e8b8 | 2013-02-21 15:37:51 -0500 | [diff] [blame] | 453 | if (match == matcher_t::MATCH_YES || |
| 454 | (match == matcher_t::MATCH_MAYBE && |
| 455 | skip == matcher_t::SKIP_NO)) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 456 | { |
| 457 | num_items--; |
Ebrahim Byagowi | aca6390 | 2019-10-22 00:06:46 +0330 | [diff] [blame] | 458 | if (match_glyph_data) match_glyph_data++; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 459 | return true; |
| 460 | } |
| 461 | |
| 462 | if (skip == matcher_t::SKIP_NO) |
Behdad Esfahbod | 722e8b8 | 2013-02-21 15:37:51 -0500 | [diff] [blame] | 463 | return false; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 464 | } |
| 465 | return false; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 466 | } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 467 | bool prev () |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 468 | { |
Behdad Esfahbod | 506ffeb | 2012-01-18 16:07:53 -0500 | [diff] [blame] | 469 | assert (num_items > 0); |
Behdad Esfahbod | 18a06f8 | 2018-07-05 14:03:48 +0430 | [diff] [blame] | 470 | while (idx > num_items - 1) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 471 | { |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 472 | idx--; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 473 | const hb_glyph_info_t &info = c->buffer->out_info[idx]; |
| 474 | |
Behdad Esfahbod | ff93ac8 | 2013-02-21 14:51:40 -0500 | [diff] [blame] | 475 | matcher_t::may_skip_t skip = matcher.may_skip (c, info); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 476 | if (unlikely (skip == matcher_t::SKIP_YES)) |
| 477 | continue; |
| 478 | |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 479 | matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data); |
Behdad Esfahbod | 722e8b8 | 2013-02-21 15:37:51 -0500 | [diff] [blame] | 480 | if (match == matcher_t::MATCH_YES || |
| 481 | (match == matcher_t::MATCH_MAYBE && |
| 482 | skip == matcher_t::SKIP_NO)) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 483 | { |
| 484 | num_items--; |
Ebrahim Byagowi | aca6390 | 2019-10-22 00:06:46 +0330 | [diff] [blame] | 485 | if (match_glyph_data) match_glyph_data++; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 486 | return true; |
| 487 | } |
| 488 | |
| 489 | if (skip == matcher_t::SKIP_NO) |
Behdad Esfahbod | 722e8b8 | 2013-02-21 15:37:51 -0500 | [diff] [blame] | 490 | return false; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 491 | } |
| 492 | return false; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 493 | } |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 494 | |
| 495 | unsigned int idx; |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 496 | protected: |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 497 | hb_ot_apply_context_t *c; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 498 | matcher_t matcher; |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 499 | const HBUINT16 *match_glyph_data; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 500 | |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 501 | unsigned int num_items; |
Behdad Esfahbod | 6962669 | 2015-01-29 13:08:41 +0100 | [diff] [blame] | 502 | unsigned int end; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 503 | }; |
| 504 | |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 505 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 506 | const char *get_name () { return "APPLY"; } |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 507 | typedef return_t (*recurse_func_t) (hb_ot_apply_context_t *c, unsigned int lookup_index); |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 508 | template <typename T> |
Behdad Esfahbod | c14efb8 | 2019-05-05 09:54:58 -0700 | [diff] [blame] | 509 | return_t dispatch (const T &obj) { return obj.apply (this); } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 510 | static return_t default_return_value () { return false; } |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 511 | bool stop_sublookup_iteration (return_t r) const { return r; } |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 512 | return_t recurse (unsigned int sub_lookup_index) |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 513 | { |
Behdad Esfahbod | baf7779 | 2017-11-14 21:53:48 -0800 | [diff] [blame] | 514 | if (unlikely (nesting_level_left == 0 || !recurse_func || buffer->max_ops-- <= 0)) |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 515 | return default_return_value (); |
| 516 | |
| 517 | nesting_level_left--; |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 518 | bool ret = recurse_func (this, sub_lookup_index); |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 519 | nesting_level_left++; |
| 520 | return ret; |
| 521 | } |
| 522 | |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 523 | skipping_iterator_t iter_input, iter_context; |
| 524 | |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 525 | hb_font_t *font; |
| 526 | hb_face_t *face; |
| 527 | hb_buffer_t *buffer; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 528 | recurse_func_t recurse_func; |
| 529 | const GDEF &gdef; |
| 530 | const VariationStore &var_store; |
| 531 | |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 532 | hb_direction_t direction; |
| 533 | hb_mask_t lookup_mask; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 534 | unsigned int table_index; /* GSUB/GPOS */ |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 535 | unsigned int lookup_index; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 536 | unsigned int lookup_props; |
| 537 | unsigned int nesting_level_left; |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 538 | |
Behdad Esfahbod | 80de4bc | 2018-09-10 16:24:52 +0200 | [diff] [blame] | 539 | bool has_glyph_classes; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 540 | bool auto_zwnj; |
| 541 | bool auto_zwj; |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 542 | bool random; |
Behdad Esfahbod | 80de4bc | 2018-09-10 16:24:52 +0200 | [diff] [blame] | 543 | |
Behdad Esfahbod | cfdea88 | 2018-09-11 10:57:48 +0200 | [diff] [blame] | 544 | uint32_t random_state; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 545 | |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 546 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 547 | hb_ot_apply_context_t (unsigned int table_index_, |
Ebrahim Byagowi | d0e2add | 2020-07-18 22:14:52 +0430 | [diff] [blame] | 548 | hb_font_t *font_, |
| 549 | hb_buffer_t *buffer_) : |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 550 | iter_input (), iter_context (), |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 551 | font (font_), face (font->face), buffer (buffer_), |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 552 | recurse_func (nullptr), |
Behdad Esfahbod | 7dcf8e1 | 2019-06-26 13:44:10 -0700 | [diff] [blame] | 553 | gdef ( |
| 554 | #ifndef HB_NO_OT_LAYOUT |
| 555 | *face->table.GDEF->table |
| 556 | #else |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 557 | Null (GDEF) |
Behdad Esfahbod | 7dcf8e1 | 2019-06-26 13:44:10 -0700 | [diff] [blame] | 558 | #endif |
| 559 | ), |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 560 | var_store (gdef.get_var_store ()), |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 561 | direction (buffer_->props.direction), |
| 562 | lookup_mask (1), |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 563 | table_index (table_index_), |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 564 | lookup_index ((unsigned int) -1), |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 565 | lookup_props (0), |
| 566 | nesting_level_left (HB_MAX_NESTING_LEVEL), |
Behdad Esfahbod | 80de4bc | 2018-09-10 16:24:52 +0200 | [diff] [blame] | 567 | has_glyph_classes (gdef.has_glyph_classes ()), |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 568 | auto_zwnj (true), |
| 569 | auto_zwj (true), |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 570 | random (false), |
Behdad Esfahbod | d748dc7 | 2018-09-24 18:30:50 -0400 | [diff] [blame] | 571 | random_state (1) { init_iters (); } |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 572 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 573 | void init_iters () |
Behdad Esfahbod | 365576d | 2015-01-29 13:59:42 +0100 | [diff] [blame] | 574 | { |
Behdad Esfahbod | 365576d | 2015-01-29 13:59:42 +0100 | [diff] [blame] | 575 | iter_input.init (this, false); |
| 576 | iter_context.init (this, true); |
| 577 | } |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 578 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 579 | void set_lookup_mask (hb_mask_t mask) { lookup_mask = mask; init_iters (); } |
| 580 | void set_auto_zwj (bool auto_zwj_) { auto_zwj = auto_zwj_; init_iters (); } |
| 581 | void set_auto_zwnj (bool auto_zwnj_) { auto_zwnj = auto_zwnj_; init_iters (); } |
| 582 | void set_random (bool random_) { random = random_; } |
| 583 | void set_recurse_func (recurse_func_t func) { recurse_func = func; } |
| 584 | void set_lookup_index (unsigned int lookup_index_) { lookup_index = lookup_index_; } |
| 585 | void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; init_iters (); } |
Behdad Esfahbod | 9516cbd | 2018-09-23 22:00:34 -0400 | [diff] [blame] | 586 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 587 | uint32_t random_number () |
Behdad Esfahbod | 08260c7 | 2018-09-11 10:51:19 +0200 | [diff] [blame] | 588 | { |
Behdad Esfahbod | cfdea88 | 2018-09-11 10:57:48 +0200 | [diff] [blame] | 589 | /* http://www.cplusplus.com/reference/random/minstd_rand/ */ |
| 590 | random_state = random_state * 48271 % 2147483647; |
| 591 | return random_state; |
Behdad Esfahbod | 08260c7 | 2018-09-11 10:51:19 +0200 | [diff] [blame] | 592 | } |
| 593 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 594 | bool match_properties_mark (hb_codepoint_t glyph, |
| 595 | unsigned int glyph_props, |
| 596 | unsigned int match_props) const |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 597 | { |
| 598 | /* If using mark filtering sets, the high short of |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 599 | * match_props has the set index. |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 600 | */ |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 601 | if (match_props & LookupFlag::UseMarkFilteringSet) |
| 602 | return gdef.mark_set_covers (match_props >> 16, glyph); |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 603 | |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 604 | /* The second byte of match_props has the meaning |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 605 | * "ignore marks of attachment type different than |
| 606 | * the attachment type specified." |
| 607 | */ |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 608 | if (match_props & LookupFlag::MarkAttachmentType) |
| 609 | return (match_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType); |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 610 | |
| 611 | return true; |
| 612 | } |
| 613 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 614 | bool check_glyph_property (const hb_glyph_info_t *info, |
| 615 | unsigned int match_props) const |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 616 | { |
Behdad Esfahbod | b98c5db | 2014-07-16 13:44:01 -0400 | [diff] [blame] | 617 | hb_codepoint_t glyph = info->codepoint; |
| 618 | unsigned int glyph_props = _hb_glyph_info_get_glyph_props (info); |
| 619 | |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 620 | /* Not covered, if, for example, glyph class is ligature and |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 621 | * match_props includes LookupFlags::IgnoreLigatures |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 622 | */ |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 623 | if (glyph_props & match_props & LookupFlag::IgnoreFlags) |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 624 | return false; |
| 625 | |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 626 | if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 627 | return match_properties_mark (glyph, glyph_props, match_props); |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 628 | |
| 629 | return true; |
| 630 | } |
| 631 | |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 632 | void _set_glyph_props (hb_codepoint_t glyph_index, |
| 633 | unsigned int class_guess = 0, |
| 634 | bool ligature = false, |
| 635 | bool component = false) const |
Behdad Esfahbod | 60da763 | 2012-07-16 16:13:32 -0400 | [diff] [blame] | 636 | { |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 637 | unsigned int add_in = _hb_glyph_info_get_glyph_props (&buffer->cur()) & |
| 638 | HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE; |
| 639 | add_in |= HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED; |
Behdad Esfahbod | 09675a8 | 2013-10-18 01:05:58 +0200 | [diff] [blame] | 640 | if (ligature) |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 641 | { |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 642 | add_in |= HB_OT_LAYOUT_GLYPH_PROPS_LIGATED; |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 643 | /* In the only place that the MULTIPLIED bit is used, Uniscribe |
| 644 | * seems to only care about the "last" transformation between |
Bruce Mitchener | 257d0e5 | 2018-10-19 22:49:21 +0700 | [diff] [blame] | 645 | * Ligature and Multiple substitutions. Ie. if you ligate, expand, |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 646 | * and ligate again, it forgives the multiplication and acts as |
| 647 | * if only ligation happened. As such, clear MULTIPLIED bit. |
| 648 | */ |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 649 | add_in &= ~HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED; |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 650 | } |
| 651 | if (component) |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 652 | add_in |= HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED; |
Behdad Esfahbod | 2fca142 | 2012-07-30 18:46:41 -0400 | [diff] [blame] | 653 | if (likely (has_glyph_classes)) |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 654 | _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | gdef.get_glyph_props (glyph_index)); |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 655 | else if (class_guess) |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 656 | _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | class_guess); |
Behdad Esfahbod | 60da763 | 2012-07-16 16:13:32 -0400 | [diff] [blame] | 657 | } |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 658 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 659 | void replace_glyph (hb_codepoint_t glyph_index) const |
Behdad Esfahbod | 3ec77d6 | 2012-06-08 21:44:06 -0400 | [diff] [blame] | 660 | { |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 661 | _set_glyph_props (glyph_index); |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 662 | buffer->replace_glyph (glyph_index); |
| 663 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 664 | void replace_glyph_inplace (hb_codepoint_t glyph_index) const |
Behdad Esfahbod | 7fbbf86 | 2012-07-30 18:36:42 -0400 | [diff] [blame] | 665 | { |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 666 | _set_glyph_props (glyph_index); |
Behdad Esfahbod | 7fbbf86 | 2012-07-30 18:36:42 -0400 | [diff] [blame] | 667 | buffer->cur().codepoint = glyph_index; |
| 668 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 669 | void replace_glyph_with_ligature (hb_codepoint_t glyph_index, |
Behdad Esfahbod | f4cd99f | 2020-04-22 14:45:57 -0700 | [diff] [blame] | 670 | unsigned int class_guess) const |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 671 | { |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 672 | _set_glyph_props (glyph_index, class_guess, true); |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 673 | buffer->replace_glyph (glyph_index); |
| 674 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 675 | void output_glyph_for_component (hb_codepoint_t glyph_index, |
Behdad Esfahbod | f4cd99f | 2020-04-22 14:45:57 -0700 | [diff] [blame] | 676 | unsigned int class_guess) const |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 677 | { |
Ebrahim Byagowi | 9748ae7 | 2020-08-11 17:52:48 +0430 | [diff] [blame] | 678 | _set_glyph_props (glyph_index, class_guess, false, true); |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 679 | buffer->output_glyph (glyph_index); |
| 680 | } |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 681 | }; |
| 682 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 683 | |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 684 | struct hb_get_subtables_context_t : |
Behdad Esfahbod | 25aec02 | 2020-06-18 16:58:01 -0700 | [diff] [blame] | 685 | hb_dispatch_context_t<hb_get_subtables_context_t> |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 686 | { |
| 687 | template <typename Type> |
Behdad Esfahbod | a061e47 | 2019-12-10 13:31:50 -0600 | [diff] [blame] | 688 | static inline bool apply_to (const void *obj, OT::hb_ot_apply_context_t *c) |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 689 | { |
| 690 | const Type *typed_obj = (const Type *) obj; |
| 691 | return typed_obj->apply (c); |
| 692 | } |
| 693 | |
| 694 | typedef bool (*hb_apply_func_t) (const void *obj, OT::hb_ot_apply_context_t *c); |
| 695 | |
| 696 | struct hb_applicable_t |
| 697 | { |
| 698 | template <typename T> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 699 | void init (const T &obj_, hb_apply_func_t apply_func_) |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 700 | { |
| 701 | obj = &obj_; |
| 702 | apply_func = apply_func_; |
| 703 | digest.init (); |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 704 | obj_.get_coverage ().collect_coverage (&digest); |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 705 | } |
| 706 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 707 | bool apply (OT::hb_ot_apply_context_t *c) const |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 708 | { |
| 709 | return digest.may_have (c->buffer->cur().codepoint) && apply_func (obj, c); |
| 710 | } |
| 711 | |
| 712 | private: |
| 713 | const void *obj; |
| 714 | hb_apply_func_t apply_func; |
| 715 | hb_set_digest_t digest; |
| 716 | }; |
| 717 | |
Behdad Esfahbod | fa333e3 | 2018-12-27 17:56:22 -0500 | [diff] [blame] | 718 | typedef hb_vector_t<hb_applicable_t> array_t; |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 719 | |
| 720 | /* Dispatch interface. */ |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 721 | template <typename T> |
Behdad Esfahbod | c14efb8 | 2019-05-05 09:54:58 -0700 | [diff] [blame] | 722 | return_t dispatch (const T &obj) |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 723 | { |
| 724 | hb_applicable_t *entry = array.push(); |
| 725 | entry->init (obj, apply_to<T>); |
Behdad Esfahbod | 7df3ecf | 2019-05-10 20:43:26 -0700 | [diff] [blame] | 726 | return hb_empty_t (); |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 727 | } |
Behdad Esfahbod | 7df3ecf | 2019-05-10 20:43:26 -0700 | [diff] [blame] | 728 | static return_t default_return_value () { return hb_empty_t (); } |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 729 | |
| 730 | hb_get_subtables_context_t (array_t &array_) : |
Behdad Esfahbod | 1535440 | 2020-06-19 08:30:59 -0700 | [diff] [blame] | 731 | array (array_) {} |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 732 | |
| 733 | array_t &array; |
Behdad Esfahbod | b339099 | 2018-10-10 12:07:49 -0400 | [diff] [blame] | 734 | }; |
| 735 | |
| 736 | |
| 737 | |
Behdad Esfahbod | 94a23aa | 2010-05-05 01:13:09 -0400 | [diff] [blame] | 738 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 739 | typedef bool (*intersects_func_t) (const hb_set_t *glyphs, const HBUINT16 &value, const void *data); |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 740 | typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const HBUINT16 &value, const void *data); |
| 741 | typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 742 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 743 | struct ContextClosureFuncs |
| 744 | { |
| 745 | intersects_func_t intersects; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 746 | }; |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 747 | struct ContextCollectGlyphsFuncs |
| 748 | { |
| 749 | collect_glyphs_func_t collect; |
| 750 | }; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 751 | struct ContextApplyFuncs |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 752 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 753 | match_func_t match; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 754 | }; |
| 755 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 756 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 757 | static inline bool intersects_glyph (const hb_set_t *glyphs, const HBUINT16 &value, const void *data HB_UNUSED) |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 758 | { |
| 759 | return glyphs->has (value); |
| 760 | } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 761 | static inline bool intersects_class (const hb_set_t *glyphs, const HBUINT16 &value, const void *data) |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 762 | { |
| 763 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
| 764 | return class_def.intersects_class (glyphs, value); |
| 765 | } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 766 | static inline bool intersects_coverage (const hb_set_t *glyphs, const HBUINT16 &value, const void *data) |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 767 | { |
| 768 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
| 769 | return (data+coverage).intersects (glyphs); |
| 770 | } |
| 771 | |
Qunxin Liu | 44d88cf | 2020-05-08 15:33:34 -0700 | [diff] [blame] | 772 | static inline bool array_is_subset_of (const hb_set_t *glyphs, |
| 773 | unsigned int count, |
| 774 | const HBUINT16 values[], |
| 775 | intersects_func_t intersects_func, |
| 776 | const void *intersects_data) |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 777 | { |
Garret Rieger | 95ab110 | 2019-10-21 13:15:46 -0700 | [diff] [blame] | 778 | for (const HBUINT16 &_ : + hb_iter (values, count)) |
Qunxin Liu | 44d88cf | 2020-05-08 15:33:34 -0700 | [diff] [blame] | 779 | if (!intersects_func (glyphs, _, intersects_data)) return false; |
| 780 | return true; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 781 | } |
| 782 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 783 | |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 784 | static inline void collect_glyph (hb_set_t *glyphs, const HBUINT16 &value, const void *data HB_UNUSED) |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 785 | { |
| 786 | glyphs->add (value); |
| 787 | } |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 788 | static inline void collect_class (hb_set_t *glyphs, const HBUINT16 &value, const void *data) |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 789 | { |
| 790 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
Behdad Esfahbod | 89ad3c6 | 2020-04-23 10:57:30 -0700 | [diff] [blame] | 791 | class_def.collect_class (glyphs, value); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 792 | } |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 793 | static inline void collect_coverage (hb_set_t *glyphs, const HBUINT16 &value, const void *data) |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 794 | { |
| 795 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 796 | (data+coverage).collect_coverage (glyphs); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 797 | } |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 798 | static inline void collect_array (hb_collect_glyphs_context_t *c HB_UNUSED, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 799 | hb_set_t *glyphs, |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 800 | unsigned int count, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 801 | const HBUINT16 values[], |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 802 | collect_glyphs_func_t collect_func, |
| 803 | const void *collect_data) |
| 804 | { |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 805 | return |
| 806 | + hb_iter (values, count) |
| 807 | | hb_apply ([&] (const HBUINT16 &_) { collect_func (glyphs, _, collect_data); }) |
| 808 | ; |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 812 | static inline bool match_glyph (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data HB_UNUSED) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 813 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 814 | return glyph_id == value; |
| 815 | } |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 816 | static inline bool match_class (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 817 | { |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 818 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 819 | return class_def.get_class (glyph_id) == value; |
| 820 | } |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 821 | static inline bool match_coverage (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 822 | { |
Behdad Esfahbod | 6b54c5d | 2009-05-18 18:30:25 -0400 | [diff] [blame] | 823 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 824 | return (data+coverage).get_coverage (glyph_id) != NOT_COVERED; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 825 | } |
| 826 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 827 | static inline bool would_match_input (hb_would_apply_context_t *c, |
| 828 | unsigned int count, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 829 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 830 | match_func_t match_func, |
| 831 | const void *match_data) |
| 832 | { |
| 833 | if (count != c->len) |
| 834 | return false; |
| 835 | |
| 836 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 837 | if (likely (!match_func (c->glyphs[i], input[i - 1], match_data))) |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 838 | return false; |
| 839 | |
| 840 | return true; |
| 841 | } |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 842 | static inline bool match_input (hb_ot_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 843 | unsigned int count, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 844 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 845 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 846 | const void *match_data, |
Behdad Esfahbod | 6cc136f | 2013-10-17 13:55:48 +0200 | [diff] [blame] | 847 | unsigned int *end_offset, |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 848 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 849 | unsigned int *p_total_component_count = nullptr) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 850 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 851 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 852 | |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 853 | if (unlikely (count > HB_MAX_CONTEXT_LENGTH)) return_trace (false); |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 854 | |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 855 | hb_buffer_t *buffer = c->buffer; |
| 856 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 857 | hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input; |
Behdad Esfahbod | b051be5 | 2015-01-29 13:40:39 +0100 | [diff] [blame] | 858 | skippy_iter.reset (buffer->idx, count - 1); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 859 | skippy_iter.set_match_func (match_func, match_data, input); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 860 | |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 861 | /* |
| 862 | * This is perhaps the trickiest part of OpenType... Remarks: |
| 863 | * |
| 864 | * - If all components of the ligature were marks, we call this a mark ligature. |
| 865 | * |
| 866 | * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize |
| 867 | * it as a ligature glyph. |
| 868 | * |
| 869 | * - Ligatures cannot be formed across glyphs attached to different components |
| 870 | * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and |
| 871 | * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother. |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 872 | * However, it would be wrong to ligate that SHADDA,FATHA sequence. |
| 873 | * There are a couple of exceptions to this: |
| 874 | * |
| 875 | * o If a ligature tries ligating with marks that belong to it itself, go ahead, |
| 876 | * assuming that the font designer knows what they are doing (otherwise it can |
| 877 | * break Indic stuff when a matra wants to ligate with a conjunct, |
| 878 | * |
| 879 | * o If two marks want to ligate and they belong to different components of the |
| 880 | * same ligature glyph, and said ligature glyph is to be ignored according to |
| 881 | * mark-filtering rules, then allow. |
ebraminio | 7c6937e | 2017-11-20 14:49:22 -0500 | [diff] [blame] | 882 | * https://github.com/harfbuzz/harfbuzz/issues/545 |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 883 | */ |
| 884 | |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 885 | unsigned int total_component_count = 0; |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 886 | total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->cur()); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 887 | |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 888 | unsigned int first_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); |
| 889 | unsigned int first_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->cur()); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 890 | |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 891 | enum { |
| 892 | LIGBASE_NOT_CHECKED, |
| 893 | LIGBASE_MAY_NOT_SKIP, |
| 894 | LIGBASE_MAY_SKIP |
| 895 | } ligbase = LIGBASE_NOT_CHECKED; |
| 896 | |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 897 | match_positions[0] = buffer->idx; |
Behdad Esfahbod | 370f03e | 2012-01-16 17:03:55 -0500 | [diff] [blame] | 898 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 899 | { |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 900 | if (!skippy_iter.next ()) return_trace (false); |
Behdad Esfahbod | 6cc136f | 2013-10-17 13:55:48 +0200 | [diff] [blame] | 901 | |
| 902 | match_positions[i] = skippy_iter.idx; |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 903 | |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 904 | unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]); |
| 905 | unsigned int this_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 906 | |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 907 | if (first_lig_id && first_lig_comp) |
| 908 | { |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 909 | /* If first component was attached to a previous ligature component, |
| 910 | * all subsequent components should be attached to the same ligature |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 911 | * component, otherwise we shouldn't ligate them... */ |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 912 | if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp) |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 913 | { |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 914 | /* ...unless, we are attached to a base ligature and that base |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 915 | * ligature is ignorable. */ |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 916 | if (ligbase == LIGBASE_NOT_CHECKED) |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 917 | { |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 918 | bool found = false; |
Behdad Esfahbod | 4d67743 | 2019-05-10 16:35:31 -0700 | [diff] [blame] | 919 | const auto *out = buffer->out_info; |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 920 | unsigned int j = buffer->out_len; |
| 921 | while (j && _hb_glyph_info_get_lig_id (&out[j - 1]) == first_lig_id) |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 922 | { |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 923 | if (_hb_glyph_info_get_lig_comp (&out[j - 1]) == 0) |
| 924 | { |
| 925 | j--; |
| 926 | found = true; |
| 927 | break; |
| 928 | } |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 929 | j--; |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 930 | } |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 931 | |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 932 | if (found && skippy_iter.may_skip (out[j]) == hb_ot_apply_context_t::matcher_t::SKIP_YES) |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 933 | ligbase = LIGBASE_MAY_SKIP; |
| 934 | else |
| 935 | ligbase = LIGBASE_MAY_NOT_SKIP; |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 936 | } |
| 937 | |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 938 | if (ligbase == LIGBASE_MAY_NOT_SKIP) |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 939 | return_trace (false); |
| 940 | } |
| 941 | } |
| 942 | else |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 943 | { |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 944 | /* If first component was NOT attached to a previous ligature component, |
| 945 | * all subsequent components should also NOT be attached to any ligature |
| 946 | * component, unless they are attached to the first component itself! */ |
| 947 | if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 948 | return_trace (false); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 949 | } |
| 950 | |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 951 | total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->info[skippy_iter.idx]); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 954 | *end_offset = skippy_iter.idx - buffer->idx + 1; |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 955 | |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 956 | if (p_total_component_count) |
| 957 | *p_total_component_count = total_component_count; |
| 958 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 959 | return_trace (true); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 960 | } |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 961 | static inline bool ligate_input (hb_ot_apply_context_t *c, |
Behdad Esfahbod | e714fe6 | 2013-10-17 13:49:51 +0200 | [diff] [blame] | 962 | unsigned int count, /* Including the first glyph */ |
Bruce Mitchener | 5a24ea1 | 2018-10-20 08:09:52 +0700 | [diff] [blame] | 963 | const unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */ |
Behdad Esfahbod | e714fe6 | 2013-10-17 13:49:51 +0200 | [diff] [blame] | 964 | unsigned int match_length, |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 965 | hb_codepoint_t lig_glyph, |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 966 | unsigned int total_component_count) |
| 967 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 968 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | e714fe6 | 2013-10-17 13:49:51 +0200 | [diff] [blame] | 969 | |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 970 | hb_buffer_t *buffer = c->buffer; |
| 971 | |
| 972 | buffer->merge_clusters (buffer->idx, buffer->idx + match_length); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 973 | |
Behdad Esfahbod | 9efddb9 | 2018-10-02 16:05:26 +0200 | [diff] [blame] | 974 | /* - If a base and one or more marks ligate, consider that as a base, NOT |
| 975 | * ligature, such that all following marks can still attach to it. |
| 976 | * https://github.com/harfbuzz/harfbuzz/issues/1109 |
| 977 | * |
| 978 | * - If all components of the ligature were marks, we call this a mark ligature. |
Behdad Esfahbod | 3cca978 | 2018-10-02 15:02:16 +0200 | [diff] [blame] | 979 | * If it *is* a mark ligature, we don't allocate a new ligature id, and leave |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 980 | * the ligature to keep its old ligature id. This will allow it to attach to |
| 981 | * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH, |
Behdad Esfahbod | 3cca978 | 2018-10-02 15:02:16 +0200 | [diff] [blame] | 982 | * and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA with a |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 983 | * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature |
| 984 | * later, we don't want them to lose their ligature id/component, otherwise |
| 985 | * GPOS will fail to correctly position the mark ligature on top of the |
| 986 | * LAM,LAM,HEH ligature. See: |
| 987 | * https://bugzilla.gnome.org/show_bug.cgi?id=676343 |
| 988 | * |
| 989 | * - If a ligature is formed of components that some of which are also ligatures |
| 990 | * themselves, and those ligature components had marks attached to *their* |
| 991 | * components, we have to attach the marks to the new ligature component |
| 992 | * positions! Now *that*'s tricky! And these marks may be following the |
| 993 | * last component of the whole sequence, so we should loop forward looking |
| 994 | * for them and update them. |
| 995 | * |
| 996 | * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a |
| 997 | * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature |
| 998 | * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature |
| 999 | * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to |
| 1000 | * the new ligature with a component value of 2. |
| 1001 | * |
| 1002 | * This in fact happened to a font... See: |
| 1003 | * https://bugzilla.gnome.org/show_bug.cgi?id=437633 |
| 1004 | */ |
| 1005 | |
Behdad Esfahbod | 9efddb9 | 2018-10-02 16:05:26 +0200 | [diff] [blame] | 1006 | bool is_base_ligature = _hb_glyph_info_is_base_glyph (&buffer->info[match_positions[0]]); |
| 1007 | bool is_mark_ligature = _hb_glyph_info_is_mark (&buffer->info[match_positions[0]]); |
| 1008 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 3cca978 | 2018-10-02 15:02:16 +0200 | [diff] [blame] | 1009 | if (!_hb_glyph_info_is_mark (&buffer->info[match_positions[i]])) |
| 1010 | { |
Behdad Esfahbod | 9efddb9 | 2018-10-02 16:05:26 +0200 | [diff] [blame] | 1011 | is_base_ligature = false; |
Behdad Esfahbod | 3cca978 | 2018-10-02 15:02:16 +0200 | [diff] [blame] | 1012 | is_mark_ligature = false; |
| 1013 | break; |
| 1014 | } |
Behdad Esfahbod | 9efddb9 | 2018-10-02 16:05:26 +0200 | [diff] [blame] | 1015 | bool is_ligature = !is_base_ligature && !is_mark_ligature; |
Behdad Esfahbod | 3cca978 | 2018-10-02 15:02:16 +0200 | [diff] [blame] | 1016 | |
Behdad Esfahbod | 9efddb9 | 2018-10-02 16:05:26 +0200 | [diff] [blame] | 1017 | unsigned int klass = is_ligature ? HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE : 0; |
| 1018 | unsigned int lig_id = is_ligature ? _hb_allocate_lig_id (buffer) : 0; |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 1019 | unsigned int last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); |
| 1020 | unsigned int last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur()); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1021 | unsigned int components_so_far = last_num_components; |
| 1022 | |
Behdad Esfahbod | 9efddb9 | 2018-10-02 16:05:26 +0200 | [diff] [blame] | 1023 | if (is_ligature) |
Behdad Esfahbod | 7e08f12 | 2013-05-27 14:48:34 -0400 | [diff] [blame] | 1024 | { |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 1025 | _hb_glyph_info_set_lig_props_for_ligature (&buffer->cur(), lig_id, total_component_count); |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 1026 | if (_hb_glyph_info_get_general_category (&buffer->cur()) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) |
Behdad Esfahbod | 3d436d3 | 2013-10-28 21:00:37 +0100 | [diff] [blame] | 1027 | { |
Behdad Esfahbod | 8259669 | 2015-11-02 17:44:05 -0800 | [diff] [blame] | 1028 | _hb_glyph_info_set_general_category (&buffer->cur(), HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER); |
Behdad Esfahbod | 3d436d3 | 2013-10-28 21:00:37 +0100 | [diff] [blame] | 1029 | } |
Behdad Esfahbod | 7e08f12 | 2013-05-27 14:48:34 -0400 | [diff] [blame] | 1030 | } |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 1031 | c->replace_glyph_with_ligature (lig_glyph, klass); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1032 | |
| 1033 | for (unsigned int i = 1; i < count; i++) |
| 1034 | { |
Behdad Esfahbod | 7185b27 | 2018-05-31 20:03:00 -0700 | [diff] [blame] | 1035 | while (buffer->idx < match_positions[i] && buffer->successful) |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1036 | { |
Behdad Esfahbod | 9efddb9 | 2018-10-02 16:05:26 +0200 | [diff] [blame] | 1037 | if (is_ligature) |
| 1038 | { |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 1039 | unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->cur()); |
Behdad Esfahbod | 2f02fc7 | 2015-12-17 15:21:14 +0000 | [diff] [blame] | 1040 | if (this_comp == 0) |
Behdad Esfahbod | 100fbea | 2015-12-17 15:23:09 +0000 | [diff] [blame] | 1041 | this_comp = last_num_components; |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1042 | unsigned int new_lig_comp = components_so_far - last_num_components + |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 1043 | hb_min (this_comp, last_num_components); |
Behdad Esfahbod | 2f02fc7 | 2015-12-17 15:21:14 +0000 | [diff] [blame] | 1044 | _hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1045 | } |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 1046 | buffer->next_glyph (); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 1049 | last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); |
| 1050 | last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur()); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1051 | components_so_far += last_num_components; |
| 1052 | |
| 1053 | /* Skip the base glyph */ |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 1054 | buffer->idx++; |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
Ebrahim Byagowi | cc977b6 | 2020-03-26 11:18:02 +0430 | [diff] [blame] | 1057 | if (!is_mark_ligature && last_lig_id) |
| 1058 | { |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1059 | /* Re-adjust components for any marks following. */ |
Ebrahim Byagowi | cc977b6 | 2020-03-26 11:18:02 +0430 | [diff] [blame] | 1060 | for (unsigned i = buffer->idx; i < buffer->len; ++i) |
| 1061 | { |
| 1062 | if (last_lig_id != _hb_glyph_info_get_lig_id (&buffer->info[i])) break; |
| 1063 | |
| 1064 | unsigned this_comp = _hb_glyph_info_get_lig_comp (&buffer->info[i]); |
| 1065 | if (!this_comp) break; |
| 1066 | |
| 1067 | unsigned new_lig_comp = components_so_far - last_num_components + |
| 1068 | hb_min (this_comp, last_num_components); |
| 1069 | _hb_glyph_info_set_lig_props_for_mark (&buffer->info[i], lig_id, new_lig_comp); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1070 | } |
| 1071 | } |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1072 | return_trace (true); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 1073 | } |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1074 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1075 | static inline bool match_backtrack (hb_ot_apply_context_t *c, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1076 | unsigned int count, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1077 | const HBUINT16 backtrack[], |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1078 | match_func_t match_func, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1079 | const void *match_data, |
| 1080 | unsigned int *match_start) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1081 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1082 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 1083 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1084 | hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context; |
Behdad Esfahbod | b051be5 | 2015-01-29 13:40:39 +0100 | [diff] [blame] | 1085 | skippy_iter.reset (c->buffer->backtrack_len (), count); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 1086 | skippy_iter.set_match_func (match_func, match_data, backtrack); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1087 | |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame] | 1088 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 1089 | if (!skippy_iter.prev ()) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1090 | return_trace (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1091 | |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1092 | *match_start = skippy_iter.idx; |
| 1093 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1094 | return_trace (true); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1097 | static inline bool match_lookahead (hb_ot_apply_context_t *c, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1098 | unsigned int count, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1099 | const HBUINT16 lookahead[], |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1100 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1101 | const void *match_data, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1102 | unsigned int offset, |
| 1103 | unsigned int *end_index) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1104 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1105 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 1106 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1107 | hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context; |
Behdad Esfahbod | b051be5 | 2015-01-29 13:40:39 +0100 | [diff] [blame] | 1108 | skippy_iter.reset (c->buffer->idx + offset - 1, count); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 1109 | skippy_iter.set_match_func (match_func, match_data, lookahead); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1110 | |
Behdad Esfahbod | 370f03e | 2012-01-16 17:03:55 -0500 | [diff] [blame] | 1111 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 1112 | if (!skippy_iter.next ()) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1113 | return_trace (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 1114 | |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1115 | *end_index = skippy_iter.idx + 1; |
| 1116 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1117 | return_trace (true); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1118 | } |
| 1119 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1120 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1121 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1122 | struct LookupRecord |
| 1123 | { |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1124 | LookupRecord* copy (hb_serialize_context_t *c, |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1125 | const hb_map_t *lookup_map) const |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1126 | { |
| 1127 | TRACE_SERIALIZE (this); |
| 1128 | auto *out = c->embed (*this); |
| 1129 | if (unlikely (!out)) return_trace (nullptr); |
| 1130 | |
| 1131 | out->lookupListIndex = hb_map_get (lookup_map, lookupListIndex); |
| 1132 | return_trace (out); |
| 1133 | } |
| 1134 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1135 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1136 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1137 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1138 | return_trace (c->check_struct (this)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 1139 | } |
| 1140 | |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1141 | HBUINT16 sequenceIndex; /* Index into current glyph |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1142 | * sequence--first glyph = 0 */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1143 | HBUINT16 lookupListIndex; /* Lookup to apply to that |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1144 | * position--zero--based */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 1145 | public: |
| 1146 | DEFINE_SIZE_STATIC (4); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1147 | }; |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1148 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1149 | template <typename context_t> |
| 1150 | static inline void recurse_lookups (context_t *c, |
| 1151 | unsigned int lookupCount, |
| 1152 | const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */) |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1153 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1154 | for (unsigned int i = 0; i < lookupCount; i++) |
Behdad Esfahbod | 86522e4 | 2013-07-22 19:07:53 -0400 | [diff] [blame] | 1155 | c->recurse (lookupRecord[i].lookupListIndex); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1156 | } |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1157 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1158 | static inline bool apply_lookup (hb_ot_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 1159 | unsigned int count, /* Including the first glyph */ |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 1160 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */ |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 1161 | unsigned int lookupCount, |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1162 | const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ |
| 1163 | unsigned int match_length) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1164 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1165 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | 902cc8a | 2012-11-23 15:06:59 -0500 | [diff] [blame] | 1166 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1167 | hb_buffer_t *buffer = c->buffer; |
jfkthame | 44f7d6e | 2017-02-17 03:03:24 +0000 | [diff] [blame] | 1168 | int end; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1169 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1170 | /* All positions are distance from beginning of *output* buffer. |
| 1171 | * Adjust. */ |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1172 | { |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1173 | unsigned int bl = buffer->backtrack_len (); |
| 1174 | end = bl + match_length; |
Behdad Esfahbod | 8751de5 | 2013-07-18 16:29:50 -0400 | [diff] [blame] | 1175 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1176 | int delta = bl - buffer->idx; |
| 1177 | /* Convert positions to new indexing. */ |
| 1178 | for (unsigned int j = 0; j < count; j++) |
| 1179 | match_positions[j] += delta; |
Behdad Esfahbod | 8820bb2 | 2013-02-14 07:41:03 -0500 | [diff] [blame] | 1180 | } |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 1181 | |
Behdad Esfahbod | 7185b27 | 2018-05-31 20:03:00 -0700 | [diff] [blame] | 1182 | for (unsigned int i = 0; i < lookupCount && buffer->successful; i++) |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1183 | { |
| 1184 | unsigned int idx = lookupRecord[i].sequenceIndex; |
| 1185 | if (idx >= count) |
| 1186 | continue; |
| 1187 | |
Behdad Esfahbod | 9cc1ed4 | 2015-11-19 12:39:09 -0800 | [diff] [blame] | 1188 | /* Don't recurse to ourself at same position. |
| 1189 | * Note that this test is too naive, it doesn't catch longer loops. */ |
| 1190 | if (idx == 0 && lookupRecord[i].lookupListIndex == c->lookup_index) |
| 1191 | continue; |
| 1192 | |
Behdad Esfahbod | e593072 | 2017-11-14 15:47:55 -0800 | [diff] [blame] | 1193 | if (unlikely (!buffer->move_to (match_positions[idx]))) |
| 1194 | break; |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1195 | |
Behdad Esfahbod | baf7779 | 2017-11-14 21:53:48 -0800 | [diff] [blame] | 1196 | if (unlikely (buffer->max_ops <= 0)) |
| 1197 | break; |
| 1198 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1199 | unsigned int orig_len = buffer->backtrack_len () + buffer->lookahead_len (); |
| 1200 | if (!c->recurse (lookupRecord[i].lookupListIndex)) |
| 1201 | continue; |
| 1202 | |
| 1203 | unsigned int new_len = buffer->backtrack_len () + buffer->lookahead_len (); |
| 1204 | int delta = new_len - orig_len; |
| 1205 | |
| 1206 | if (!delta) |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 1207 | continue; |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1208 | |
Behdad Esfahbod | 9ac9af7 | 2017-03-05 13:51:01 -0800 | [diff] [blame] | 1209 | /* Recursed lookup changed buffer len. Adjust. |
| 1210 | * |
| 1211 | * TODO: |
| 1212 | * |
| 1213 | * Right now, if buffer length increased by n, we assume n new glyphs |
| 1214 | * were added right after the current position, and if buffer length |
| 1215 | * was decreased by n, we assume n match positions after the current |
| 1216 | * one where removed. The former (buffer length increased) case is |
| 1217 | * fine, but the decrease case can be improved in at least two ways, |
| 1218 | * both of which are significant: |
| 1219 | * |
| 1220 | * - If recursed-to lookup is MultipleSubst and buffer length |
| 1221 | * decreased, then it's current match position that was deleted, |
| 1222 | * NOT the one after it. |
| 1223 | * |
| 1224 | * - If buffer length was decreased by n, it does not necessarily |
| 1225 | * mean that n match positions where removed, as there might |
| 1226 | * have been marks and default-ignorables in the sequence. We |
| 1227 | * should instead drop match positions between current-position |
| 1228 | * and current-position + n instead. |
| 1229 | * |
| 1230 | * It should be possible to construct tests for both of these cases. |
| 1231 | */ |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1232 | |
jfkthame | 44f7d6e | 2017-02-17 03:03:24 +0000 | [diff] [blame] | 1233 | end += delta; |
Behdad Esfahbod | 47e7a18 | 2017-03-10 13:23:02 -0800 | [diff] [blame] | 1234 | if (end <= int (match_positions[idx])) |
Behdad Esfahbod | 359dead | 2016-05-06 16:19:19 +0100 | [diff] [blame] | 1235 | { |
Behdad Esfahbod | 4b4a1b9 | 2016-12-21 23:10:43 -0600 | [diff] [blame] | 1236 | /* End might end up being smaller than match_positions[idx] if the recursed |
Behdad Esfahbod | 47e7a18 | 2017-03-10 13:23:02 -0800 | [diff] [blame] | 1237 | * lookup ended up removing many items, more than we have had matched. |
Behdad Esfahbod | 4b4a1b9 | 2016-12-21 23:10:43 -0600 | [diff] [blame] | 1238 | * Just never rewind end back and get out of here. |
| 1239 | * https://bugs.chromium.org/p/chromium/issues/detail?id=659496 */ |
| 1240 | end = match_positions[idx]; |
Behdad Esfahbod | 47e7a18 | 2017-03-10 13:23:02 -0800 | [diff] [blame] | 1241 | /* There can't be any further changes. */ |
Behdad Esfahbod | 359dead | 2016-05-06 16:19:19 +0100 | [diff] [blame] | 1242 | break; |
| 1243 | } |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1244 | |
| 1245 | unsigned int next = idx + 1; /* next now is the position after the recursed lookup. */ |
| 1246 | |
| 1247 | if (delta > 0) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1248 | { |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 1249 | if (unlikely (delta + count > HB_MAX_CONTEXT_LENGTH)) |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1250 | break; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1251 | } |
| 1252 | else |
| 1253 | { |
Behdad Esfahbod | 47e7a18 | 2017-03-10 13:23:02 -0800 | [diff] [blame] | 1254 | /* NOTE: delta is negative. */ |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 1255 | delta = hb_max (delta, (int) next - (int) count); |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1256 | next -= delta; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1257 | } |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1258 | |
| 1259 | /* Shift! */ |
| 1260 | memmove (match_positions + next + delta, match_positions + next, |
| 1261 | (count - next) * sizeof (match_positions[0])); |
| 1262 | next += delta; |
| 1263 | count += delta; |
| 1264 | |
| 1265 | /* Fill in new entries. */ |
| 1266 | for (unsigned int j = idx + 1; j < next; j++) |
| 1267 | match_positions[j] = match_positions[j - 1] + 1; |
| 1268 | |
| 1269 | /* And fixup the rest. */ |
| 1270 | for (; next < count; next++) |
| 1271 | match_positions[next] += delta; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1274 | buffer->move_to (end); |
| 1275 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1276 | return_trace (true); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1277 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1278 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1279 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1280 | |
| 1281 | /* Contextual lookups */ |
| 1282 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1283 | struct ContextClosureLookupContext |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1284 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1285 | ContextClosureFuncs funcs; |
| 1286 | const void *intersects_data; |
| 1287 | }; |
| 1288 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1289 | struct ContextCollectGlyphsLookupContext |
| 1290 | { |
| 1291 | ContextCollectGlyphsFuncs funcs; |
| 1292 | const void *collect_data; |
| 1293 | }; |
| 1294 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1295 | struct ContextApplyLookupContext |
| 1296 | { |
| 1297 | ContextApplyFuncs funcs; |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1298 | const void *match_data; |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1299 | }; |
| 1300 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1301 | static inline bool context_intersects (const hb_set_t *glyphs, |
| 1302 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 1303 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
| 1304 | ContextClosureLookupContext &lookup_context) |
| 1305 | { |
Qunxin Liu | 44d88cf | 2020-05-08 15:33:34 -0700 | [diff] [blame] | 1306 | return array_is_subset_of (glyphs, |
| 1307 | inputCount ? inputCount - 1 : 0, input, |
| 1308 | lookup_context.funcs.intersects, lookup_context.intersects_data); |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1311 | static inline void context_closure_lookup (hb_closure_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1312 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1313 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1314 | unsigned int lookupCount, |
| 1315 | const LookupRecord lookupRecord[], |
| 1316 | ContextClosureLookupContext &lookup_context) |
| 1317 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1318 | if (context_intersects (c->glyphs, |
| 1319 | inputCount, input, |
| 1320 | lookup_context)) |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1321 | recurse_lookups (c, |
| 1322 | lookupCount, lookupRecord); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1323 | } |
| 1324 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1325 | static inline void context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c, |
| 1326 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1327 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1328 | unsigned int lookupCount, |
| 1329 | const LookupRecord lookupRecord[], |
| 1330 | ContextCollectGlyphsLookupContext &lookup_context) |
| 1331 | { |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1332 | collect_array (c, c->input, |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1333 | inputCount ? inputCount - 1 : 0, input, |
| 1334 | lookup_context.funcs.collect, lookup_context.collect_data); |
| 1335 | recurse_lookups (c, |
| 1336 | lookupCount, lookupRecord); |
| 1337 | } |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1338 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1339 | static inline bool context_would_apply_lookup (hb_would_apply_context_t *c, |
| 1340 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1341 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 1342 | unsigned int lookupCount HB_UNUSED, |
| 1343 | const LookupRecord lookupRecord[] HB_UNUSED, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1344 | ContextApplyLookupContext &lookup_context) |
| 1345 | { |
| 1346 | return would_match_input (c, |
| 1347 | inputCount, input, |
| 1348 | lookup_context.funcs.match, lookup_context.match_data); |
| 1349 | } |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1350 | static inline bool context_apply_lookup (hb_ot_apply_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1351 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1352 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1353 | unsigned int lookupCount, |
| 1354 | const LookupRecord lookupRecord[], |
| 1355 | ContextApplyLookupContext &lookup_context) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1356 | { |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1357 | unsigned int match_length = 0; |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 1358 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH]; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1359 | return match_input (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 1360 | inputCount, input, |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1361 | lookup_context.funcs.match, lookup_context.match_data, |
| 1362 | &match_length, match_positions) |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1363 | && (c->buffer->unsafe_to_break (c->buffer->idx, c->buffer->idx + match_length), |
| 1364 | apply_lookup (c, |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1365 | inputCount, match_positions, |
| 1366 | lookupCount, lookupRecord, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1367 | match_length)); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1368 | } |
| 1369 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1370 | struct Rule |
| 1371 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1372 | bool intersects (const hb_set_t *glyphs, ContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1373 | { |
| 1374 | return context_intersects (glyphs, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1375 | inputCount, inputZ.arrayZ, |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1376 | lookup_context); |
| 1377 | } |
| 1378 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1379 | void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1380 | { |
Ebrahim Byagowi | 0c65a23 | 2020-04-23 11:23:54 +0430 | [diff] [blame] | 1381 | if (unlikely (c->lookup_limit_exceeded ())) return; |
Garret Rieger | 014e038 | 2020-03-31 16:29:29 -0700 | [diff] [blame] | 1382 | |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 1383 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAfter<UnsizedArrayOf<LookupRecord>> |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 1384 | (inputZ.as_array ((inputCount ? inputCount - 1 : 0))); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1385 | context_closure_lookup (c, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1386 | inputCount, inputZ.arrayZ, |
| 1387 | lookupCount, lookupRecord.arrayZ, |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1388 | lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1389 | } |
| 1390 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1391 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 1392 | { |
Ebrahim Byagowi | 0c65a23 | 2020-04-23 11:23:54 +0430 | [diff] [blame] | 1393 | if (unlikely (c->lookup_limit_exceeded ())) return; |
Garret Rieger | 014e038 | 2020-03-31 16:29:29 -0700 | [diff] [blame] | 1394 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1395 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAfter<UnsizedArrayOf<LookupRecord>> |
| 1396 | (inputZ.as_array (inputCount ? inputCount - 1 : 0)); |
| 1397 | recurse_lookups (c, lookupCount, lookupRecord.arrayZ); |
| 1398 | } |
| 1399 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1400 | void collect_glyphs (hb_collect_glyphs_context_t *c, |
| 1401 | ContextCollectGlyphsLookupContext &lookup_context) const |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1402 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 1403 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAfter<UnsizedArrayOf<LookupRecord>> |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 1404 | (inputZ.as_array (inputCount ? inputCount - 1 : 0)); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1405 | context_collect_glyphs_lookup (c, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1406 | inputCount, inputZ.arrayZ, |
| 1407 | lookupCount, lookupRecord.arrayZ, |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1408 | lookup_context); |
| 1409 | } |
| 1410 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1411 | bool would_apply (hb_would_apply_context_t *c, |
| 1412 | ContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1413 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 1414 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAfter<UnsizedArrayOf<LookupRecord>> |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 1415 | (inputZ.as_array (inputCount ? inputCount - 1 : 0)); |
Behdad Esfahbod | 90b60bd | 2019-03-29 22:12:42 -0700 | [diff] [blame] | 1416 | return context_would_apply_lookup (c, |
| 1417 | inputCount, inputZ.arrayZ, |
| 1418 | lookupCount, lookupRecord.arrayZ, |
| 1419 | lookup_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1420 | } |
| 1421 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1422 | bool apply (hb_ot_apply_context_t *c, |
| 1423 | ContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1424 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1425 | TRACE_APPLY (this); |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 1426 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAfter<UnsizedArrayOf<LookupRecord>> |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 1427 | (inputZ.as_array (inputCount ? inputCount - 1 : 0)); |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1428 | return_trace (context_apply_lookup (c, inputCount, inputZ.arrayZ, lookupCount, lookupRecord.arrayZ, lookup_context)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1429 | } |
| 1430 | |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1431 | bool serialize (hb_serialize_context_t *c, |
| 1432 | const hb_map_t *input_mapping, /* old->new glyphid or class mapping */ |
| 1433 | const hb_map_t *lookup_map) const |
| 1434 | { |
| 1435 | TRACE_SERIALIZE (this); |
| 1436 | auto *out = c->start_embed (this); |
| 1437 | if (unlikely (!c->extend_min (out))) return_trace (false); |
| 1438 | |
| 1439 | out->inputCount = inputCount; |
| 1440 | out->lookupCount = lookupCount; |
| 1441 | |
| 1442 | const hb_array_t<const HBUINT16> input = inputZ.as_array (inputCount - 1); |
| 1443 | for (const auto org : input) |
| 1444 | { |
| 1445 | HBUINT16 d; |
| 1446 | d = input_mapping->get (org); |
| 1447 | c->copy (d); |
| 1448 | } |
| 1449 | |
| 1450 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAfter<UnsizedArrayOf<LookupRecord>> |
Ebrahim Byagowi | 5a7cc7f | 2020-07-29 08:33:32 +0430 | [diff] [blame] | 1451 | (inputZ.as_array ((inputCount ? inputCount - 1 : 0))); |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1452 | for (unsigned i = 0; i < (unsigned) lookupCount; i++) |
| 1453 | c->copy (lookupRecord[i], lookup_map); |
| 1454 | |
| 1455 | return_trace (true); |
| 1456 | } |
| 1457 | |
| 1458 | bool subset (hb_subset_context_t *c, |
| 1459 | const hb_map_t *lookup_map, |
| 1460 | const hb_map_t *klass_map = nullptr) const |
| 1461 | { |
| 1462 | TRACE_SUBSET (this); |
| 1463 | |
| 1464 | const hb_array_t<const HBUINT16> input = inputZ.as_array ((inputCount ? inputCount - 1 : 0)); |
| 1465 | if (!input.length) return_trace (false); |
| 1466 | |
| 1467 | const hb_map_t *mapping = klass_map == nullptr ? c->plan->glyph_map : klass_map; |
| 1468 | if (!hb_all (input, mapping)) return_trace (false); |
| 1469 | return_trace (serialize (c->serializer, mapping, lookup_map)); |
| 1470 | } |
| 1471 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1472 | public: |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1473 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1474 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1475 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 5aad819 | 2017-11-03 17:16:26 -0400 | [diff] [blame] | 1476 | return_trace (inputCount.sanitize (c) && |
| 1477 | lookupCount.sanitize (c) && |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1478 | c->check_range (inputZ.arrayZ, |
Behdad Esfahbod | 9c6921c | 2018-11-30 15:16:57 -0500 | [diff] [blame] | 1479 | inputZ.item_size * (inputCount ? inputCount - 1 : 0) + |
Behdad Esfahbod | 6d7c6e1 | 2018-02-07 14:09:56 -0600 | [diff] [blame] | 1480 | LookupRecord::static_size * lookupCount)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1481 | } |
| 1482 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1483 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1484 | HBUINT16 inputCount; /* Total number of glyphs in input |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1485 | * glyph sequence--includes the first |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1486 | * glyph */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1487 | HBUINT16 lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1488 | UnsizedArrayOf<HBUINT16> |
Ebrahim Byagowi | ce114d6 | 2019-12-31 15:53:02 +0330 | [diff] [blame] | 1489 | inputZ; /* Array of match inputs--start with |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1490 | * second glyph */ |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1491 | /*UnsizedArrayOf<LookupRecord> |
| 1492 | lookupRecordX;*/ /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1493 | * design order */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 1494 | public: |
Behdad Esfahbod | 6d7c6e1 | 2018-02-07 14:09:56 -0600 | [diff] [blame] | 1495 | DEFINE_SIZE_ARRAY (4, inputZ); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1496 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1497 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1498 | struct RuleSet |
| 1499 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1500 | bool intersects (const hb_set_t *glyphs, |
| 1501 | ContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1502 | { |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1503 | return |
| 1504 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1505 | | hb_map (hb_add (this)) |
| 1506 | | hb_map ([&] (const Rule &_) { return _.intersects (glyphs, lookup_context); }) |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1507 | | hb_any |
| 1508 | ; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1511 | void closure (hb_closure_context_t *c, |
| 1512 | ContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1513 | { |
Ebrahim Byagowi | 0c65a23 | 2020-04-23 11:23:54 +0430 | [diff] [blame] | 1514 | if (unlikely (c->lookup_limit_exceeded ())) return; |
Garret Rieger | 014e038 | 2020-03-31 16:29:29 -0700 | [diff] [blame] | 1515 | |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1516 | return |
| 1517 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1518 | | hb_map (hb_add (this)) |
| 1519 | | hb_apply ([&] (const Rule &_) { _.closure (c, lookup_context); }) |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1520 | ; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1521 | } |
| 1522 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1523 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 1524 | { |
Ebrahim Byagowi | 0c65a23 | 2020-04-23 11:23:54 +0430 | [diff] [blame] | 1525 | if (unlikely (c->lookup_limit_exceeded ())) return; |
Garret Rieger | 014e038 | 2020-03-31 16:29:29 -0700 | [diff] [blame] | 1526 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1527 | return |
| 1528 | + hb_iter (rule) |
| 1529 | | hb_map (hb_add (this)) |
| 1530 | | hb_apply ([&] (const Rule &_) { _.closure_lookups (c); }) |
| 1531 | ; |
| 1532 | } |
| 1533 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1534 | void collect_glyphs (hb_collect_glyphs_context_t *c, |
| 1535 | ContextCollectGlyphsLookupContext &lookup_context) const |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1536 | { |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1537 | return |
| 1538 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1539 | | hb_map (hb_add (this)) |
| 1540 | | hb_apply ([&] (const Rule &_) { _.collect_glyphs (c, lookup_context); }) |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1541 | ; |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1542 | } |
| 1543 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1544 | bool would_apply (hb_would_apply_context_t *c, |
| 1545 | ContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1546 | { |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1547 | return |
| 1548 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1549 | | hb_map (hb_add (this)) |
| 1550 | | hb_map ([&] (const Rule &_) { return _.would_apply (c, lookup_context); }) |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1551 | | hb_any |
| 1552 | ; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1555 | bool apply (hb_ot_apply_context_t *c, |
| 1556 | ContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1557 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1558 | TRACE_APPLY (this); |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1559 | return_trace ( |
| 1560 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1561 | | hb_map (hb_add (this)) |
| 1562 | | hb_map ([&] (const Rule &_) { return _.apply (c, lookup_context); }) |
Behdad Esfahbod | 22ec4c3 | 2019-03-29 22:27:46 -0700 | [diff] [blame] | 1563 | | hb_any |
| 1564 | ) |
| 1565 | ; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1566 | } |
| 1567 | |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1568 | bool subset (hb_subset_context_t *c, |
| 1569 | const hb_map_t *lookup_map, |
| 1570 | const hb_map_t *klass_map = nullptr) const |
| 1571 | { |
| 1572 | TRACE_SUBSET (this); |
| 1573 | |
| 1574 | auto snap = c->serializer->snapshot (); |
| 1575 | auto *out = c->serializer->start_embed (*this); |
| 1576 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
| 1577 | |
| 1578 | for (const OffsetTo<Rule>& _ : rule) |
| 1579 | { |
| 1580 | if (!_) continue; |
| 1581 | auto *o = out->rule.serialize_append (c->serializer); |
| 1582 | if (unlikely (!o)) continue; |
| 1583 | |
| 1584 | auto o_snap = c->serializer->snapshot (); |
| 1585 | if (!o->serialize_subset (c, _, this, lookup_map, klass_map)) |
| 1586 | { |
Ebrahim Byagowi | 5a7cc7f | 2020-07-29 08:33:32 +0430 | [diff] [blame] | 1587 | out->rule.pop (); |
| 1588 | c->serializer->revert (o_snap); |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | bool ret = bool (out->rule); |
| 1593 | if (!ret) c->serializer->revert (snap); |
| 1594 | |
| 1595 | return_trace (ret); |
| 1596 | } |
| 1597 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1598 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1599 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1600 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1601 | return_trace (rule.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1602 | } |
| 1603 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1604 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1605 | OffsetArrayOf<Rule> |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1606 | rule; /* Array of Rule tables |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1607 | * ordered by preference */ |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 1608 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1609 | DEFINE_SIZE_ARRAY (2, rule); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1610 | }; |
| 1611 | |
| 1612 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1613 | struct ContextFormat1 |
| 1614 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1615 | bool intersects (const hb_set_t *glyphs) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1616 | { |
| 1617 | struct ContextClosureLookupContext lookup_context = { |
| 1618 | {intersects_glyph}, |
| 1619 | nullptr |
| 1620 | }; |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 1621 | |
| 1622 | return |
| 1623 | + hb_zip (this+coverage, ruleSet) |
| 1624 | | hb_filter (*glyphs, hb_first) |
| 1625 | | hb_map (hb_second) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1626 | | hb_map (hb_add (this)) |
| 1627 | | hb_map ([&] (const RuleSet &_) { return _.intersects (glyphs, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 1628 | | hb_any |
| 1629 | ; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1632 | void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1633 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1634 | struct ContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1635 | {intersects_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1636 | nullptr |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1637 | }; |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 1638 | |
| 1639 | + hb_zip (this+coverage, ruleSet) |
| 1640 | | hb_filter (*c->glyphs, hb_first) |
| 1641 | | hb_map (hb_second) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1642 | | hb_map (hb_add (this)) |
| 1643 | | hb_apply ([&] (const RuleSet &_) { _.closure (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 1644 | ; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1645 | } |
| 1646 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1647 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 1648 | { |
| 1649 | + hb_iter (ruleSet) |
| 1650 | | hb_map (hb_add (this)) |
| 1651 | | hb_apply ([&] (const RuleSet &_) { _.closure_lookups (c); }) |
| 1652 | ; |
| 1653 | } |
| 1654 | |
Qunxin Liu | 8200e48 | 2020-02-26 13:11:42 -0800 | [diff] [blame] | 1655 | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const {} |
| 1656 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1657 | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1658 | { |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 1659 | (this+coverage).collect_coverage (c->input); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1660 | |
| 1661 | struct ContextCollectGlyphsLookupContext lookup_context = { |
| 1662 | {collect_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1663 | nullptr |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1664 | }; |
| 1665 | |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 1666 | + hb_iter (ruleSet) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1667 | | hb_map (hb_add (this)) |
| 1668 | | hb_apply ([&] (const RuleSet &_) { _.collect_glyphs (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 1669 | ; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1670 | } |
| 1671 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1672 | bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1673 | { |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 1674 | const RuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])]; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1675 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1676 | {match_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1677 | nullptr |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1678 | }; |
Behdad Esfahbod | 90b60bd | 2019-03-29 22:12:42 -0700 | [diff] [blame] | 1679 | return rule_set.would_apply (c, lookup_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1680 | } |
| 1681 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 1682 | const Coverage &get_coverage () const { return this+coverage; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1683 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1684 | bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1685 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1686 | TRACE_APPLY (this); |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 1687 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 1688 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1689 | return_trace (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1690 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1691 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1692 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1693 | {match_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1694 | nullptr |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1695 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1696 | return_trace (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1697 | } |
| 1698 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1699 | bool subset (hb_subset_context_t *c) const |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 1700 | { |
| 1701 | TRACE_SUBSET (this); |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1702 | const hb_set_t &glyphset = *c->plan->glyphset (); |
| 1703 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
| 1704 | |
| 1705 | auto *out = c->serializer->start_embed (*this); |
| 1706 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
| 1707 | out->format = format; |
| 1708 | |
| 1709 | const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; |
| 1710 | hb_sorted_vector_t<hb_codepoint_t> new_coverage; |
| 1711 | + hb_zip (this+coverage, ruleSet) |
| 1712 | | hb_filter (glyphset, hb_first) |
| 1713 | | hb_filter (subset_offset_array (c, out->ruleSet, this, lookup_map), hb_second) |
| 1714 | | hb_map (hb_first) |
| 1715 | | hb_map (glyph_map) |
| 1716 | | hb_sink (new_coverage) |
| 1717 | ; |
| 1718 | |
| 1719 | out->coverage.serialize (c->serializer, out) |
Ebrahim Byagowi | 5a7cc7f | 2020-07-29 08:33:32 +0430 | [diff] [blame] | 1720 | .serialize (c->serializer, new_coverage.iter ()); |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1721 | return_trace (bool (new_coverage)); |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1724 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1725 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1726 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1727 | return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1728 | } |
| 1729 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1730 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1731 | HBUINT16 format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1732 | OffsetTo<Coverage> |
| 1733 | coverage; /* Offset to Coverage table--from |
| 1734 | * beginning of table */ |
| 1735 | OffsetArrayOf<RuleSet> |
| 1736 | ruleSet; /* Array of RuleSet tables |
| 1737 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1738 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1739 | DEFINE_SIZE_ARRAY (6, ruleSet); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1740 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1741 | |
| 1742 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1743 | struct ContextFormat2 |
| 1744 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1745 | bool intersects (const hb_set_t *glyphs) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1746 | { |
| 1747 | if (!(this+coverage).intersects (glyphs)) |
| 1748 | return false; |
| 1749 | |
| 1750 | const ClassDef &class_def = this+classDef; |
| 1751 | |
| 1752 | struct ContextClosureLookupContext lookup_context = { |
| 1753 | {intersects_class}, |
| 1754 | &class_def |
| 1755 | }; |
| 1756 | |
Behdad Esfahbod | 668d2d5 | 2019-03-29 22:48:38 -0700 | [diff] [blame] | 1757 | return |
Behdad Esfahbod | 26111a1 | 2020-06-28 02:59:47 -0700 | [diff] [blame] | 1758 | + hb_iter (ruleSet) |
| 1759 | | hb_map (hb_add (this)) |
| 1760 | | hb_enumerate |
| 1761 | | hb_map ([&] (const hb_pair_t<unsigned, const RuleSet &> p) |
Behdad Esfahbod | e530692 | 2019-03-29 23:31:07 -0700 | [diff] [blame] | 1762 | { return class_def.intersects_class (glyphs, p.first) && |
Behdad Esfahbod | 26111a1 | 2020-06-28 02:59:47 -0700 | [diff] [blame] | 1763 | p.second.intersects (glyphs, lookup_context); }) |
Behdad Esfahbod | 668d2d5 | 2019-03-29 22:48:38 -0700 | [diff] [blame] | 1764 | | hb_any |
| 1765 | ; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1768 | void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1769 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1770 | if (!(this+coverage).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1771 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1772 | |
| 1773 | const ClassDef &class_def = this+classDef; |
| 1774 | |
| 1775 | struct ContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1776 | {intersects_class}, |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 1777 | &class_def |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1778 | }; |
| 1779 | |
Behdad Esfahbod | f505b5d | 2019-03-29 22:55:02 -0700 | [diff] [blame] | 1780 | return |
| 1781 | + hb_enumerate (ruleSet) |
Behdad Esfahbod | 78d35f0 | 2019-05-15 18:15:05 -0700 | [diff] [blame] | 1782 | | hb_filter ([&] (unsigned _) |
Behdad Esfahbod | f505b5d | 2019-03-29 22:55:02 -0700 | [diff] [blame] | 1783 | { return class_def.intersects_class (c->glyphs, _); }, |
| 1784 | hb_first) |
| 1785 | | hb_map (hb_second) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1786 | | hb_map (hb_add (this)) |
| 1787 | | hb_apply ([&] (const RuleSet &_) { _.closure (c, lookup_context); }) |
Behdad Esfahbod | f505b5d | 2019-03-29 22:55:02 -0700 | [diff] [blame] | 1788 | ; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1789 | } |
| 1790 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1791 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 1792 | { |
| 1793 | + hb_iter (ruleSet) |
| 1794 | | hb_map (hb_add (this)) |
| 1795 | | hb_apply ([&] (const RuleSet &_) { _.closure_lookups (c); }) |
| 1796 | ; |
| 1797 | } |
| 1798 | |
Qunxin Liu | 8200e48 | 2020-02-26 13:11:42 -0800 | [diff] [blame] | 1799 | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const {} |
| 1800 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1801 | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1802 | { |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 1803 | (this+coverage).collect_coverage (c->input); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1804 | |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 1805 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1806 | struct ContextCollectGlyphsLookupContext lookup_context = { |
| 1807 | {collect_class}, |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 1808 | &class_def |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1809 | }; |
| 1810 | |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 1811 | + hb_iter (ruleSet) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 1812 | | hb_map (hb_add (this)) |
| 1813 | | hb_apply ([&] (const RuleSet &_) { _.collect_glyphs (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 1814 | ; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1815 | } |
| 1816 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1817 | bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1818 | { |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1819 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | 2dc1141 | 2012-11-24 19:16:34 -0500 | [diff] [blame] | 1820 | unsigned int index = class_def.get_class (c->glyphs[0]); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1821 | const RuleSet &rule_set = this+ruleSet[index]; |
| 1822 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1823 | {match_class}, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1824 | &class_def |
| 1825 | }; |
Behdad Esfahbod | 90b60bd | 2019-03-29 22:12:42 -0700 | [diff] [blame] | 1826 | return rule_set.would_apply (c, lookup_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1827 | } |
| 1828 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 1829 | const Coverage &get_coverage () const { return this+coverage; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1830 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1831 | bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1832 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1833 | TRACE_APPLY (this); |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 1834 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1835 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1836 | |
| 1837 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | 2dc1141 | 2012-11-24 19:16:34 -0500 | [diff] [blame] | 1838 | index = class_def.get_class (c->buffer->cur().codepoint); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1839 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1840 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1841 | {match_class}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1842 | &class_def |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1843 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1844 | return_trace (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1845 | } |
| 1846 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1847 | bool subset (hb_subset_context_t *c) const |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 1848 | { |
| 1849 | TRACE_SUBSET (this); |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1850 | auto *out = c->serializer->start_embed (*this); |
| 1851 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
| 1852 | out->format = format; |
| 1853 | if (unlikely (!out->coverage.serialize_subset (c, coverage, this))) |
| 1854 | return_trace (false); |
| 1855 | |
| 1856 | hb_map_t klass_map; |
| 1857 | out->classDef.serialize_subset (c, classDef, this, &klass_map); |
| 1858 | |
| 1859 | const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; |
| 1860 | bool ret = true; |
Garret Rieger | 8c3d4de | 2020-09-09 12:38:34 -0700 | [diff] [blame] | 1861 | int non_zero_index = 0, index = 0; |
Ebrahim Byagowi | a79d0e4 | 2020-05-21 07:32:58 +0430 | [diff] [blame] | 1862 | for (const hb_pair_t<unsigned, const OffsetTo<RuleSet>&> _ : + hb_enumerate (ruleSet) |
| 1863 | | hb_filter (klass_map, hb_first)) |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1864 | { |
| 1865 | auto *o = out->ruleSet.serialize_append (c->serializer); |
| 1866 | if (unlikely (!o)) |
| 1867 | { |
Ebrahim Byagowi | 5a7cc7f | 2020-07-29 08:33:32 +0430 | [diff] [blame] | 1868 | ret = false; |
| 1869 | break; |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | if (o->serialize_subset (c, _.second, this, lookup_map, &klass_map)) |
Ebrahim Byagowi | 5a7cc7f | 2020-07-29 08:33:32 +0430 | [diff] [blame] | 1873 | non_zero_index = index; |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 1874 | |
| 1875 | index++; |
| 1876 | } |
| 1877 | |
| 1878 | if (!ret) return_trace (ret); |
| 1879 | |
| 1880 | //prune empty trailing ruleSets |
| 1881 | --index; |
| 1882 | while (index > non_zero_index) |
| 1883 | { |
| 1884 | out->ruleSet.pop (); |
| 1885 | index--; |
| 1886 | } |
| 1887 | |
| 1888 | return_trace (bool (out->ruleSet)); |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1891 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1892 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1893 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1894 | return_trace (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1895 | } |
| 1896 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1897 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1898 | HBUINT16 format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1899 | OffsetTo<Coverage> |
| 1900 | coverage; /* Offset to Coverage table--from |
| 1901 | * beginning of table */ |
| 1902 | OffsetTo<ClassDef> |
| 1903 | classDef; /* Offset to glyph ClassDef table--from |
| 1904 | * beginning of table */ |
| 1905 | OffsetArrayOf<RuleSet> |
| 1906 | ruleSet; /* Array of RuleSet tables |
| 1907 | * ordered by class */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1908 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1909 | DEFINE_SIZE_ARRAY (8, ruleSet); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1910 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1911 | |
| 1912 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1913 | struct ContextFormat3 |
| 1914 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1915 | bool intersects (const hb_set_t *glyphs) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1916 | { |
Behdad Esfahbod | fb05908 | 2018-11-30 20:45:40 -0500 | [diff] [blame] | 1917 | if (!(this+coverageZ[0]).intersects (glyphs)) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1918 | return false; |
| 1919 | |
| 1920 | struct ContextClosureLookupContext lookup_context = { |
| 1921 | {intersects_coverage}, |
| 1922 | this |
| 1923 | }; |
| 1924 | return context_intersects (glyphs, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1925 | glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1926 | lookup_context); |
| 1927 | } |
| 1928 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1929 | void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1930 | { |
Behdad Esfahbod | fb05908 | 2018-11-30 20:45:40 -0500 | [diff] [blame] | 1931 | if (!(this+coverageZ[0]).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1932 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1933 | |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 1934 | const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount)); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1935 | struct ContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1936 | {intersects_coverage}, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1937 | this |
| 1938 | }; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1939 | context_closure_lookup (c, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1940 | glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1941 | lookupCount, lookupRecord, |
| 1942 | lookup_context); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1943 | } |
| 1944 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 1945 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 1946 | { |
| 1947 | const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount)); |
| 1948 | recurse_lookups (c, lookupCount, lookupRecord); |
| 1949 | } |
| 1950 | |
Qunxin Liu | 8200e48 | 2020-02-26 13:11:42 -0800 | [diff] [blame] | 1951 | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const {} |
| 1952 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1953 | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1954 | { |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 1955 | (this+coverageZ[0]).collect_coverage (c->input); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1956 | |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 1957 | const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount)); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1958 | struct ContextCollectGlyphsLookupContext lookup_context = { |
| 1959 | {collect_coverage}, |
Behdad Esfahbod | e75943d | 2012-11-30 08:38:24 +0200 | [diff] [blame] | 1960 | this |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1961 | }; |
| 1962 | |
| 1963 | context_collect_glyphs_lookup (c, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1964 | glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1965 | lookupCount, lookupRecord, |
| 1966 | lookup_context); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1967 | } |
| 1968 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1969 | bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1970 | { |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 1971 | const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1972 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1973 | {match_coverage}, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1974 | this |
| 1975 | }; |
Behdad Esfahbod | 90b60bd | 2019-03-29 22:12:42 -0700 | [diff] [blame] | 1976 | return context_would_apply_lookup (c, |
| 1977 | glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), |
| 1978 | lookupCount, lookupRecord, |
| 1979 | lookup_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1980 | } |
| 1981 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 1982 | const Coverage &get_coverage () const { return this+coverageZ[0]; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1983 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1984 | bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1985 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1986 | TRACE_APPLY (this); |
Behdad Esfahbod | fb05908 | 2018-11-30 20:45:40 -0500 | [diff] [blame] | 1987 | unsigned int index = (this+coverageZ[0]).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1988 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1989 | |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 1990 | const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount)); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1991 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1992 | {match_coverage}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1993 | this |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1994 | }; |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1995 | return_trace (context_apply_lookup (c, glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), lookupCount, lookupRecord, lookup_context)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1996 | } |
| 1997 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 1998 | bool subset (hb_subset_context_t *c) const |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 1999 | { |
| 2000 | TRACE_SUBSET (this); |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 2001 | auto *out = c->serializer->start_embed (this); |
| 2002 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
| 2003 | |
| 2004 | out->format = format; |
| 2005 | out->glyphCount = glyphCount; |
| 2006 | out->lookupCount = lookupCount; |
| 2007 | |
Behdad Esfahbod | 26111a1 | 2020-06-28 02:59:47 -0700 | [diff] [blame] | 2008 | auto coverages = coverageZ.as_array (glyphCount); |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 2009 | |
| 2010 | for (const OffsetTo<Coverage>& offset : coverages) |
| 2011 | { |
| 2012 | auto *o = c->serializer->allocate_size<OffsetTo<Coverage>> (OffsetTo<Coverage>::static_size); |
| 2013 | if (unlikely (!o)) return_trace (false); |
| 2014 | if (!o->serialize_subset (c, offset, this)) return_trace (false); |
| 2015 | } |
| 2016 | |
| 2017 | const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount)); |
| 2018 | const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; |
| 2019 | for (unsigned i = 0; i < (unsigned) lookupCount; i++) |
| 2020 | c->serializer->copy (lookupRecord[i], lookup_map); |
Ebrahim Byagowi | a79d0e4 | 2020-05-21 07:32:58 +0430 | [diff] [blame] | 2021 | |
Qunxin Liu | 8b5d3eb | 2020-04-17 11:58:31 -0700 | [diff] [blame] | 2022 | return_trace (true); |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2025 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2026 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2027 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2028 | if (!c->check_struct (this)) return_trace (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2029 | unsigned int count = glyphCount; |
Behdad Esfahbod | fb05908 | 2018-11-30 20:45:40 -0500 | [diff] [blame] | 2030 | if (!count) return_trace (false); /* We want to access coverageZ[0] freely. */ |
Behdad Esfahbod | 9507b05 | 2018-09-10 23:18:07 +0200 | [diff] [blame] | 2031 | if (!c->check_array (coverageZ.arrayZ, count)) return_trace (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2032 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2033 | if (!coverageZ[i].sanitize (c, this)) return_trace (false); |
Behdad Esfahbod | 0382b71 | 2018-11-02 12:23:26 -0400 | [diff] [blame] | 2034 | const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount)); |
Behdad Esfahbod | 9507b05 | 2018-09-10 23:18:07 +0200 | [diff] [blame] | 2035 | return_trace (c->check_array (lookupRecord, lookupCount)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2038 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2039 | HBUINT16 format; /* Format identifier--format = 3 */ |
| 2040 | HBUINT16 glyphCount; /* Number of glyphs in the input glyph |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 2041 | * sequence */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2042 | HBUINT16 lookupCount; /* Number of LookupRecords */ |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2043 | UnsizedArrayOf<OffsetTo<Coverage>> |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 2044 | coverageZ; /* Array of offsets to Coverage |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2045 | * table in glyph sequence order */ |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 2046 | /*UnsizedArrayOf<LookupRecord> |
| 2047 | lookupRecordX;*/ /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 2048 | * design order */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 2049 | public: |
Behdad Esfahbod | 6d7c6e1 | 2018-02-07 14:09:56 -0600 | [diff] [blame] | 2050 | DEFINE_SIZE_ARRAY (6, coverageZ); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 2051 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 2052 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2053 | struct Context |
| 2054 | { |
Behdad Esfahbod | 36bb24f | 2019-05-05 10:14:17 -0700 | [diff] [blame] | 2055 | template <typename context_t, typename ...Ts> |
Behdad Esfahbod | 83e3eab | 2019-05-07 20:58:43 -0700 | [diff] [blame] | 2056 | typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2057 | { |
Behdad Esfahbod | 00f6a8e | 2014-12-12 20:36:49 -0800 | [diff] [blame] | 2058 | TRACE_DISPATCH (this, u.format); |
Behdad Esfahbod | f396fbb | 2015-10-09 12:25:55 -0400 | [diff] [blame] | 2059 | if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2060 | switch (u.format) { |
Behdad Esfahbod | 36bb24f | 2019-05-05 10:14:17 -0700 | [diff] [blame] | 2061 | case 1: return_trace (c->dispatch (u.format1, hb_forward<Ts> (ds)...)); |
| 2062 | case 2: return_trace (c->dispatch (u.format2, hb_forward<Ts> (ds)...)); |
| 2063 | case 3: return_trace (c->dispatch (u.format3, hb_forward<Ts> (ds)...)); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2064 | default:return_trace (c->default_return_value ()); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2065 | } |
| 2066 | } |
| 2067 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2068 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 2069 | union { |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2070 | HBUINT16 format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 2071 | ContextFormat1 format1; |
| 2072 | ContextFormat2 format2; |
| 2073 | ContextFormat3 format3; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 2074 | } u; |
| 2075 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 2076 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2077 | |
| 2078 | /* Chaining Contextual lookups */ |
| 2079 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2080 | struct ChainContextClosureLookupContext |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2081 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2082 | ContextClosureFuncs funcs; |
| 2083 | const void *intersects_data[3]; |
| 2084 | }; |
| 2085 | |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2086 | struct ChainContextCollectGlyphsLookupContext |
| 2087 | { |
| 2088 | ContextCollectGlyphsFuncs funcs; |
| 2089 | const void *collect_data[3]; |
| 2090 | }; |
| 2091 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2092 | struct ChainContextApplyLookupContext |
| 2093 | { |
| 2094 | ContextApplyFuncs funcs; |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 2095 | const void *match_data[3]; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2096 | }; |
| 2097 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2098 | static inline bool chain_context_intersects (const hb_set_t *glyphs, |
| 2099 | unsigned int backtrackCount, |
| 2100 | const HBUINT16 backtrack[], |
| 2101 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 2102 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
| 2103 | unsigned int lookaheadCount, |
| 2104 | const HBUINT16 lookahead[], |
| 2105 | ChainContextClosureLookupContext &lookup_context) |
| 2106 | { |
Qunxin Liu | 44d88cf | 2020-05-08 15:33:34 -0700 | [diff] [blame] | 2107 | return array_is_subset_of (glyphs, |
| 2108 | backtrackCount, backtrack, |
| 2109 | lookup_context.funcs.intersects, lookup_context.intersects_data[0]) |
| 2110 | && array_is_subset_of (glyphs, |
| 2111 | inputCount ? inputCount - 1 : 0, input, |
| 2112 | lookup_context.funcs.intersects, lookup_context.intersects_data[1]) |
| 2113 | && array_is_subset_of (glyphs, |
| 2114 | lookaheadCount, lookahead, |
| 2115 | lookup_context.funcs.intersects, lookup_context.intersects_data[2]); |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2118 | static inline void chain_context_closure_lookup (hb_closure_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2119 | unsigned int backtrackCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2120 | const HBUINT16 backtrack[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2121 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2122 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2123 | unsigned int lookaheadCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2124 | const HBUINT16 lookahead[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2125 | unsigned int lookupCount, |
| 2126 | const LookupRecord lookupRecord[], |
| 2127 | ChainContextClosureLookupContext &lookup_context) |
| 2128 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2129 | if (chain_context_intersects (c->glyphs, |
| 2130 | backtrackCount, backtrack, |
| 2131 | inputCount, input, |
| 2132 | lookaheadCount, lookahead, |
| 2133 | lookup_context)) |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 2134 | recurse_lookups (c, |
| 2135 | lookupCount, lookupRecord); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2136 | } |
| 2137 | |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2138 | static inline void chain_context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c, |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 2139 | unsigned int backtrackCount, |
| 2140 | const HBUINT16 backtrack[], |
| 2141 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 2142 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
| 2143 | unsigned int lookaheadCount, |
| 2144 | const HBUINT16 lookahead[], |
| 2145 | unsigned int lookupCount, |
| 2146 | const LookupRecord lookupRecord[], |
| 2147 | ChainContextCollectGlyphsLookupContext &lookup_context) |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2148 | { |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 2149 | collect_array (c, c->before, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2150 | backtrackCount, backtrack, |
| 2151 | lookup_context.funcs.collect, lookup_context.collect_data[0]); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 2152 | collect_array (c, c->input, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2153 | inputCount ? inputCount - 1 : 0, input, |
| 2154 | lookup_context.funcs.collect, lookup_context.collect_data[1]); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 2155 | collect_array (c, c->after, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2156 | lookaheadCount, lookahead, |
| 2157 | lookup_context.funcs.collect, lookup_context.collect_data[2]); |
| 2158 | recurse_lookups (c, |
| 2159 | lookupCount, lookupRecord); |
| 2160 | } |
| 2161 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2162 | static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c, |
| 2163 | unsigned int backtrackCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2164 | const HBUINT16 backtrack[] HB_UNUSED, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2165 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2166 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2167 | unsigned int lookaheadCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2168 | const HBUINT16 lookahead[] HB_UNUSED, |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 2169 | unsigned int lookupCount HB_UNUSED, |
| 2170 | const LookupRecord lookupRecord[] HB_UNUSED, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2171 | ChainContextApplyLookupContext &lookup_context) |
| 2172 | { |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 2173 | return (c->zero_context ? !backtrackCount && !lookaheadCount : true) |
Behdad Esfahbod | 1f2bb17 | 2012-08-23 16:10:37 -0400 | [diff] [blame] | 2174 | && would_match_input (c, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2175 | inputCount, input, |
| 2176 | lookup_context.funcs.match, lookup_context.match_data[1]); |
| 2177 | } |
| 2178 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 2179 | static inline bool chain_context_apply_lookup (hb_ot_apply_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2180 | unsigned int backtrackCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2181 | const HBUINT16 backtrack[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2182 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2183 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2184 | unsigned int lookaheadCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2185 | const HBUINT16 lookahead[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2186 | unsigned int lookupCount, |
| 2187 | const LookupRecord lookupRecord[], |
| 2188 | ChainContextApplyLookupContext &lookup_context) |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 2189 | { |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 2190 | unsigned int start_index = 0, match_length = 0, end_index = 0; |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 2191 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH]; |
Behdad Esfahbod | f19e0b0 | 2012-06-09 02:26:57 -0400 | [diff] [blame] | 2192 | return match_input (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 2193 | inputCount, input, |
| 2194 | lookup_context.funcs.match, lookup_context.match_data[1], |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 2195 | &match_length, match_positions) |
Behdad Esfahbod | f19e0b0 | 2012-06-09 02:26:57 -0400 | [diff] [blame] | 2196 | && match_backtrack (c, |
| 2197 | backtrackCount, backtrack, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 2198 | lookup_context.funcs.match, lookup_context.match_data[0], |
| 2199 | &start_index) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 2200 | && match_lookahead (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 2201 | lookaheadCount, lookahead, |
| 2202 | lookup_context.funcs.match, lookup_context.match_data[2], |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 2203 | match_length, &end_index) |
| 2204 | && (c->buffer->unsafe_to_break_from_outbuffer (start_index, end_index), |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 2205 | apply_lookup (c, |
| 2206 | inputCount, match_positions, |
| 2207 | lookupCount, lookupRecord, |
| 2208 | match_length)); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 2209 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2210 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2211 | struct ChainRule |
| 2212 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2213 | bool intersects (const hb_set_t *glyphs, ChainContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2214 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2215 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
| 2216 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2217 | return chain_context_intersects (glyphs, |
| 2218 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 2219 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2220 | lookahead.len, lookahead.arrayZ, |
| 2221 | lookup_context); |
| 2222 | } |
| 2223 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2224 | void closure (hb_closure_context_t *c, |
| 2225 | ChainContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2226 | { |
Ebrahim Byagowi | 0c65a23 | 2020-04-23 11:23:54 +0430 | [diff] [blame] | 2227 | if (unlikely (c->lookup_limit_exceeded ())) return; |
Garret Rieger | 4ad686b | 2020-03-25 23:32:28 -0700 | [diff] [blame] | 2228 | |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2229 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
| 2230 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
| 2231 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2232 | chain_context_closure_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2233 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 2234 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2235 | lookahead.len, lookahead.arrayZ, |
| 2236 | lookup.len, lookup.arrayZ, |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2237 | lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2238 | } |
| 2239 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 2240 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 2241 | { |
Ebrahim Byagowi | 0c65a23 | 2020-04-23 11:23:54 +0430 | [diff] [blame] | 2242 | if (unlikely (c->lookup_limit_exceeded ())) return; |
Garret Rieger | 4ad686b | 2020-03-25 23:32:28 -0700 | [diff] [blame] | 2243 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 2244 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
| 2245 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
| 2246 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
| 2247 | recurse_lookups (c, lookup.len, lookup.arrayZ); |
| 2248 | } |
| 2249 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2250 | void collect_glyphs (hb_collect_glyphs_context_t *c, |
| 2251 | ChainContextCollectGlyphsLookupContext &lookup_context) const |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2252 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2253 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
| 2254 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
| 2255 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2256 | chain_context_collect_glyphs_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2257 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 2258 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2259 | lookahead.len, lookahead.arrayZ, |
| 2260 | lookup.len, lookup.arrayZ, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2261 | lookup_context); |
| 2262 | } |
| 2263 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2264 | bool would_apply (hb_would_apply_context_t *c, |
| 2265 | ChainContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2266 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2267 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
| 2268 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
| 2269 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | 90b60bd | 2019-03-29 22:12:42 -0700 | [diff] [blame] | 2270 | return chain_context_would_apply_lookup (c, |
| 2271 | backtrack.len, backtrack.arrayZ, |
| 2272 | input.lenP1, input.arrayZ, |
| 2273 | lookahead.len, lookahead.arrayZ, lookup.len, |
| 2274 | lookup.arrayZ, lookup_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2275 | } |
| 2276 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2277 | bool apply (hb_ot_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2278 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2279 | TRACE_APPLY (this); |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2280 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
| 2281 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
| 2282 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2283 | return_trace (chain_context_apply_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2284 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 2285 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2286 | lookahead.len, lookahead.arrayZ, lookup.len, |
| 2287 | lookup.arrayZ, lookup_context)); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2288 | } |
| 2289 | |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2290 | template<typename Iterator, |
| 2291 | hb_requires (hb_is_iterator (Iterator))> |
| 2292 | void serialize_array (hb_serialize_context_t *c, |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 2293 | HBUINT16 len, |
| 2294 | Iterator it) const |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2295 | { |
| 2296 | c->copy (len); |
| 2297 | for (const auto g : it) |
| 2298 | { |
| 2299 | HBUINT16 gid; |
| 2300 | gid = g; |
| 2301 | c->copy (gid); |
| 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | ChainRule* copy (hb_serialize_context_t *c, |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2306 | const hb_map_t *lookup_map, |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2307 | const hb_map_t *backtrack_map, |
| 2308 | const hb_map_t *input_map = nullptr, |
| 2309 | const hb_map_t *lookahead_map = nullptr) const |
| 2310 | { |
| 2311 | TRACE_SERIALIZE (this); |
| 2312 | auto *out = c->start_embed (this); |
| 2313 | if (unlikely (!out)) return_trace (nullptr); |
| 2314 | |
| 2315 | const hb_map_t *mapping = backtrack_map; |
| 2316 | serialize_array (c, backtrack.len, + backtrack.iter () |
| 2317 | | hb_map (mapping)); |
| 2318 | |
| 2319 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
| 2320 | if (input_map) mapping = input_map; |
| 2321 | serialize_array (c, input.lenP1, + input.iter () |
| 2322 | | hb_map (mapping)); |
| 2323 | |
| 2324 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
| 2325 | if (lookahead_map) mapping = lookahead_map; |
| 2326 | serialize_array (c, lookahead.len, + lookahead.iter () |
| 2327 | | hb_map (mapping)); |
| 2328 | |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2329 | const ArrayOf<LookupRecord> &lookupRecord = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2330 | |
Garret Rieger | 8f47dd5 | 2020-11-04 11:05:22 -0800 | [diff] [blame^] | 2331 | HBUINT16* lookupCount = c->embed (&(lookupRecord.len)); |
| 2332 | if (!lookupCount) return_trace (nullptr); |
| 2333 | |
| 2334 | for (unsigned i = 0; i < lookupRecord.len; i++) |
| 2335 | { |
| 2336 | if (!lookup_map->has (lookupRecord[i].lookupListIndex)) |
| 2337 | { |
| 2338 | (*lookupCount)--; |
| 2339 | continue; |
| 2340 | } |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2341 | if (!c->copy (lookupRecord[i], lookup_map)) return_trace (nullptr); |
Garret Rieger | 8f47dd5 | 2020-11-04 11:05:22 -0800 | [diff] [blame^] | 2342 | } |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2343 | |
| 2344 | return_trace (out); |
| 2345 | } |
| 2346 | |
| 2347 | bool subset (hb_subset_context_t *c, |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2348 | const hb_map_t *lookup_map, |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 2349 | const hb_map_t *backtrack_map = nullptr, |
| 2350 | const hb_map_t *input_map = nullptr, |
| 2351 | const hb_map_t *lookahead_map = nullptr) const |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2352 | { |
| 2353 | TRACE_SUBSET (this); |
| 2354 | |
Qunxin Liu | b2fcca6 | 2019-10-24 15:15:26 -0700 | [diff] [blame] | 2355 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
| 2356 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
| 2357 | |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2358 | if (!backtrack_map) |
| 2359 | { |
| 2360 | const hb_set_t &glyphset = *c->plan->glyphset (); |
| 2361 | if (!hb_all (backtrack, glyphset) || |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 2362 | !hb_all (input, glyphset) || |
| 2363 | !hb_all (lookahead, glyphset)) |
| 2364 | return_trace (false); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2365 | |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2366 | copy (c->serializer, lookup_map, c->plan->glyph_map); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2367 | } |
| 2368 | else |
| 2369 | { |
| 2370 | if (!hb_all (backtrack, backtrack_map) || |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 2371 | !hb_all (input, input_map) || |
| 2372 | !hb_all (lookahead, lookahead_map)) |
| 2373 | return_trace (false); |
Ebrahim Byagowi | aca6390 | 2019-10-22 00:06:46 +0330 | [diff] [blame] | 2374 | |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2375 | copy (c->serializer, lookup_map, backtrack_map, input_map, lookahead_map); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | return_trace (true); |
| 2379 | } |
| 2380 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2381 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2382 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2383 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2384 | if (!backtrack.sanitize (c)) return_trace (false); |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2385 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2386 | if (!input.sanitize (c)) return_trace (false); |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2387 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16>> (input); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2388 | if (!lookahead.sanitize (c)) return_trace (false); |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2389 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2390 | return_trace (lookup.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2391 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2392 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2393 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2394 | ArrayOf<HBUINT16> |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 2395 | backtrack; /* Array of backtracking values |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2396 | * (to be matched before the input |
| 2397 | * sequence) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2398 | HeadlessArrayOf<HBUINT16> |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 2399 | inputX; /* Array of input values (start with |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2400 | * second glyph) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2401 | ArrayOf<HBUINT16> |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 2402 | lookaheadX; /* Array of lookahead values's (to be |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2403 | * matched after the input sequence) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 2404 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 2405 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2406 | * design order) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2407 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 2408 | DEFINE_SIZE_MIN (8); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2409 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2410 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2411 | struct ChainRuleSet |
| 2412 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2413 | bool intersects (const hb_set_t *glyphs, ChainContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2414 | { |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2415 | return |
| 2416 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2417 | | hb_map (hb_add (this)) |
| 2418 | | hb_map ([&] (const ChainRule &_) { return _.intersects (glyphs, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2419 | | hb_any |
| 2420 | ; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2421 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2422 | void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2423 | { |
Ebrahim Byagowi | 0c65a23 | 2020-04-23 11:23:54 +0430 | [diff] [blame] | 2424 | if (unlikely (c->lookup_limit_exceeded ())) return; |
Garret Rieger | 4ad686b | 2020-03-25 23:32:28 -0700 | [diff] [blame] | 2425 | |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2426 | return |
| 2427 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2428 | | hb_map (hb_add (this)) |
| 2429 | | hb_apply ([&] (const ChainRule &_) { _.closure (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2430 | ; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2431 | } |
| 2432 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 2433 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 2434 | { |
Ebrahim Byagowi | 0c65a23 | 2020-04-23 11:23:54 +0430 | [diff] [blame] | 2435 | if (unlikely (c->lookup_limit_exceeded ())) return; |
Garret Rieger | 4ad686b | 2020-03-25 23:32:28 -0700 | [diff] [blame] | 2436 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 2437 | return |
| 2438 | + hb_iter (rule) |
| 2439 | | hb_map (hb_add (this)) |
| 2440 | | hb_apply ([&] (const ChainRule &_) { _.closure_lookups (c); }) |
| 2441 | ; |
| 2442 | } |
| 2443 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2444 | void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2445 | { |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2446 | return |
| 2447 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2448 | | hb_map (hb_add (this)) |
| 2449 | | hb_apply ([&] (const ChainRule &_) { _.collect_glyphs (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2450 | ; |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2451 | } |
| 2452 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2453 | bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2454 | { |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2455 | return |
| 2456 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2457 | | hb_map (hb_add (this)) |
| 2458 | | hb_map ([&] (const ChainRule &_) { return _.would_apply (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2459 | | hb_any |
| 2460 | ; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2461 | } |
| 2462 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2463 | bool apply (hb_ot_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2464 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2465 | TRACE_APPLY (this); |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2466 | return_trace ( |
| 2467 | + hb_iter (rule) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2468 | | hb_map (hb_add (this)) |
| 2469 | | hb_map ([&] (const ChainRule &_) { return _.apply (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2470 | | hb_any |
| 2471 | ) |
| 2472 | ; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2473 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2474 | |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2475 | bool subset (hb_subset_context_t *c, |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2476 | const hb_map_t *lookup_map, |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 2477 | const hb_map_t *backtrack_klass_map = nullptr, |
| 2478 | const hb_map_t *input_klass_map = nullptr, |
| 2479 | const hb_map_t *lookahead_klass_map = nullptr) const |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2480 | { |
| 2481 | TRACE_SUBSET (this); |
| 2482 | |
| 2483 | auto snap = c->serializer->snapshot (); |
| 2484 | auto *out = c->serializer->start_embed (*this); |
| 2485 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
| 2486 | |
| 2487 | for (const OffsetTo<ChainRule>& _ : rule) |
| 2488 | { |
| 2489 | if (!_) continue; |
| 2490 | auto *o = out->rule.serialize_append (c->serializer); |
| 2491 | if (unlikely (!o)) continue; |
Ebrahim Byagowi | aca6390 | 2019-10-22 00:06:46 +0330 | [diff] [blame] | 2492 | |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2493 | auto o_snap = c->serializer->snapshot (); |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 2494 | if (!o->serialize_subset (c, _, this, |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2495 | lookup_map, |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 2496 | backtrack_klass_map, |
| 2497 | input_klass_map, |
| 2498 | lookahead_klass_map)) |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2499 | { |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 2500 | out->rule.pop (); |
| 2501 | c->serializer->revert (o_snap); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | bool ret = bool (out->rule); |
| 2506 | if (!ret) c->serializer->revert (snap); |
Ebrahim Byagowi | aca6390 | 2019-10-22 00:06:46 +0330 | [diff] [blame] | 2507 | |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2508 | return_trace (ret); |
| 2509 | } |
| 2510 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2511 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2512 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2513 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2514 | return_trace (rule.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2515 | } |
| 2516 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2517 | protected: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2518 | OffsetArrayOf<ChainRule> |
| 2519 | rule; /* Array of ChainRule tables |
| 2520 | * ordered by preference */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2521 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 2522 | DEFINE_SIZE_ARRAY (2, rule); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2523 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2524 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2525 | struct ChainContextFormat1 |
| 2526 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2527 | bool intersects (const hb_set_t *glyphs) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2528 | { |
| 2529 | struct ChainContextClosureLookupContext lookup_context = { |
| 2530 | {intersects_glyph}, |
| 2531 | {nullptr, nullptr, nullptr} |
| 2532 | }; |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2533 | |
| 2534 | return |
| 2535 | + hb_zip (this+coverage, ruleSet) |
| 2536 | | hb_filter (*glyphs, hb_first) |
| 2537 | | hb_map (hb_second) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2538 | | hb_map (hb_add (this)) |
| 2539 | | hb_map ([&] (const ChainRuleSet &_) { return _.intersects (glyphs, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2540 | | hb_any |
| 2541 | ; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2544 | void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2545 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2546 | struct ChainContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2547 | {intersects_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 2548 | {nullptr, nullptr, nullptr} |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2549 | }; |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2550 | |
| 2551 | + hb_zip (this+coverage, ruleSet) |
| 2552 | | hb_filter (*c->glyphs, hb_first) |
| 2553 | | hb_map (hb_second) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2554 | | hb_map (hb_add (this)) |
| 2555 | | hb_apply ([&] (const ChainRuleSet &_) { _.closure (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2556 | ; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2557 | } |
| 2558 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 2559 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 2560 | { |
| 2561 | + hb_iter (ruleSet) |
| 2562 | | hb_map (hb_add (this)) |
| 2563 | | hb_apply ([&] (const ChainRuleSet &_) { _.closure_lookups (c); }) |
| 2564 | ; |
| 2565 | } |
| 2566 | |
Qunxin Liu | 8200e48 | 2020-02-26 13:11:42 -0800 | [diff] [blame] | 2567 | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const {} |
| 2568 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2569 | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2570 | { |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 2571 | (this+coverage).collect_coverage (c->input); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2572 | |
| 2573 | struct ChainContextCollectGlyphsLookupContext lookup_context = { |
| 2574 | {collect_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 2575 | {nullptr, nullptr, nullptr} |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2576 | }; |
| 2577 | |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2578 | + hb_iter (ruleSet) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2579 | | hb_map (hb_add (this)) |
| 2580 | | hb_apply ([&] (const ChainRuleSet &_) { _.collect_glyphs (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2581 | ; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2582 | } |
| 2583 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2584 | bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2585 | { |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 2586 | const ChainRuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])]; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2587 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2588 | {match_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 2589 | {nullptr, nullptr, nullptr} |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2590 | }; |
Behdad Esfahbod | 90b60bd | 2019-03-29 22:12:42 -0700 | [diff] [blame] | 2591 | return rule_set.would_apply (c, lookup_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2592 | } |
| 2593 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 2594 | const Coverage &get_coverage () const { return this+coverage; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2595 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2596 | bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2597 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2598 | TRACE_APPLY (this); |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 2599 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2600 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2601 | |
| 2602 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2603 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2604 | {match_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 2605 | {nullptr, nullptr, nullptr} |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2606 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2607 | return_trace (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2608 | } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2609 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2610 | bool subset (hb_subset_context_t *c) const |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 2611 | { |
| 2612 | TRACE_SUBSET (this); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2613 | const hb_set_t &glyphset = *c->plan->glyphset (); |
| 2614 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
| 2615 | |
| 2616 | auto *out = c->serializer->start_embed (*this); |
| 2617 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
| 2618 | out->format = format; |
| 2619 | |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2620 | const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2621 | hb_sorted_vector_t<hb_codepoint_t> new_coverage; |
| 2622 | + hb_zip (this+coverage, ruleSet) |
| 2623 | | hb_filter (glyphset, hb_first) |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2624 | | hb_filter (subset_offset_array (c, out->ruleSet, this, lookup_map), hb_second) |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2625 | | hb_map (hb_first) |
| 2626 | | hb_map (glyph_map) |
| 2627 | | hb_sink (new_coverage) |
| 2628 | ; |
| 2629 | |
| 2630 | out->coverage.serialize (c->serializer, out) |
| 2631 | .serialize (c->serializer, new_coverage.iter ()); |
| 2632 | return_trace (bool (new_coverage)); |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 2633 | } |
| 2634 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2635 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2636 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2637 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2638 | return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2639 | } |
| 2640 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2641 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2642 | HBUINT16 format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2643 | OffsetTo<Coverage> |
| 2644 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2645 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2646 | OffsetArrayOf<ChainRuleSet> |
| 2647 | ruleSet; /* Array of ChainRuleSet tables |
| 2648 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2649 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 2650 | DEFINE_SIZE_ARRAY (6, ruleSet); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2651 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2652 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2653 | struct ChainContextFormat2 |
| 2654 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2655 | bool intersects (const hb_set_t *glyphs) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2656 | { |
| 2657 | if (!(this+coverage).intersects (glyphs)) |
| 2658 | return false; |
| 2659 | |
| 2660 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 2661 | const ClassDef &input_class_def = this+inputClassDef; |
| 2662 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 2663 | |
| 2664 | struct ChainContextClosureLookupContext lookup_context = { |
| 2665 | {intersects_class}, |
| 2666 | {&backtrack_class_def, |
| 2667 | &input_class_def, |
| 2668 | &lookahead_class_def} |
| 2669 | }; |
| 2670 | |
Behdad Esfahbod | f505b5d | 2019-03-29 22:55:02 -0700 | [diff] [blame] | 2671 | return |
Behdad Esfahbod | 26111a1 | 2020-06-28 02:59:47 -0700 | [diff] [blame] | 2672 | + hb_iter (ruleSet) |
| 2673 | | hb_map (hb_add (this)) |
| 2674 | | hb_enumerate |
| 2675 | | hb_map ([&] (const hb_pair_t<unsigned, const ChainRuleSet &> p) |
Behdad Esfahbod | 78d35f0 | 2019-05-15 18:15:05 -0700 | [diff] [blame] | 2676 | { return input_class_def.intersects_class (glyphs, p.first) && |
Behdad Esfahbod | 26111a1 | 2020-06-28 02:59:47 -0700 | [diff] [blame] | 2677 | p.second.intersects (glyphs, lookup_context); }) |
Behdad Esfahbod | f505b5d | 2019-03-29 22:55:02 -0700 | [diff] [blame] | 2678 | | hb_any |
| 2679 | ; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2680 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2681 | void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2682 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2683 | if (!(this+coverage).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2684 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2685 | |
| 2686 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 2687 | const ClassDef &input_class_def = this+inputClassDef; |
| 2688 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 2689 | |
| 2690 | struct ChainContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2691 | {intersects_class}, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2692 | {&backtrack_class_def, |
| 2693 | &input_class_def, |
| 2694 | &lookahead_class_def} |
| 2695 | }; |
| 2696 | |
Behdad Esfahbod | f505b5d | 2019-03-29 22:55:02 -0700 | [diff] [blame] | 2697 | return |
| 2698 | + hb_enumerate (ruleSet) |
Behdad Esfahbod | 78d35f0 | 2019-05-15 18:15:05 -0700 | [diff] [blame] | 2699 | | hb_filter ([&] (unsigned _) |
Behdad Esfahbod | f505b5d | 2019-03-29 22:55:02 -0700 | [diff] [blame] | 2700 | { return input_class_def.intersects_class (c->glyphs, _); }, |
| 2701 | hb_first) |
| 2702 | | hb_map (hb_second) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2703 | | hb_map (hb_add (this)) |
| 2704 | | hb_apply ([&] (const ChainRuleSet &_) { _.closure (c, lookup_context); }) |
Behdad Esfahbod | f505b5d | 2019-03-29 22:55:02 -0700 | [diff] [blame] | 2705 | ; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2706 | } |
| 2707 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 2708 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 2709 | { |
| 2710 | + hb_iter (ruleSet) |
| 2711 | | hb_map (hb_add (this)) |
| 2712 | | hb_apply ([&] (const ChainRuleSet &_) { _.closure_lookups (c); }) |
| 2713 | ; |
| 2714 | } |
| 2715 | |
Qunxin Liu | 8200e48 | 2020-02-26 13:11:42 -0800 | [diff] [blame] | 2716 | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const {} |
| 2717 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2718 | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2719 | { |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 2720 | (this+coverage).collect_coverage (c->input); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2721 | |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2722 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 2723 | const ClassDef &input_class_def = this+inputClassDef; |
| 2724 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 2725 | |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2726 | struct ChainContextCollectGlyphsLookupContext lookup_context = { |
| 2727 | {collect_class}, |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2728 | {&backtrack_class_def, |
| 2729 | &input_class_def, |
| 2730 | &lookahead_class_def} |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2731 | }; |
| 2732 | |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2733 | + hb_iter (ruleSet) |
Behdad Esfahbod | 2376867 | 2019-05-15 21:57:26 -0700 | [diff] [blame] | 2734 | | hb_map (hb_add (this)) |
| 2735 | | hb_apply ([&] (const ChainRuleSet &_) { _.collect_glyphs (c, lookup_context); }) |
Behdad Esfahbod | 05f2130 | 2019-03-29 22:40:13 -0700 | [diff] [blame] | 2736 | ; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2737 | } |
| 2738 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2739 | bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2740 | { |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2741 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2742 | const ClassDef &input_class_def = this+inputClassDef; |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2743 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2744 | |
Behdad Esfahbod | 2dc1141 | 2012-11-24 19:16:34 -0500 | [diff] [blame] | 2745 | unsigned int index = input_class_def.get_class (c->glyphs[0]); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2746 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
| 2747 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2748 | {match_class}, |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2749 | {&backtrack_class_def, |
| 2750 | &input_class_def, |
| 2751 | &lookahead_class_def} |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2752 | }; |
Behdad Esfahbod | 90b60bd | 2019-03-29 22:12:42 -0700 | [diff] [blame] | 2753 | return rule_set.would_apply (c, lookup_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2754 | } |
| 2755 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 2756 | const Coverage &get_coverage () const { return this+coverage; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2757 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2758 | bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2759 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2760 | TRACE_APPLY (this); |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 2761 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2762 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2763 | |
| 2764 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 2765 | const ClassDef &input_class_def = this+inputClassDef; |
| 2766 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 2767 | |
Behdad Esfahbod | 2dc1141 | 2012-11-24 19:16:34 -0500 | [diff] [blame] | 2768 | index = input_class_def.get_class (c->buffer->cur().codepoint); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2769 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2770 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2771 | {match_class}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 2772 | {&backtrack_class_def, |
| 2773 | &input_class_def, |
| 2774 | &lookahead_class_def} |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2775 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2776 | return_trace (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2777 | } |
| 2778 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2779 | bool subset (hb_subset_context_t *c) const |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 2780 | { |
| 2781 | TRACE_SUBSET (this); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2782 | auto *out = c->serializer->start_embed (*this); |
| 2783 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
| 2784 | out->format = format; |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 2785 | out->coverage.serialize_subset (c, coverage, this); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2786 | |
| 2787 | hb_map_t backtrack_klass_map; |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 2788 | out->backtrackClassDef.serialize_subset (c, backtrackClassDef, this, &backtrack_klass_map); |
Garret Rieger | 06dbb6a | 2020-07-31 15:56:14 -0700 | [diff] [blame] | 2789 | if (unlikely (!c->serializer->check_success (!backtrack_klass_map.in_error ()))) |
| 2790 | return_trace (false); |
Ebrahim Byagowi | aca6390 | 2019-10-22 00:06:46 +0330 | [diff] [blame] | 2791 | |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2792 | // subset inputClassDef based on glyphs survived in Coverage subsetting |
| 2793 | hb_map_t input_klass_map; |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 2794 | out->inputClassDef.serialize_subset (c, inputClassDef, this, &input_klass_map); |
Garret Rieger | 06dbb6a | 2020-07-31 15:56:14 -0700 | [diff] [blame] | 2795 | if (unlikely (!c->serializer->check_success (!input_klass_map.in_error ()))) |
| 2796 | return_trace (false); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2797 | |
| 2798 | hb_map_t lookahead_klass_map; |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 2799 | out->lookaheadClassDef.serialize_subset (c, lookaheadClassDef, this, &lookahead_klass_map); |
Garret Rieger | 06dbb6a | 2020-07-31 15:56:14 -0700 | [diff] [blame] | 2800 | if (unlikely (!c->serializer->check_success (!lookahead_klass_map.in_error ()))) |
| 2801 | return_trace (false); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2802 | |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2803 | unsigned non_zero_index = 0, index = 0; |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2804 | bool ret = true; |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2805 | const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2806 | for (const OffsetTo<ChainRuleSet>& _ : + hb_enumerate (ruleSet) |
| 2807 | | hb_filter (input_klass_map, hb_first) |
| 2808 | | hb_map (hb_second)) |
| 2809 | { |
| 2810 | auto *o = out->ruleSet.serialize_append (c->serializer); |
| 2811 | if (unlikely (!o)) |
| 2812 | { |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 2813 | ret = false; |
| 2814 | break; |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2815 | } |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2816 | if (o->serialize_subset (c, _, this, |
| 2817 | lookup_map, |
| 2818 | &backtrack_klass_map, |
| 2819 | &input_klass_map, |
| 2820 | &lookahead_klass_map)) |
Ebrahim Byagowi | 5a7cc7f | 2020-07-29 08:33:32 +0430 | [diff] [blame] | 2821 | non_zero_index = index; |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2822 | |
| 2823 | index++; |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | if (!ret) return_trace (ret); |
| 2827 | |
| 2828 | //prune empty trailing ruleSets |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2829 | --index; |
| 2830 | while (index > non_zero_index) |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2831 | { |
| 2832 | out->ruleSet.pop (); |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 2833 | index--; |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | return_trace (bool (out->ruleSet)); |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2839 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2840 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2841 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2842 | return_trace (coverage.sanitize (c, this) && |
| 2843 | backtrackClassDef.sanitize (c, this) && |
| 2844 | inputClassDef.sanitize (c, this) && |
| 2845 | lookaheadClassDef.sanitize (c, this) && |
| 2846 | ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2847 | } |
| 2848 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2849 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2850 | HBUINT16 format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2851 | OffsetTo<Coverage> |
| 2852 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2853 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2854 | OffsetTo<ClassDef> |
| 2855 | backtrackClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2856 | * containing backtrack sequence |
| 2857 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2858 | OffsetTo<ClassDef> |
| 2859 | inputClassDef; /* Offset to glyph ClassDef |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2860 | * table containing input sequence |
| 2861 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2862 | OffsetTo<ClassDef> |
| 2863 | lookaheadClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2864 | * containing lookahead sequence |
| 2865 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2866 | OffsetArrayOf<ChainRuleSet> |
| 2867 | ruleSet; /* Array of ChainRuleSet tables |
| 2868 | * ordered by class */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2869 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 2870 | DEFINE_SIZE_ARRAY (12, ruleSet); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2871 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2872 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2873 | struct ChainContextFormat3 |
| 2874 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2875 | bool intersects (const hb_set_t *glyphs) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2876 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2877 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2878 | |
| 2879 | if (!(this+input[0]).intersects (glyphs)) |
| 2880 | return false; |
| 2881 | |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2882 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage>> (input); |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2883 | struct ChainContextClosureLookupContext lookup_context = { |
| 2884 | {intersects_coverage}, |
| 2885 | {this, this, this} |
| 2886 | }; |
| 2887 | return chain_context_intersects (glyphs, |
| 2888 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2889 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2890 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2891 | lookup_context); |
| 2892 | } |
| 2893 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2894 | void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2895 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2896 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2897 | |
| 2898 | if (!(this+input[0]).intersects (c->glyphs)) |
| 2899 | return; |
| 2900 | |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2901 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage>> (input); |
| 2902 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2903 | struct ChainContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2904 | {intersects_coverage}, |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2905 | {this, this, this} |
| 2906 | }; |
| 2907 | chain_context_closure_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2908 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2909 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2910 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2911 | lookup.len, lookup.arrayZ, |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2912 | lookup_context); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2913 | } |
| 2914 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 2915 | void closure_lookups (hb_closure_lookups_context_t *c) const |
| 2916 | { |
| 2917 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
| 2918 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage>> (input); |
| 2919 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
| 2920 | recurse_lookups (c, lookup.len, lookup.arrayZ); |
| 2921 | } |
| 2922 | |
Qunxin Liu | 8200e48 | 2020-02-26 13:11:42 -0800 | [diff] [blame] | 2923 | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const {} |
| 2924 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2925 | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2926 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2927 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2928 | |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 2929 | (this+input[0]).collect_coverage (c->input); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2930 | |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2931 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage>> (input); |
| 2932 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2933 | struct ChainContextCollectGlyphsLookupContext lookup_context = { |
| 2934 | {collect_coverage}, |
| 2935 | {this, this, this} |
| 2936 | }; |
| 2937 | chain_context_collect_glyphs_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2938 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2939 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2940 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2941 | lookup.len, lookup.arrayZ, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2942 | lookup_context); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2943 | } |
| 2944 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2945 | bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2946 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2947 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
| 2948 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage>> (input); |
| 2949 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2950 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2951 | {match_coverage}, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2952 | {this, this, this} |
| 2953 | }; |
Behdad Esfahbod | 90b60bd | 2019-03-29 22:12:42 -0700 | [diff] [blame] | 2954 | return chain_context_would_apply_lookup (c, |
| 2955 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2956 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2957 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2958 | lookup.len, lookup.arrayZ, lookup_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2959 | } |
| 2960 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 2961 | const Coverage &get_coverage () const |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2962 | { |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2963 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2964 | return this+input[0]; |
| 2965 | } |
| 2966 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 2967 | bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2968 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2969 | TRACE_APPLY (this); |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2970 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 2971 | |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 2972 | unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2973 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2974 | |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 2975 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage>> (input); |
| 2976 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2977 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2978 | {match_coverage}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 2979 | {this, this, this} |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 2980 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2981 | return_trace (chain_context_apply_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2982 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2983 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2984 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2985 | lookup.len, lookup.arrayZ, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2986 | } |
| 2987 | |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2988 | template<typename Iterator, |
| 2989 | hb_requires (hb_is_iterator (Iterator))> |
Ebrahim Byagowi | 07acd1a | 2020-03-08 23:39:24 +0330 | [diff] [blame] | 2990 | bool serialize_coverage_offsets (hb_subset_context_t *c, Iterator it, const void* base) const |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2991 | { |
| 2992 | TRACE_SERIALIZE (this); |
| 2993 | auto *out = c->serializer->start_embed<OffsetArrayOf<Coverage>> (); |
| 2994 | |
| 2995 | if (unlikely (!c->serializer->allocate_size<HBUINT16> (HBUINT16::static_size))) return_trace (false); |
| 2996 | |
| 2997 | + it |
Ebrahim Byagowi | 07acd1a | 2020-03-08 23:39:24 +0330 | [diff] [blame] | 2998 | | hb_apply (subset_offset_array (c, *out, base)) |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 2999 | ; |
| 3000 | |
| 3001 | return_trace (out->len); |
| 3002 | } |
| 3003 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3004 | bool subset (hb_subset_context_t *c) const |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 3005 | { |
| 3006 | TRACE_SUBSET (this); |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 3007 | |
| 3008 | auto *out = c->serializer->start_embed (this); |
| 3009 | if (unlikely (!out)) return_trace (false); |
| 3010 | if (unlikely (!c->serializer->embed (this->format))) return_trace (false); |
| 3011 | |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 3012 | if (!serialize_coverage_offsets (c, backtrack.iter (), this)) |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 3013 | return_trace (false); |
Ebrahim Byagowi | aca6390 | 2019-10-22 00:06:46 +0330 | [diff] [blame] | 3014 | |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 3015 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 3016 | if (!serialize_coverage_offsets (c, input.iter (), this)) |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 3017 | return_trace (false); |
| 3018 | |
| 3019 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage>> (input); |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 3020 | if (!serialize_coverage_offsets (c, lookahead.iter (), this)) |
Qunxin Liu | b66094a | 2019-09-30 16:19:18 -0700 | [diff] [blame] | 3021 | return_trace (false); |
Ebrahim Byagowi | aca6390 | 2019-10-22 00:06:46 +0330 | [diff] [blame] | 3022 | |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 3023 | const ArrayOf<LookupRecord> &lookupRecord = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
| 3024 | HBUINT16 lookupCount; |
| 3025 | lookupCount = lookupRecord.len; |
| 3026 | if (!c->serializer->copy (lookupCount)) return_trace (false); |
| 3027 | |
| 3028 | const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; |
| 3029 | for (unsigned i = 0; i < (unsigned) lookupCount; i++) |
| 3030 | if (!c->serializer->copy (lookupRecord[i], lookup_map)) return_trace (false); |
Ebrahim Byagowi | d0e2add | 2020-07-18 22:14:52 +0430 | [diff] [blame] | 3031 | |
Qunxin Liu | 593e58c | 2020-05-20 18:00:25 -0700 | [diff] [blame] | 3032 | return_trace (true); |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3035 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 3036 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 3037 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 3038 | if (!backtrack.sanitize (c, this)) return_trace (false); |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 3039 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage>> (backtrack); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 3040 | if (!input.sanitize (c, this)) return_trace (false); |
| 3041 | if (!input.len) return_trace (false); /* To be consistent with Context. */ |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 3042 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage>> (input); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 3043 | if (!lookahead.sanitize (c, this)) return_trace (false); |
Ebrahim Byagowi | 9258878 | 2019-04-30 13:05:10 -0700 | [diff] [blame] | 3044 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord>> (lookahead); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 3045 | return_trace (lookup.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 3046 | } |
| 3047 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 3048 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 3049 | HBUINT16 format; /* Format identifier--format = 3 */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 3050 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 3051 | backtrack; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 3052 | * in backtracking sequence, in glyph |
| 3053 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 3054 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 3055 | inputX ; /* Array of coverage |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 3056 | * tables in input sequence, in glyph |
| 3057 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 3058 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 3059 | lookaheadX; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 3060 | * in lookahead sequence, in glyph |
| 3061 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 3062 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 3063 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 3064 | * design order) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 3065 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 3066 | DEFINE_SIZE_MIN (10); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 3067 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 3068 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 3069 | struct ChainContext |
| 3070 | { |
Behdad Esfahbod | 36bb24f | 2019-05-05 10:14:17 -0700 | [diff] [blame] | 3071 | template <typename context_t, typename ...Ts> |
Behdad Esfahbod | 83e3eab | 2019-05-07 20:58:43 -0700 | [diff] [blame] | 3072 | typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 3073 | { |
Behdad Esfahbod | 00f6a8e | 2014-12-12 20:36:49 -0800 | [diff] [blame] | 3074 | TRACE_DISPATCH (this, u.format); |
Behdad Esfahbod | f396fbb | 2015-10-09 12:25:55 -0400 | [diff] [blame] | 3075 | if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 3076 | switch (u.format) { |
Behdad Esfahbod | 36bb24f | 2019-05-05 10:14:17 -0700 | [diff] [blame] | 3077 | case 1: return_trace (c->dispatch (u.format1, hb_forward<Ts> (ds)...)); |
| 3078 | case 2: return_trace (c->dispatch (u.format2, hb_forward<Ts> (ds)...)); |
| 3079 | case 3: return_trace (c->dispatch (u.format3, hb_forward<Ts> (ds)...)); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 3080 | default:return_trace (c->default_return_value ()); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 3084 | protected: |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 3085 | union { |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 3086 | HBUINT16 format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 3087 | ChainContextFormat1 format1; |
| 3088 | ChainContextFormat2 format2; |
| 3089 | ChainContextFormat3 format3; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 3090 | } u; |
| 3091 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 3092 | |
| 3093 | |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3094 | template <typename T> |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3095 | struct ExtensionFormat1 |
| 3096 | { |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3097 | unsigned int get_type () const { return extensionLookupType; } |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3098 | |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3099 | template <typename X> |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3100 | const X& get_subtable () const |
Behdad Esfahbod | 858b627 | 2019-12-10 13:18:32 -0600 | [diff] [blame] | 3101 | { return this + reinterpret_cast<const LOffsetTo<typename T::SubTable> &> (extensionOffset); } |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3102 | |
Behdad Esfahbod | 36bb24f | 2019-05-05 10:14:17 -0700 | [diff] [blame] | 3103 | template <typename context_t, typename ...Ts> |
Behdad Esfahbod | 83e3eab | 2019-05-07 20:58:43 -0700 | [diff] [blame] | 3104 | typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3105 | { |
| 3106 | TRACE_DISPATCH (this, format); |
Behdad Esfahbod | f396fbb | 2015-10-09 12:25:55 -0400 | [diff] [blame] | 3107 | if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ()); |
Behdad Esfahbod | 36bb24f | 2019-05-05 10:14:17 -0700 | [diff] [blame] | 3108 | return_trace (get_subtable<typename T::SubTable> ().dispatch (c, get_type (), hb_forward<Ts> (ds)...)); |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3109 | } |
| 3110 | |
Qunxin Liu | 8200e48 | 2020-02-26 13:11:42 -0800 | [diff] [blame] | 3111 | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const |
| 3112 | { dispatch (c); } |
| 3113 | |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3114 | /* This is called from may_dispatch() above with hb_sanitize_context_t. */ |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3115 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 3116 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 3117 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 949f6af | 2018-01-15 20:44:10 -0500 | [diff] [blame] | 3118 | return_trace (c->check_struct (this) && |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 3119 | extensionLookupType != T::SubTable::Extension); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 3120 | } |
| 3121 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 3122 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 3123 | HBUINT16 format; /* Format identifier. Set to 1. */ |
| 3124 | HBUINT16 extensionLookupType; /* Lookup type of subtable referenced |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3125 | * by ExtensionOffset (i.e. the |
| 3126 | * extension subtable). */ |
Behdad Esfahbod | cd9bc73 | 2019-05-10 13:17:41 -0700 | [diff] [blame] | 3127 | Offset32 extensionOffset; /* Offset to the extension subtable, |
Behdad Esfahbod | 81f2af4 | 2010-04-22 00:58:49 -0400 | [diff] [blame] | 3128 | * of lookup type subtable. */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 3129 | public: |
| 3130 | DEFINE_SIZE_STATIC (8); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3131 | }; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3132 | |
Behdad Esfahbod | 653eeb2 | 2012-11-23 16:57:36 -0500 | [diff] [blame] | 3133 | template <typename T> |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3134 | struct Extension |
| 3135 | { |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3136 | unsigned int get_type () const |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3137 | { |
| 3138 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 3139 | case 1: return u.format1.get_type (); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3140 | default:return 0; |
| 3141 | } |
| 3142 | } |
Behdad Esfahbod | 7dddd4e | 2012-11-23 17:04:55 -0500 | [diff] [blame] | 3143 | template <typename X> |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3144 | const X& get_subtable () const |
Behdad Esfahbod | 7dddd4e | 2012-11-23 17:04:55 -0500 | [diff] [blame] | 3145 | { |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3146 | switch (u.format) { |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 3147 | case 1: return u.format1.template get_subtable<typename T::SubTable> (); |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 3148 | default:return Null (typename T::SubTable); |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3149 | } |
Behdad Esfahbod | 7dddd4e | 2012-11-23 17:04:55 -0500 | [diff] [blame] | 3150 | } |
| 3151 | |
Behdad Esfahbod | 36bb24f | 2019-05-05 10:14:17 -0700 | [diff] [blame] | 3152 | template <typename context_t, typename ...Ts> |
Behdad Esfahbod | 83e3eab | 2019-05-07 20:58:43 -0700 | [diff] [blame] | 3153 | typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const |
Behdad Esfahbod | 653eeb2 | 2012-11-23 16:57:36 -0500 | [diff] [blame] | 3154 | { |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3155 | TRACE_DISPATCH (this, u.format); |
Behdad Esfahbod | f396fbb | 2015-10-09 12:25:55 -0400 | [diff] [blame] | 3156 | if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 3157 | switch (u.format) { |
Behdad Esfahbod | 36bb24f | 2019-05-05 10:14:17 -0700 | [diff] [blame] | 3158 | case 1: return_trace (u.format1.dispatch (c, hb_forward<Ts> (ds)...)); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 3159 | default:return_trace (c->default_return_value ()); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 3160 | } |
| 3161 | } |
| 3162 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 3163 | protected: |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3164 | union { |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 3165 | HBUINT16 format; /* Format identifier */ |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 3166 | ExtensionFormat1<T> format1; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3167 | } u; |
| 3168 | }; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 3169 | |
| 3170 | |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 3171 | /* |
| 3172 | * GSUB/GPOS Common |
| 3173 | */ |
| 3174 | |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 3175 | struct hb_ot_layout_lookup_accelerator_t |
| 3176 | { |
| 3177 | template <typename TLookup> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3178 | void init (const TLookup &lookup) |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 3179 | { |
| 3180 | digest.init (); |
Behdad Esfahbod | 5cf53c0 | 2020-04-23 10:55:41 -0700 | [diff] [blame] | 3181 | lookup.collect_coverage (&digest); |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 3182 | |
| 3183 | subtables.init (); |
| 3184 | OT::hb_get_subtables_context_t c_get_subtables (subtables); |
| 3185 | lookup.dispatch (&c_get_subtables); |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 3186 | } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3187 | void fini () { subtables.fini (); } |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 3188 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3189 | bool may_have (hb_codepoint_t g) const |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 3190 | { return digest.may_have (g); } |
| 3191 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3192 | bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | e78549e | 2018-10-10 11:54:48 -0400 | [diff] [blame] | 3193 | { |
Behdad Esfahbod | 474a120 | 2018-12-21 18:46:51 -0500 | [diff] [blame] | 3194 | for (unsigned int i = 0; i < subtables.length; i++) |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 3195 | if (subtables[i].apply (c)) |
| 3196 | return true; |
| 3197 | return false; |
Behdad Esfahbod | e78549e | 2018-10-10 11:54:48 -0400 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | private: |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 3201 | hb_set_digest_t digest; |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 3202 | hb_get_subtables_context_t::array_t subtables; |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 3203 | }; |
| 3204 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 3205 | struct GSUBGPOS |
| 3206 | { |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3207 | bool has_data () const { return version.to_int (); } |
| 3208 | unsigned int get_script_count () const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3209 | { return (this+scriptList).len; } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3210 | const Tag& get_script_tag (unsigned int i) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3211 | { return (this+scriptList).get_tag (i); } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3212 | unsigned int get_script_tags (unsigned int start_offset, |
| 3213 | unsigned int *script_count /* IN/OUT */, |
| 3214 | hb_tag_t *script_tags /* OUT */) const |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 3215 | { return (this+scriptList).get_tags (start_offset, script_count, script_tags); } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3216 | const Script& get_script (unsigned int i) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3217 | { return (this+scriptList)[i]; } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3218 | bool find_script_index (hb_tag_t tag, unsigned int *index) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3219 | { return (this+scriptList).find_index (tag, index); } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 3220 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3221 | unsigned int get_feature_count () const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3222 | { return (this+featureList).len; } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3223 | hb_tag_t get_feature_tag (unsigned int i) const |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 3224 | { return i == Index::NOT_FOUND_INDEX ? HB_TAG_NONE : (this+featureList).get_tag (i); } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3225 | unsigned int get_feature_tags (unsigned int start_offset, |
| 3226 | unsigned int *feature_count /* IN/OUT */, |
| 3227 | hb_tag_t *feature_tags /* OUT */) const |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 3228 | { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3229 | const Feature& get_feature (unsigned int i) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3230 | { return (this+featureList)[i]; } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3231 | bool find_feature_index (hb_tag_t tag, unsigned int *index) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3232 | { return (this+featureList).find_index (tag, index); } |
| 3233 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3234 | unsigned int get_lookup_count () const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3235 | { return (this+lookupList).len; } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3236 | const Lookup& get_lookup (unsigned int i) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 3237 | { return (this+lookupList)[i]; } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 3238 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3239 | bool find_variations_index (const int *coords, unsigned int num_coords, |
| 3240 | unsigned int *index) const |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3241 | { |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 3242 | #ifdef HB_NO_VAR |
Ebrahim Byagowi | 2e1bf61 | 2020-03-26 22:59:26 +0430 | [diff] [blame] | 3243 | *index = FeatureVariations::NOT_FOUND_INDEX; |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3244 | return false; |
| 3245 | #endif |
Ebrahim Byagowi | 071e2e3 | 2020-03-26 12:01:53 +0430 | [diff] [blame] | 3246 | return (version.to_int () >= 0x00010001u ? this+featureVars : Null (FeatureVariations)) |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3247 | .find_index (coords, num_coords, index); |
| 3248 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3249 | const Feature& get_feature_variation (unsigned int feature_index, |
Behdad Esfahbod | 3d9a6e6 | 2019-01-22 12:02:06 +0100 | [diff] [blame] | 3250 | unsigned int variations_index) const |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 3251 | { |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3252 | #ifndef HB_NO_VAR |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 3253 | if (FeatureVariations::NOT_FOUND_INDEX != variations_index && |
| 3254 | version.to_int () >= 0x00010001u) |
| 3255 | { |
Behdad Esfahbod | 4ebbeb7 | 2016-09-10 04:52:34 -0700 | [diff] [blame] | 3256 | const Feature *feature = (this+featureVars).find_substitute (variations_index, |
| 3257 | feature_index); |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 3258 | if (feature) |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 3259 | return *feature; |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 3260 | } |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3261 | #endif |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 3262 | return get_feature (feature_index); |
| 3263 | } |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 3264 | |
Qunxin Liu | 0b39c48 | 2019-10-22 16:00:43 -0700 | [diff] [blame] | 3265 | void feature_variation_collect_lookups (const hb_set_t *feature_indexes, |
| 3266 | hb_set_t *lookup_indexes /* OUT */) const |
| 3267 | { |
| 3268 | #ifndef HB_NO_VAR |
| 3269 | if (version.to_int () >= 0x00010001u) |
| 3270 | (this+featureVars).collect_lookups (feature_indexes, lookup_indexes); |
| 3271 | #endif |
| 3272 | } |
| 3273 | |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 3274 | template <typename TLookup> |
Qunxin Liu | 973c47f | 2020-06-11 11:27:57 -0700 | [diff] [blame] | 3275 | void closure_lookups (hb_face_t *face, |
| 3276 | const hb_set_t *glyphs, |
Ebrahim Byagowi | 5a7cc7f | 2020-07-29 08:33:32 +0430 | [diff] [blame] | 3277 | hb_set_t *lookup_indexes /* IN/OUT */) const |
Qunxin Liu | 973c47f | 2020-06-11 11:27:57 -0700 | [diff] [blame] | 3278 | { |
| 3279 | hb_set_t visited_lookups, inactive_lookups; |
| 3280 | OT::hb_closure_lookups_context_t c (face, glyphs, &visited_lookups, &inactive_lookups); |
| 3281 | |
| 3282 | for (unsigned lookup_index : + hb_iter (lookup_indexes)) |
| 3283 | reinterpret_cast<const TLookup &> (get_lookup (lookup_index)).closure_lookups (&c, lookup_index); |
| 3284 | |
| 3285 | hb_set_union (lookup_indexes, &visited_lookups); |
| 3286 | hb_set_subtract (lookup_indexes, &inactive_lookups); |
| 3287 | } |
| 3288 | |
| 3289 | template <typename TLookup> |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3290 | bool subset (hb_subset_layout_context_t *c) const |
Behdad Esfahbod | bfa72a9 | 2018-09-01 18:34:50 -0700 | [diff] [blame] | 3291 | { |
| 3292 | TRACE_SUBSET (this); |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3293 | auto *out = c->subset_context->serializer->embed (*this); |
Behdad Esfahbod | bfa72a9 | 2018-09-01 18:34:50 -0700 | [diff] [blame] | 3294 | if (unlikely (!out)) return_trace (false); |
Behdad Esfahbod | 1b6d0c4 | 2018-12-13 18:10:48 -0500 | [diff] [blame] | 3295 | |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3296 | typedef LookupOffsetList<TLookup> TLookupList; |
Behdad Esfahbod | 858b627 | 2019-12-10 13:18:32 -0600 | [diff] [blame] | 3297 | reinterpret_cast<OffsetTo<TLookupList> &> (out->lookupList) |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 3298 | .serialize_subset (c->subset_context, |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3299 | reinterpret_cast<const OffsetTo<TLookupList> &> (lookupList), |
| 3300 | this, |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3301 | c); |
| 3302 | |
| 3303 | reinterpret_cast<OffsetTo<RecordListOfFeature> &> (out->featureList) |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 3304 | .serialize_subset (c->subset_context, |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3305 | reinterpret_cast<const OffsetTo<RecordListOfFeature> &> (featureList), |
| 3306 | this, |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3307 | c); |
| 3308 | |
| 3309 | out->scriptList.serialize_subset (c->subset_context, |
| 3310 | scriptList, |
| 3311 | this, |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3312 | c); |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 3313 | |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3314 | #ifndef HB_NO_VAR |
Behdad Esfahbod | bfa72a9 | 2018-09-01 18:34:50 -0700 | [diff] [blame] | 3315 | if (version.to_int () >= 0x00010001u) |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3316 | { |
ariza | 188a0a4 | 2020-03-07 11:02:36 -0800 | [diff] [blame] | 3317 | bool ret = out->featureVars.serialize_subset (c->subset_context, featureVars, this, c); |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3318 | if (!ret) |
| 3319 | { |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 3320 | out->version.major = 1; |
| 3321 | out->version.minor = 0; |
Qunxin Liu | e565d1f | 2019-11-01 10:21:36 -0700 | [diff] [blame] | 3322 | } |
| 3323 | } |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3324 | #endif |
Behdad Esfahbod | 1b6d0c4 | 2018-12-13 18:10:48 -0500 | [diff] [blame] | 3325 | |
Behdad Esfahbod | bfa72a9 | 2018-09-01 18:34:50 -0700 | [diff] [blame] | 3326 | return_trace (true); |
| 3327 | } |
| 3328 | |
Qunxin Liu | 8ffc9ad | 2019-10-31 15:59:02 -0700 | [diff] [blame] | 3329 | void closure_features (const hb_map_t *lookup_indexes, /* IN */ |
| 3330 | hb_set_t *feature_indexes /* OUT */) const |
| 3331 | { |
Garret Rieger | 414529e | 2020-02-28 15:15:55 -0800 | [diff] [blame] | 3332 | unsigned int feature_count = hb_min (get_feature_count (), (unsigned) HB_MAX_FEATURES); |
Garret Rieger | 75622b0 | 2020-02-28 14:11:48 -0800 | [diff] [blame] | 3333 | for (unsigned i = 0; i < feature_count; i++) |
Qunxin Liu | 8ffc9ad | 2019-10-31 15:59:02 -0700 | [diff] [blame] | 3334 | { |
Qunxin Liu | d7c012a | 2020-02-26 13:11:42 -0800 | [diff] [blame] | 3335 | const Feature& f = get_feature (i); |
| 3336 | if ((!f.featureParams.is_null ()) || f.intersects_lookup_indexes (lookup_indexes)) |
Ebrahim Byagowi | 5a7cc7f | 2020-07-29 08:33:32 +0430 | [diff] [blame] | 3337 | feature_indexes->add (i); |
Qunxin Liu | 8ffc9ad | 2019-10-31 15:59:02 -0700 | [diff] [blame] | 3338 | } |
| 3339 | #ifndef HB_NO_VAR |
| 3340 | if (version.to_int () >= 0x00010001u) |
| 3341 | (this+featureVars).closure_features (lookup_indexes, feature_indexes); |
| 3342 | #endif |
| 3343 | } |
| 3344 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3345 | unsigned int get_size () const |
Behdad Esfahbod | bfa72a9 | 2018-09-01 18:34:50 -0700 | [diff] [blame] | 3346 | { |
| 3347 | return min_size + |
| 3348 | (version.to_int () >= 0x00010001u ? featureVars.static_size : 0); |
| 3349 | } |
| 3350 | |
Behdad Esfahbod | 6d61852 | 2018-09-03 16:41:28 -0700 | [diff] [blame] | 3351 | template <typename TLookup> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3352 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 3353 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 3354 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 6d61852 | 2018-09-03 16:41:28 -0700 | [diff] [blame] | 3355 | typedef OffsetListOf<TLookup> TLookupList; |
Behdad Esfahbod | 8e3cde6 | 2019-06-19 19:58:24 -0700 | [diff] [blame] | 3356 | if (unlikely (!(version.sanitize (c) && |
| 3357 | likely (version.major == 1) && |
| 3358 | scriptList.sanitize (c, this) && |
| 3359 | featureList.sanitize (c, this) && |
Behdad Esfahbod | 858b627 | 2019-12-10 13:18:32 -0600 | [diff] [blame] | 3360 | reinterpret_cast<const OffsetTo<TLookupList> &> (lookupList).sanitize (c, this)))) |
Behdad Esfahbod | 8e3cde6 | 2019-06-19 19:58:24 -0700 | [diff] [blame] | 3361 | return_trace (false); |
| 3362 | |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3363 | #ifndef HB_NO_VAR |
Behdad Esfahbod | 8e3cde6 | 2019-06-19 19:58:24 -0700 | [diff] [blame] | 3364 | if (unlikely (!(version.to_int () < 0x00010001u || featureVars.sanitize (c, this)))) |
| 3365 | return_trace (false); |
Behdad Esfahbod | a849873 | 2019-06-19 19:26:22 -0700 | [diff] [blame] | 3366 | #endif |
Behdad Esfahbod | 8e3cde6 | 2019-06-19 19:58:24 -0700 | [diff] [blame] | 3367 | |
| 3368 | return_trace (true); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 3369 | } |
| 3370 | |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3371 | template <typename T> |
| 3372 | struct accelerator_t |
| 3373 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 3374 | void init (hb_face_t *face) |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3375 | { |
Ebrahim Byagowi | ba22df3 | 2020-03-10 10:42:20 +0330 | [diff] [blame] | 3376 | this->table = hb_sanitize_context_t ().reference_table<T> (face); |
Behdad Esfahbod | 5671947 | 2020-06-05 12:57:23 -0700 | [diff] [blame] | 3377 | if (unlikely (this->table->is_blocklisted (this->table.get_blob (), face))) |
Behdad Esfahbod | 574d888 | 2018-11-25 16:51:22 -0500 | [diff] [blame] | 3378 | { |
| 3379 | hb_blob_destroy (this->table.get_blob ()); |
| 3380 | this->table = hb_blob_get_empty (); |
| 3381 | } |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3382 | |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 3383 | this->lookup_count = table->get_lookup_count (); |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3384 | |
| 3385 | this->accels = (hb_ot_layout_lookup_accelerator_t *) calloc (this->lookup_count, sizeof (hb_ot_layout_lookup_accelerator_t)); |
| 3386 | if (unlikely (!this->accels)) |
Dominik Röttsches | a5f6f86 | 2020-10-23 14:25:05 +0300 | [diff] [blame] | 3387 | { |
Ebrahim Byagowi | 11aa046 | 2018-11-15 23:10:56 +0330 | [diff] [blame] | 3388 | this->lookup_count = 0; |
Behdad Esfahbod | 53806e5 | 2020-11-25 11:51:37 -0700 | [diff] [blame] | 3389 | this->table.destroy (); |
Dominik Röttsches | a5f6f86 | 2020-10-23 14:25:05 +0300 | [diff] [blame] | 3390 | this->table = hb_blob_get_empty (); |
| 3391 | } |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3392 | |
| 3393 | for (unsigned int i = 0; i < this->lookup_count; i++) |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 3394 | this->accels[i].init (table->get_lookup (i)); |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 3397 | void fini () |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3398 | { |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 3399 | for (unsigned int i = 0; i < this->lookup_count; i++) |
| 3400 | this->accels[i].fini (); |
| 3401 | free (this->accels); |
Behdad Esfahbod | da6aa3b | 2018-11-11 11:40:57 -0500 | [diff] [blame] | 3402 | this->table.destroy (); |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
Behdad Esfahbod | 5d0078a | 2018-11-10 23:52:15 -0500 | [diff] [blame] | 3405 | hb_blob_ptr_t<T> table; |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 3406 | unsigned int lookup_count; |
| 3407 | hb_ot_layout_lookup_accelerator_t *accels; |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 3408 | }; |
| 3409 | |
Behdad Esfahbod | 212aba6 | 2009-05-24 00:50:27 -0400 | [diff] [blame] | 3410 | protected: |
Behdad Esfahbod | 9a13ed4 | 2016-02-22 11:44:45 +0900 | [diff] [blame] | 3411 | FixedVersion<>version; /* Version of the GSUB/GPOS table--initially set |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 3412 | * to 0x00010000u */ |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 3413 | OffsetTo<ScriptList> |
Ebrahim Byagowi | ce114d6 | 2019-12-31 15:53:02 +0330 | [diff] [blame] | 3414 | scriptList; /* ScriptList table */ |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 3415 | OffsetTo<FeatureList> |
Ebrahim Byagowi | ce114d6 | 2019-12-31 15:53:02 +0330 | [diff] [blame] | 3416 | featureList; /* FeatureList table */ |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 3417 | OffsetTo<LookupList> |
Ebrahim Byagowi | ce114d6 | 2019-12-31 15:53:02 +0330 | [diff] [blame] | 3418 | lookupList; /* LookupList table */ |
Behdad Esfahbod | 5e156fa | 2017-01-22 20:28:56 -0800 | [diff] [blame] | 3419 | LOffsetTo<FeatureVariations> |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 3420 | featureVars; /* Offset to Feature Variations |
| 3421 | table--from beginning of table |
| 3422 | * (may be NULL). Introduced |
| 3423 | * in version 0x00010001. */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 3424 | public: |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 3425 | DEFINE_SIZE_MIN (10); |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 3426 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 3427 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 3428 | |
Behdad Esfahbod | 7d52e66 | 2012-11-16 18:49:54 -0800 | [diff] [blame] | 3429 | } /* namespace OT */ |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 3430 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 3431 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 3432 | #endif /* HB_OT_LAYOUT_GSUBGPOS_HH */ |