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 : |
| 45 | hb_dispatch_context_t<hb_intersects_context_t, bool, 0> |
| 46 | { |
| 47 | inline const char *get_name (void) { return "INTERSECTS"; } |
| 48 | template <typename T> |
| 49 | inline return_t dispatch (const T &obj) { return obj.intersects (this->glyphs); } |
| 50 | static return_t default_return_value (void) { return false; } |
| 51 | bool stop_sublookup_iteration (return_t r) const { return r; } |
| 52 | |
| 53 | const hb_set_t *glyphs; |
| 54 | unsigned int debug_depth; |
| 55 | |
| 56 | hb_intersects_context_t (const hb_set_t *glyphs_) : |
| 57 | glyphs (glyphs_), |
| 58 | debug_depth (0) {} |
| 59 | }; |
| 60 | |
Behdad Esfahbod | 77a1a2b | 2015-10-09 12:20:58 -0400 | [diff] [blame] | 61 | struct hb_closure_context_t : |
| 62 | hb_dispatch_context_t<hb_closure_context_t, hb_void_t, HB_DEBUG_CLOSURE> |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 63 | { |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 64 | inline const char *get_name (void) { return "CLOSURE"; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 65 | typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); |
| 66 | template <typename T> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 67 | inline return_t dispatch (const T &obj) { obj.closure (this); return HB_VOID; } |
Behdad Esfahbod | 130bb3f | 2012-12-05 16:49:47 -0500 | [diff] [blame] | 68 | static return_t default_return_value (void) { return HB_VOID; } |
Behdad Esfahbod | 7b912c1 | 2013-01-04 01:25:27 -0600 | [diff] [blame] | 69 | bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 70 | void recurse (unsigned int lookup_index) |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 71 | { |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 72 | if (unlikely (nesting_level_left == 0 || !recurse_func)) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 73 | return; |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 74 | |
| 75 | nesting_level_left--; |
| 76 | recurse_func (this, lookup_index); |
| 77 | nesting_level_left++; |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 78 | } |
| 79 | |
Behdad Esfahbod | ba0ea56 | 2018-06-11 23:24:41 -0400 | [diff] [blame] | 80 | bool should_visit_lookup (unsigned int lookup_index) |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 81 | { |
| 82 | if (is_lookup_done (lookup_index)) |
| 83 | return false; |
| 84 | done_lookups->set (lookup_index, glyphs->get_population ()); |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | bool is_lookup_done (unsigned int lookup_index) |
| 89 | { |
Behdad Esfahbod | c38bd40 | 2018-07-24 09:43:27 -0700 | [diff] [blame] | 90 | /* Have we visited this lookup with the current set of glyphs? */ |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 91 | return done_lookups->get (lookup_index) == glyphs->get_population (); |
| 92 | } |
| 93 | |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 94 | hb_face_t *face; |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 95 | hb_set_t *glyphs; |
Behdad Esfahbod | 6b11fea | 2018-07-25 16:01:37 -0700 | [diff] [blame] | 96 | hb_auto_t<hb_set_t> out[1]; |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 97 | recurse_func_t recurse_func; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 98 | unsigned int nesting_level_left; |
| 99 | unsigned int debug_depth; |
| 100 | |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 101 | hb_closure_context_t (hb_face_t *face_, |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 102 | hb_set_t *glyphs_, |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 103 | hb_map_t *done_lookups_, |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 104 | unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) : |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 105 | face (face_), |
| 106 | glyphs (glyphs_), |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 107 | recurse_func (nullptr), |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 108 | nesting_level_left (nesting_level_left_), |
Behdad Esfahbod | a7e1b4a | 2018-06-11 22:05:08 -0400 | [diff] [blame] | 109 | debug_depth (0), |
| 110 | done_lookups (done_lookups_) {} |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 111 | |
Behdad Esfahbod | c38bd40 | 2018-07-24 09:43:27 -0700 | [diff] [blame] | 112 | ~hb_closure_context_t (void) |
| 113 | { |
| 114 | flush (); |
Behdad Esfahbod | c38bd40 | 2018-07-24 09:43:27 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 117 | void set_recurse_func (recurse_func_t func) { recurse_func = func; } |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 118 | |
Behdad Esfahbod | c38bd40 | 2018-07-24 09:43:27 -0700 | [diff] [blame] | 119 | void flush (void) |
| 120 | { |
| 121 | hb_set_union (glyphs, out); |
| 122 | hb_set_clear (out); |
| 123 | } |
| 124 | |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 125 | private: |
| 126 | hb_map_t *done_lookups; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 127 | }; |
| 128 | |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 129 | |
Behdad Esfahbod | 77a1a2b | 2015-10-09 12:20:58 -0400 | [diff] [blame] | 130 | struct hb_would_apply_context_t : |
| 131 | hb_dispatch_context_t<hb_would_apply_context_t, bool, HB_DEBUG_WOULD_APPLY> |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 132 | { |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 133 | inline const char *get_name (void) { return "WOULD_APPLY"; } |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 134 | template <typename T> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 135 | inline return_t dispatch (const T &obj) { return obj.would_apply (this); } |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 136 | static return_t default_return_value (void) { return false; } |
Behdad Esfahbod | 7b912c1 | 2013-01-04 01:25:27 -0600 | [diff] [blame] | 137 | bool stop_sublookup_iteration (return_t r) const { return r; } |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 138 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 139 | hb_face_t *face; |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 140 | const hb_codepoint_t *glyphs; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 141 | unsigned int len; |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 142 | bool zero_context; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 143 | unsigned int debug_depth; |
| 144 | |
| 145 | hb_would_apply_context_t (hb_face_t *face_, |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 146 | const hb_codepoint_t *glyphs_, |
| 147 | unsigned int len_, |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 148 | bool zero_context_) : |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 149 | face (face_), |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 150 | glyphs (glyphs_), |
| 151 | len (len_), |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 152 | zero_context (zero_context_), |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 153 | debug_depth (0) {} |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | |
Behdad Esfahbod | 77a1a2b | 2015-10-09 12:20:58 -0400 | [diff] [blame] | 157 | struct hb_collect_glyphs_context_t : |
| 158 | hb_dispatch_context_t<hb_collect_glyphs_context_t, hb_void_t, HB_DEBUG_COLLECT_GLYPHS> |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 159 | { |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 160 | inline const char *get_name (void) { return "COLLECT_GLYPHS"; } |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 161 | 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] | 162 | template <typename T> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 163 | inline return_t dispatch (const T &obj) { obj.collect_glyphs (this); return HB_VOID; } |
Behdad Esfahbod | 130bb3f | 2012-12-05 16:49:47 -0500 | [diff] [blame] | 164 | static return_t default_return_value (void) { return HB_VOID; } |
Behdad Esfahbod | 7b912c1 | 2013-01-04 01:25:27 -0600 | [diff] [blame] | 165 | bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 166 | void recurse (unsigned int lookup_index) |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 167 | { |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 168 | if (unlikely (nesting_level_left == 0 || !recurse_func)) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 169 | return; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 170 | |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 171 | /* 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] | 172 | * 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] | 173 | * glyphs in the recursion. If output is not requested, we can go home now. |
| 174 | * |
| 175 | * Note further, that the above is not exactly correct. A recursed lookup |
| 176 | * is allowed to match input that is not matched in the context, but that's |
| 177 | * not how most fonts are built. It's possible to relax that and recurse |
| 178 | * with all sets here if it proves to be an issue. |
| 179 | */ |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 180 | |
| 181 | if (output == hb_set_get_empty ()) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 182 | return; |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 183 | |
Behdad Esfahbod | fde3e4a | 2014-10-29 11:23:08 -0700 | [diff] [blame] | 184 | /* Return if new lookup was recursed to before. */ |
Behdad Esfahbod | 8b9d9b7 | 2017-10-22 17:48:06 -0400 | [diff] [blame] | 185 | if (recursed_lookups->has (lookup_index)) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 186 | return; |
Behdad Esfahbod | fde3e4a | 2014-10-29 11:23:08 -0700 | [diff] [blame] | 187 | |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 188 | hb_set_t *old_before = before; |
| 189 | hb_set_t *old_input = input; |
| 190 | hb_set_t *old_after = after; |
| 191 | before = input = after = hb_set_get_empty (); |
Behdad Esfahbod | 1bcfa06 | 2012-12-04 16:58:09 -0500 | [diff] [blame] | 192 | |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 193 | nesting_level_left--; |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 194 | recurse_func (this, lookup_index); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 195 | nesting_level_left++; |
Behdad Esfahbod | 4a350d0 | 2012-12-04 17:13:09 -0500 | [diff] [blame] | 196 | |
| 197 | before = old_before; |
| 198 | input = old_input; |
| 199 | after = old_after; |
| 200 | |
Behdad Esfahbod | 8b9d9b7 | 2017-10-22 17:48:06 -0400 | [diff] [blame] | 201 | recursed_lookups->add (lookup_index); |
Behdad Esfahbod | fde3e4a | 2014-10-29 11:23:08 -0700 | [diff] [blame] | 202 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 203 | return; |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 204 | } |
| 205 | |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 206 | hb_face_t *face; |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 207 | hb_set_t *before; |
| 208 | hb_set_t *input; |
| 209 | hb_set_t *after; |
| 210 | hb_set_t *output; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 211 | recurse_func_t recurse_func; |
Behdad Esfahbod | 8b9d9b7 | 2017-10-22 17:48:06 -0400 | [diff] [blame] | 212 | hb_set_t *recursed_lookups; |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 213 | unsigned int nesting_level_left; |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 214 | unsigned int debug_depth; |
| 215 | |
| 216 | hb_collect_glyphs_context_t (hb_face_t *face_, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 217 | hb_set_t *glyphs_before, /* OUT. May be nullptr */ |
| 218 | hb_set_t *glyphs_input, /* OUT. May be nullptr */ |
| 219 | hb_set_t *glyphs_after, /* OUT. May be nullptr */ |
| 220 | hb_set_t *glyphs_output, /* OUT. May be nullptr */ |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 221 | unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) : |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 222 | face (face_), |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 223 | before (glyphs_before ? glyphs_before : hb_set_get_empty ()), |
| 224 | input (glyphs_input ? glyphs_input : hb_set_get_empty ()), |
| 225 | after (glyphs_after ? glyphs_after : hb_set_get_empty ()), |
| 226 | output (glyphs_output ? glyphs_output : hb_set_get_empty ()), |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 227 | recurse_func (nullptr), |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 228 | recursed_lookups (hb_set_create ()), |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 229 | nesting_level_left (nesting_level_left_), |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 230 | debug_depth (0) {} |
| 231 | ~hb_collect_glyphs_context_t (void) { hb_set_destroy (recursed_lookups); } |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 232 | |
| 233 | void set_recurse_func (recurse_func_t func) { recurse_func = func; } |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | |
| 237 | |
Behdad Esfahbod | 8e36ccf | 2015-02-17 19:15:34 +0300 | [diff] [blame] | 238 | template <typename set_t> |
Behdad Esfahbod | 77a1a2b | 2015-10-09 12:20:58 -0400 | [diff] [blame] | 239 | struct hb_add_coverage_context_t : |
| 240 | hb_dispatch_context_t<hb_add_coverage_context_t<set_t>, const Coverage &, HB_DEBUG_GET_COVERAGE> |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 241 | { |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 242 | inline const char *get_name (void) { return "GET_COVERAGE"; } |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 243 | typedef const Coverage &return_t; |
| 244 | template <typename T> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 245 | inline return_t dispatch (const T &obj) { return obj.get_coverage (); } |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 246 | static return_t default_return_value (void) { return Null(Coverage); } |
Behdad Esfahbod | 8e36ccf | 2015-02-17 19:15:34 +0300 | [diff] [blame] | 247 | bool stop_sublookup_iteration (return_t r) const |
| 248 | { |
| 249 | r.add_coverage (set); |
| 250 | return false; |
| 251 | } |
Behdad Esfahbod | 1d67ef9 | 2012-11-22 16:47:53 -0500 | [diff] [blame] | 252 | |
Behdad Esfahbod | 8e36ccf | 2015-02-17 19:15:34 +0300 | [diff] [blame] | 253 | hb_add_coverage_context_t (set_t *set_) : |
| 254 | set (set_), |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 255 | debug_depth (0) {} |
| 256 | |
Behdad Esfahbod | 8e36ccf | 2015-02-17 19:15:34 +0300 | [diff] [blame] | 257 | set_t *set; |
Behdad Esfahbod | a1733db | 2012-11-23 16:40:04 -0500 | [diff] [blame] | 258 | unsigned int debug_depth; |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 259 | }; |
| 260 | |
| 261 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 262 | struct hb_ot_apply_context_t : |
| 263 | 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] | 264 | { |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 265 | struct matcher_t |
| 266 | { |
| 267 | inline matcher_t (void) : |
| 268 | lookup_props (0), |
Behdad Esfahbod | cfc507c | 2013-02-14 10:40:12 -0500 | [diff] [blame] | 269 | ignore_zwnj (false), |
| 270 | ignore_zwj (false), |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 271 | mask (-1), |
| 272 | #define arg1(arg) (arg) /* Remove the macro to see why it's needed! */ |
| 273 | syllable arg1(0), |
| 274 | #undef arg1 |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 275 | match_func (nullptr), |
| 276 | match_data (nullptr) {}; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 277 | |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 278 | 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] | 279 | |
| 280 | inline void set_ignore_zwnj (bool ignore_zwnj_) { ignore_zwnj = ignore_zwnj_; } |
Behdad Esfahbod | 0b45479 | 2013-02-14 10:46:52 -0500 | [diff] [blame] | 281 | inline void set_ignore_zwj (bool ignore_zwj_) { ignore_zwj = ignore_zwj_; } |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 282 | inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; } |
| 283 | inline void set_mask (hb_mask_t mask_) { mask = mask_; } |
| 284 | inline void set_syllable (uint8_t syllable_) { syllable = syllable_; } |
| 285 | inline void set_match_func (match_func_t match_func_, |
| 286 | const void *match_data_) |
| 287 | { match_func = match_func_; match_data = match_data_; } |
| 288 | |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 289 | enum may_match_t { |
| 290 | MATCH_NO, |
| 291 | MATCH_YES, |
| 292 | MATCH_MAYBE |
| 293 | }; |
| 294 | |
| 295 | inline may_match_t may_match (const hb_glyph_info_t &info, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 296 | const HBUINT16 *glyph_data) const |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 297 | { |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 298 | if (!(info.mask & mask) || |
| 299 | (syllable && syllable != info.syllable ())) |
| 300 | return MATCH_NO; |
| 301 | |
| 302 | if (match_func) |
| 303 | return match_func (info.codepoint, *glyph_data, match_data) ? MATCH_YES : MATCH_NO; |
| 304 | |
| 305 | return MATCH_MAYBE; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | enum may_skip_t { |
| 309 | SKIP_NO, |
| 310 | SKIP_YES, |
| 311 | SKIP_MAYBE |
| 312 | }; |
| 313 | |
| 314 | inline may_skip_t |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 315 | may_skip (const hb_ot_apply_context_t *c, |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 316 | const hb_glyph_info_t &info) const |
| 317 | { |
Behdad Esfahbod | b98c5db | 2014-07-16 13:44:01 -0400 | [diff] [blame] | 318 | if (!c->check_glyph_property (&info, lookup_props)) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 319 | return SKIP_YES; |
| 320 | |
Khaled Hosny | 06cfe3f | 2017-05-17 21:32:47 +0300 | [diff] [blame] | 321 | if (unlikely (_hb_glyph_info_is_default_ignorable_and_not_hidden (&info) && |
Behdad Esfahbod | 0b45479 | 2013-02-14 10:46:52 -0500 | [diff] [blame] | 322 | (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info)) && |
Behdad Esfahbod | 4ba796b | 2015-07-22 17:41:31 +0100 | [diff] [blame] | 323 | (ignore_zwj || !_hb_glyph_info_is_zwj (&info)))) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 324 | return SKIP_MAYBE; |
| 325 | |
| 326 | return SKIP_NO; |
| 327 | } |
| 328 | |
| 329 | protected: |
| 330 | unsigned int lookup_props; |
| 331 | bool ignore_zwnj; |
Behdad Esfahbod | 0b45479 | 2013-02-14 10:46:52 -0500 | [diff] [blame] | 332 | bool ignore_zwj; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 333 | hb_mask_t mask; |
| 334 | uint8_t syllable; |
| 335 | match_func_t match_func; |
| 336 | const void *match_data; |
| 337 | }; |
| 338 | |
Behdad Esfahbod | 6962669 | 2015-01-29 13:08:41 +0100 | [diff] [blame] | 339 | struct skipping_iterator_t |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 340 | { |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 341 | inline void init (hb_ot_apply_context_t *c_, bool context_match = false) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 342 | { |
Behdad Esfahbod | 514564f | 2015-01-29 13:48:48 +0100 | [diff] [blame] | 343 | c = c_; |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 344 | match_glyph_data = nullptr; |
| 345 | matcher.set_match_func (nullptr, nullptr); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 346 | matcher.set_lookup_props (c->lookup_props); |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 347 | /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */ |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 348 | matcher.set_ignore_zwnj (c->table_index == 1 || (context_match && c->auto_zwnj)); |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 349 | /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */ |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 350 | matcher.set_ignore_zwj (c->table_index == 1 || (context_match || c->auto_zwj)); |
Behdad Esfahbod | 514564f | 2015-01-29 13:48:48 +0100 | [diff] [blame] | 351 | matcher.set_mask (context_match ? -1 : c->lookup_mask); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 352 | } |
Behdad Esfahbod | 514564f | 2015-01-29 13:48:48 +0100 | [diff] [blame] | 353 | inline void set_lookup_props (unsigned int lookup_props) |
| 354 | { |
| 355 | matcher.set_lookup_props (lookup_props); |
| 356 | } |
Behdad Esfahbod | 4a6b1ee | 2015-10-21 11:20:55 -0200 | [diff] [blame] | 357 | inline void set_match_func (matcher_t::match_func_t match_func_, |
| 358 | const void *match_data_, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 359 | const HBUINT16 glyph_data[]) |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 360 | { |
Behdad Esfahbod | 4a6b1ee | 2015-10-21 11:20:55 -0200 | [diff] [blame] | 361 | matcher.set_match_func (match_func_, match_data_); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 362 | match_glyph_data = glyph_data; |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 363 | } |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 364 | |
Behdad Esfahbod | b051be5 | 2015-01-29 13:40:39 +0100 | [diff] [blame] | 365 | inline void reset (unsigned int start_index_, |
| 366 | unsigned int num_items_) |
| 367 | { |
| 368 | idx = start_index_; |
| 369 | num_items = num_items_; |
| 370 | end = c->buffer->len; |
| 371 | matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0); |
| 372 | } |
| 373 | |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 374 | inline void reject (void) { num_items++; match_glyph_data--; } |
Behdad Esfahbod | 6962669 | 2015-01-29 13:08:41 +0100 | [diff] [blame] | 375 | |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 376 | inline matcher_t::may_skip_t |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 377 | may_skip (const hb_glyph_info_t &info) const |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 378 | { |
| 379 | return matcher.may_skip (c, info); |
| 380 | } |
| 381 | |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 382 | inline bool next (void) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 383 | { |
Behdad Esfahbod | 506ffeb | 2012-01-18 16:07:53 -0500 | [diff] [blame] | 384 | assert (num_items > 0); |
Behdad Esfahbod | 37d13ac | 2015-01-29 11:38:01 +0100 | [diff] [blame] | 385 | while (idx + num_items < end) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 386 | { |
Behdad Esfahbod | a4a48fe | 2012-01-17 18:08:41 -0500 | [diff] [blame] | 387 | idx++; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 388 | const hb_glyph_info_t &info = c->buffer->info[idx]; |
| 389 | |
Behdad Esfahbod | ff93ac8 | 2013-02-21 14:51:40 -0500 | [diff] [blame] | 390 | matcher_t::may_skip_t skip = matcher.may_skip (c, info); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 391 | if (unlikely (skip == matcher_t::SKIP_YES)) |
| 392 | continue; |
| 393 | |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 394 | 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] | 395 | if (match == matcher_t::MATCH_YES || |
| 396 | (match == matcher_t::MATCH_MAYBE && |
| 397 | skip == matcher_t::SKIP_NO)) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 398 | { |
| 399 | num_items--; |
| 400 | match_glyph_data++; |
| 401 | return true; |
| 402 | } |
| 403 | |
| 404 | if (skip == matcher_t::SKIP_NO) |
Behdad Esfahbod | 722e8b8 | 2013-02-21 15:37:51 -0500 | [diff] [blame] | 405 | return false; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 406 | } |
| 407 | return false; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 408 | } |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 409 | inline bool prev (void) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 410 | { |
Behdad Esfahbod | 506ffeb | 2012-01-18 16:07:53 -0500 | [diff] [blame] | 411 | assert (num_items > 0); |
Behdad Esfahbod | 18a06f8 | 2018-07-05 14:03:48 +0430 | [diff] [blame] | 412 | while (idx > num_items - 1) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 413 | { |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 414 | idx--; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 415 | const hb_glyph_info_t &info = c->buffer->out_info[idx]; |
| 416 | |
Behdad Esfahbod | ff93ac8 | 2013-02-21 14:51:40 -0500 | [diff] [blame] | 417 | matcher_t::may_skip_t skip = matcher.may_skip (c, info); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 418 | if (unlikely (skip == matcher_t::SKIP_YES)) |
| 419 | continue; |
| 420 | |
Behdad Esfahbod | 2b2a6e8 | 2013-02-21 15:07:03 -0500 | [diff] [blame] | 421 | 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] | 422 | if (match == matcher_t::MATCH_YES || |
| 423 | (match == matcher_t::MATCH_MAYBE && |
| 424 | skip == matcher_t::SKIP_NO)) |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 425 | { |
| 426 | num_items--; |
| 427 | match_glyph_data++; |
| 428 | return true; |
| 429 | } |
| 430 | |
| 431 | if (skip == matcher_t::SKIP_NO) |
Behdad Esfahbod | 722e8b8 | 2013-02-21 15:37:51 -0500 | [diff] [blame] | 432 | return false; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 433 | } |
| 434 | return false; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 435 | } |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 436 | |
| 437 | unsigned int idx; |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 438 | protected: |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 439 | hb_ot_apply_context_t *c; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 440 | matcher_t matcher; |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 441 | const HBUINT16 *match_glyph_data; |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 442 | |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 443 | unsigned int num_items; |
Behdad Esfahbod | 6962669 | 2015-01-29 13:08:41 +0100 | [diff] [blame] | 444 | unsigned int end; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 445 | }; |
| 446 | |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 447 | |
| 448 | inline const char *get_name (void) { return "APPLY"; } |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 449 | 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] | 450 | template <typename T> |
| 451 | inline return_t dispatch (const T &obj) { return obj.apply (this); } |
| 452 | static return_t default_return_value (void) { return false; } |
| 453 | bool stop_sublookup_iteration (return_t r) const { return r; } |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 454 | return_t recurse (unsigned int sub_lookup_index) |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 455 | { |
Behdad Esfahbod | baf7779 | 2017-11-14 21:53:48 -0800 | [diff] [blame] | 456 | if (unlikely (nesting_level_left == 0 || !recurse_func || buffer->max_ops-- <= 0)) |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 457 | return default_return_value (); |
| 458 | |
| 459 | nesting_level_left--; |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 460 | bool ret = recurse_func (this, sub_lookup_index); |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 461 | nesting_level_left++; |
| 462 | return ret; |
| 463 | } |
| 464 | |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 465 | skipping_iterator_t iter_input, iter_context; |
| 466 | |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 467 | hb_font_t *font; |
| 468 | hb_face_t *face; |
| 469 | hb_buffer_t *buffer; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 470 | recurse_func_t recurse_func; |
| 471 | const GDEF &gdef; |
| 472 | const VariationStore &var_store; |
| 473 | |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 474 | hb_direction_t direction; |
| 475 | hb_mask_t lookup_mask; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 476 | unsigned int table_index; /* GSUB/GPOS */ |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 477 | unsigned int lookup_index; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 478 | unsigned int lookup_props; |
| 479 | unsigned int nesting_level_left; |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 480 | unsigned int debug_depth; |
| 481 | |
Behdad Esfahbod | 80de4bc | 2018-09-10 16:24:52 +0200 | [diff] [blame] | 482 | bool has_glyph_classes; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 483 | bool auto_zwnj; |
| 484 | bool auto_zwj; |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 485 | bool random; |
Behdad Esfahbod | 80de4bc | 2018-09-10 16:24:52 +0200 | [diff] [blame] | 486 | |
Behdad Esfahbod | cfdea88 | 2018-09-11 10:57:48 +0200 | [diff] [blame] | 487 | uint32_t random_state; |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 488 | |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 489 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 490 | hb_ot_apply_context_t (unsigned int table_index_, |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 491 | hb_font_t *font_, |
| 492 | hb_buffer_t *buffer_) : |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 493 | iter_input (), iter_context (), |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 494 | font (font_), face (font->face), buffer (buffer_), |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 495 | recurse_func (nullptr), |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 496 | gdef (_get_gdef (face)), |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 497 | var_store (gdef.get_var_store ()), |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 498 | direction (buffer_->props.direction), |
| 499 | lookup_mask (1), |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 500 | table_index (table_index_), |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 501 | lookup_index ((unsigned int) -1), |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 502 | lookup_props (0), |
| 503 | nesting_level_left (HB_MAX_NESTING_LEVEL), |
| 504 | debug_depth (0), |
Behdad Esfahbod | 80de4bc | 2018-09-10 16:24:52 +0200 | [diff] [blame] | 505 | has_glyph_classes (gdef.has_glyph_classes ()), |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 506 | auto_zwnj (true), |
| 507 | auto_zwj (true), |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 508 | random (false), |
Behdad Esfahbod | 80de4bc | 2018-09-10 16:24:52 +0200 | [diff] [blame] | 509 | random_state (1) {} |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 510 | |
Behdad Esfahbod | 9516cbd | 2018-09-23 22:00:34 -0400 | [diff] [blame^] | 511 | inline void reinit_iters (void) |
Behdad Esfahbod | 365576d | 2015-01-29 13:59:42 +0100 | [diff] [blame] | 512 | { |
Behdad Esfahbod | 365576d | 2015-01-29 13:59:42 +0100 | [diff] [blame] | 513 | iter_input.init (this, false); |
| 514 | iter_context.init (this, true); |
| 515 | } |
Behdad Esfahbod | 2cecc38 | 2015-01-29 13:32:05 +0100 | [diff] [blame] | 516 | |
Behdad Esfahbod | 9516cbd | 2018-09-23 22:00:34 -0400 | [diff] [blame^] | 517 | inline void set_lookup_mask (hb_mask_t mask) { lookup_mask = mask; } |
| 518 | inline void set_auto_zwj (bool auto_zwj_) { auto_zwj = auto_zwj_; reinit_iters (); } |
| 519 | inline void set_auto_zwnj (bool auto_zwnj_) { auto_zwnj = auto_zwnj_; reinit_iters (); } |
| 520 | inline void set_random (bool random_) { random = random_; } |
| 521 | inline void set_recurse_func (recurse_func_t func) { recurse_func = func; } |
| 522 | inline void set_lookup_index (unsigned int lookup_index_) { lookup_index = lookup_index_; } |
| 523 | inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; reinit_iters (); } |
| 524 | |
Behdad Esfahbod | 08260c7 | 2018-09-11 10:51:19 +0200 | [diff] [blame] | 525 | inline uint32_t random_number (void) |
| 526 | { |
Behdad Esfahbod | cfdea88 | 2018-09-11 10:57:48 +0200 | [diff] [blame] | 527 | /* http://www.cplusplus.com/reference/random/minstd_rand/ */ |
| 528 | random_state = random_state * 48271 % 2147483647; |
| 529 | return random_state; |
Behdad Esfahbod | 08260c7 | 2018-09-11 10:51:19 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 532 | inline bool |
| 533 | match_properties_mark (hb_codepoint_t glyph, |
| 534 | unsigned int glyph_props, |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 535 | unsigned int match_props) const |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 536 | { |
| 537 | /* If using mark filtering sets, the high short of |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 538 | * match_props has the set index. |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 539 | */ |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 540 | if (match_props & LookupFlag::UseMarkFilteringSet) |
| 541 | return gdef.mark_set_covers (match_props >> 16, glyph); |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 542 | |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 543 | /* The second byte of match_props has the meaning |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 544 | * "ignore marks of attachment type different than |
| 545 | * the attachment type specified." |
| 546 | */ |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 547 | if (match_props & LookupFlag::MarkAttachmentType) |
| 548 | return (match_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType); |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 549 | |
| 550 | return true; |
| 551 | } |
| 552 | |
| 553 | inline bool |
Behdad Esfahbod | b98c5db | 2014-07-16 13:44:01 -0400 | [diff] [blame] | 554 | check_glyph_property (const hb_glyph_info_t *info, |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 555 | unsigned int match_props) const |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 556 | { |
Behdad Esfahbod | b98c5db | 2014-07-16 13:44:01 -0400 | [diff] [blame] | 557 | hb_codepoint_t glyph = info->codepoint; |
| 558 | unsigned int glyph_props = _hb_glyph_info_get_glyph_props (info); |
| 559 | |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 560 | /* Not covered, if, for example, glyph class is ligature and |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 561 | * match_props includes LookupFlags::IgnoreLigatures |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 562 | */ |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 563 | if (glyph_props & match_props & LookupFlag::IgnoreFlags) |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 564 | return false; |
| 565 | |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 566 | if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) |
Behdad Esfahbod | b931e0b | 2015-04-08 14:39:00 -0700 | [diff] [blame] | 567 | return match_properties_mark (glyph, glyph_props, match_props); |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 568 | |
| 569 | return true; |
| 570 | } |
| 571 | |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 572 | inline void _set_glyph_props (hb_codepoint_t glyph_index, |
Behdad Esfahbod | 71b4c99 | 2013-10-28 00:20:59 +0100 | [diff] [blame] | 573 | unsigned int class_guess = 0, |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 574 | bool ligature = false, |
| 575 | bool component = false) const |
Behdad Esfahbod | 60da763 | 2012-07-16 16:13:32 -0400 | [diff] [blame] | 576 | { |
Behdad Esfahbod | 09675a8 | 2013-10-18 01:05:58 +0200 | [diff] [blame] | 577 | unsigned int add_in = _hb_glyph_info_get_glyph_props (&buffer->cur()) & |
| 578 | HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE; |
| 579 | add_in |= HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED; |
| 580 | if (ligature) |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 581 | { |
Behdad Esfahbod | 09675a8 | 2013-10-18 01:05:58 +0200 | [diff] [blame] | 582 | add_in |= HB_OT_LAYOUT_GLYPH_PROPS_LIGATED; |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 583 | /* In the only place that the MULTIPLIED bit is used, Uniscribe |
| 584 | * seems to only care about the "last" transformation between |
| 585 | * Ligature and Multiple substitions. Ie. if you ligate, expand, |
| 586 | * and ligate again, it forgives the multiplication and acts as |
| 587 | * if only ligation happened. As such, clear MULTIPLIED bit. |
| 588 | */ |
| 589 | add_in &= ~HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED; |
| 590 | } |
| 591 | if (component) |
| 592 | add_in |= HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED; |
Behdad Esfahbod | 2fca142 | 2012-07-30 18:46:41 -0400 | [diff] [blame] | 593 | if (likely (has_glyph_classes)) |
Behdad Esfahbod | 05ad6b5 | 2013-10-18 00:45:59 +0200 | [diff] [blame] | 594 | _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] | 595 | else if (class_guess) |
Behdad Esfahbod | 09675a8 | 2013-10-18 01:05:58 +0200 | [diff] [blame] | 596 | _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | class_guess); |
Behdad Esfahbod | 60da763 | 2012-07-16 16:13:32 -0400 | [diff] [blame] | 597 | } |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 598 | |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 599 | inline void replace_glyph (hb_codepoint_t glyph_index) const |
Behdad Esfahbod | 3ec77d6 | 2012-06-08 21:44:06 -0400 | [diff] [blame] | 600 | { |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 601 | _set_glyph_props (glyph_index); |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 602 | buffer->replace_glyph (glyph_index); |
| 603 | } |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 604 | inline void replace_glyph_inplace (hb_codepoint_t glyph_index) const |
Behdad Esfahbod | 7fbbf86 | 2012-07-30 18:36:42 -0400 | [diff] [blame] | 605 | { |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 606 | _set_glyph_props (glyph_index); |
Behdad Esfahbod | 7fbbf86 | 2012-07-30 18:36:42 -0400 | [diff] [blame] | 607 | buffer->cur().codepoint = glyph_index; |
| 608 | } |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 609 | inline void replace_glyph_with_ligature (hb_codepoint_t glyph_index, |
| 610 | unsigned int class_guess) const |
| 611 | { |
Behdad Esfahbod | 09675a8 | 2013-10-18 01:05:58 +0200 | [diff] [blame] | 612 | _set_glyph_props (glyph_index, class_guess, true); |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 613 | buffer->replace_glyph (glyph_index); |
| 614 | } |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 615 | inline void output_glyph_for_component (hb_codepoint_t glyph_index, |
| 616 | unsigned int class_guess) const |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 617 | { |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 618 | _set_glyph_props (glyph_index, class_guess, false, true); |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 619 | buffer->output_glyph (glyph_index); |
| 620 | } |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 621 | }; |
| 622 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 623 | |
Behdad Esfahbod | 94a23aa | 2010-05-05 01:13:09 -0400 | [diff] [blame] | 624 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 625 | 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] | 626 | typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const HBUINT16 &value, const void *data); |
| 627 | 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] | 628 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 629 | struct ContextClosureFuncs |
| 630 | { |
| 631 | intersects_func_t intersects; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 632 | }; |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 633 | struct ContextCollectGlyphsFuncs |
| 634 | { |
| 635 | collect_glyphs_func_t collect; |
| 636 | }; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 637 | struct ContextApplyFuncs |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 638 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 639 | match_func_t match; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 640 | }; |
| 641 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 642 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 643 | 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] | 644 | { |
| 645 | return glyphs->has (value); |
| 646 | } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 647 | 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] | 648 | { |
| 649 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
| 650 | return class_def.intersects_class (glyphs, value); |
| 651 | } |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 652 | 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] | 653 | { |
| 654 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
| 655 | return (data+coverage).intersects (glyphs); |
| 656 | } |
| 657 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 658 | static inline bool intersects_array (const hb_set_t *glyphs, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 659 | unsigned int count, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 660 | const HBUINT16 values[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 661 | intersects_func_t intersects_func, |
| 662 | const void *intersects_data) |
| 663 | { |
| 664 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 665 | if (likely (!intersects_func (glyphs, values[i], intersects_data))) |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 666 | return false; |
| 667 | return true; |
| 668 | } |
| 669 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 670 | |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 671 | 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] | 672 | { |
| 673 | glyphs->add (value); |
| 674 | } |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 675 | 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] | 676 | { |
| 677 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
Behdad Esfahbod | 71e6adf | 2017-12-16 11:07:37 -0500 | [diff] [blame] | 678 | class_def.add_class (glyphs, value); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 679 | } |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 680 | 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] | 681 | { |
| 682 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
| 683 | (data+coverage).add_coverage (glyphs); |
| 684 | } |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 685 | 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] | 686 | hb_set_t *glyphs, |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 687 | unsigned int count, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 688 | const HBUINT16 values[], |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 689 | collect_glyphs_func_t collect_func, |
| 690 | const void *collect_data) |
| 691 | { |
| 692 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 693 | collect_func (glyphs, values[i], collect_data); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 697 | 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] | 698 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 699 | return glyph_id == value; |
| 700 | } |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 701 | 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] | 702 | { |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 703 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 704 | return class_def.get_class (glyph_id) == value; |
| 705 | } |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 706 | 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] | 707 | { |
Behdad Esfahbod | 6b54c5d | 2009-05-18 18:30:25 -0400 | [diff] [blame] | 708 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 709 | return (data+coverage).get_coverage (glyph_id) != NOT_COVERED; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 710 | } |
| 711 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 712 | static inline bool would_match_input (hb_would_apply_context_t *c, |
| 713 | unsigned int count, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 714 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 715 | match_func_t match_func, |
| 716 | const void *match_data) |
| 717 | { |
| 718 | if (count != c->len) |
| 719 | return false; |
| 720 | |
| 721 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 722 | if (likely (!match_func (c->glyphs[i], input[i - 1], match_data))) |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 723 | return false; |
| 724 | |
| 725 | return true; |
| 726 | } |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 727 | static inline bool match_input (hb_ot_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 728 | unsigned int count, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 729 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 730 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 731 | const void *match_data, |
Behdad Esfahbod | 6cc136f | 2013-10-17 13:55:48 +0200 | [diff] [blame] | 732 | unsigned int *end_offset, |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 733 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 734 | bool *p_is_mark_ligature = nullptr, |
| 735 | unsigned int *p_total_component_count = nullptr) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 736 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 737 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 738 | |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 739 | if (unlikely (count > HB_MAX_CONTEXT_LENGTH)) return_trace (false); |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 740 | |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 741 | hb_buffer_t *buffer = c->buffer; |
| 742 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 743 | 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] | 744 | skippy_iter.reset (buffer->idx, count - 1); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 745 | skippy_iter.set_match_func (match_func, match_data, input); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 746 | |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 747 | /* |
| 748 | * This is perhaps the trickiest part of OpenType... Remarks: |
| 749 | * |
| 750 | * - If all components of the ligature were marks, we call this a mark ligature. |
| 751 | * |
| 752 | * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize |
| 753 | * it as a ligature glyph. |
| 754 | * |
| 755 | * - Ligatures cannot be formed across glyphs attached to different components |
| 756 | * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and |
| 757 | * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother. |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 758 | * However, it would be wrong to ligate that SHADDA,FATHA sequence. |
| 759 | * There are a couple of exceptions to this: |
| 760 | * |
| 761 | * o If a ligature tries ligating with marks that belong to it itself, go ahead, |
| 762 | * assuming that the font designer knows what they are doing (otherwise it can |
| 763 | * break Indic stuff when a matra wants to ligate with a conjunct, |
| 764 | * |
| 765 | * o If two marks want to ligate and they belong to different components of the |
| 766 | * same ligature glyph, and said ligature glyph is to be ignored according to |
| 767 | * mark-filtering rules, then allow. |
ebraminio | 7c6937e | 2017-11-20 14:49:22 -0500 | [diff] [blame] | 768 | * https://github.com/harfbuzz/harfbuzz/issues/545 |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 769 | */ |
| 770 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 771 | bool is_mark_ligature = _hb_glyph_info_is_mark (&buffer->cur()); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 772 | |
| 773 | unsigned int total_component_count = 0; |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 774 | total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->cur()); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 775 | |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 776 | unsigned int first_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); |
| 777 | 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] | 778 | |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 779 | enum { |
| 780 | LIGBASE_NOT_CHECKED, |
| 781 | LIGBASE_MAY_NOT_SKIP, |
| 782 | LIGBASE_MAY_SKIP |
| 783 | } ligbase = LIGBASE_NOT_CHECKED; |
| 784 | |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 785 | match_positions[0] = buffer->idx; |
Behdad Esfahbod | 370f03e | 2012-01-16 17:03:55 -0500 | [diff] [blame] | 786 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 787 | { |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 788 | if (!skippy_iter.next ()) return_trace (false); |
Behdad Esfahbod | 6cc136f | 2013-10-17 13:55:48 +0200 | [diff] [blame] | 789 | |
| 790 | match_positions[i] = skippy_iter.idx; |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 791 | |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 792 | unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]); |
| 793 | 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] | 794 | |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 795 | if (first_lig_id && first_lig_comp) |
| 796 | { |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 797 | /* If first component was attached to a previous ligature component, |
| 798 | * all subsequent components should be attached to the same ligature |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 799 | * component, otherwise we shouldn't ligate them... */ |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 800 | 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] | 801 | { |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 802 | /* ...unless, we are attached to a base ligature and that base |
| 803 | * ligature is ignorable. */ |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 804 | if (ligbase == LIGBASE_NOT_CHECKED) |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 805 | { |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 806 | bool found = false; |
| 807 | const hb_glyph_info_t *out = buffer->out_info; |
| 808 | unsigned int j = buffer->out_len; |
| 809 | 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] | 810 | { |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 811 | if (_hb_glyph_info_get_lig_comp (&out[j - 1]) == 0) |
| 812 | { |
| 813 | j--; |
| 814 | found = true; |
| 815 | break; |
| 816 | } |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 817 | j--; |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 818 | } |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 819 | |
Behdad Esfahbod | 12757b6 | 2018-01-26 18:14:05 -0800 | [diff] [blame] | 820 | 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] | 821 | ligbase = LIGBASE_MAY_SKIP; |
| 822 | else |
| 823 | ligbase = LIGBASE_MAY_NOT_SKIP; |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 824 | } |
| 825 | |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 826 | if (ligbase == LIGBASE_MAY_NOT_SKIP) |
Behdad Esfahbod | 8b2c94c | 2017-10-02 20:02:45 +0200 | [diff] [blame] | 827 | return_trace (false); |
| 828 | } |
| 829 | } |
| 830 | else |
Behdad Esfahbod | 621c49c | 2017-10-04 15:06:48 +0200 | [diff] [blame] | 831 | { |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 832 | /* If first component was NOT attached to a previous ligature component, |
| 833 | * all subsequent components should also NOT be attached to any ligature |
| 834 | * component, unless they are attached to the first component itself! */ |
| 835 | 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] | 836 | return_trace (false); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 837 | } |
| 838 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 839 | is_mark_ligature = is_mark_ligature && _hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx]); |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 840 | 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] | 841 | } |
| 842 | |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 843 | *end_offset = skippy_iter.idx - buffer->idx + 1; |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 844 | |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 845 | if (p_is_mark_ligature) |
| 846 | *p_is_mark_ligature = is_mark_ligature; |
| 847 | |
| 848 | if (p_total_component_count) |
| 849 | *p_total_component_count = total_component_count; |
| 850 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 851 | return_trace (true); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 852 | } |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 853 | static inline bool ligate_input (hb_ot_apply_context_t *c, |
Behdad Esfahbod | e714fe6 | 2013-10-17 13:49:51 +0200 | [diff] [blame] | 854 | unsigned int count, /* Including the first glyph */ |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 855 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */ |
Behdad Esfahbod | e714fe6 | 2013-10-17 13:49:51 +0200 | [diff] [blame] | 856 | unsigned int match_length, |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 857 | hb_codepoint_t lig_glyph, |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 858 | bool is_mark_ligature, |
| 859 | unsigned int total_component_count) |
| 860 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 861 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | e714fe6 | 2013-10-17 13:49:51 +0200 | [diff] [blame] | 862 | |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 863 | hb_buffer_t *buffer = c->buffer; |
| 864 | |
| 865 | buffer->merge_clusters (buffer->idx, buffer->idx + match_length); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 866 | |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 867 | /* |
| 868 | * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave |
| 869 | * the ligature to keep its old ligature id. This will allow it to attach to |
| 870 | * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH, |
| 871 | * and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a |
| 872 | * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature |
| 873 | * later, we don't want them to lose their ligature id/component, otherwise |
| 874 | * GPOS will fail to correctly position the mark ligature on top of the |
| 875 | * LAM,LAM,HEH ligature. See: |
| 876 | * https://bugzilla.gnome.org/show_bug.cgi?id=676343 |
| 877 | * |
| 878 | * - If a ligature is formed of components that some of which are also ligatures |
| 879 | * themselves, and those ligature components had marks attached to *their* |
| 880 | * components, we have to attach the marks to the new ligature component |
| 881 | * positions! Now *that*'s tricky! And these marks may be following the |
| 882 | * last component of the whole sequence, so we should loop forward looking |
| 883 | * for them and update them. |
| 884 | * |
| 885 | * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a |
| 886 | * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature |
| 887 | * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature |
| 888 | * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to |
| 889 | * the new ligature with a component value of 2. |
| 890 | * |
| 891 | * This in fact happened to a font... See: |
| 892 | * https://bugzilla.gnome.org/show_bug.cgi?id=437633 |
| 893 | */ |
| 894 | |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 895 | unsigned int klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE; |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 896 | unsigned int lig_id = is_mark_ligature ? 0 : _hb_allocate_lig_id (buffer); |
| 897 | unsigned int last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); |
| 898 | 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] | 899 | unsigned int components_so_far = last_num_components; |
| 900 | |
| 901 | if (!is_mark_ligature) |
Behdad Esfahbod | 7e08f12 | 2013-05-27 14:48:34 -0400 | [diff] [blame] | 902 | { |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 903 | _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] | 904 | 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] | 905 | { |
Behdad Esfahbod | 8259669 | 2015-11-02 17:44:05 -0800 | [diff] [blame] | 906 | _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] | 907 | } |
Behdad Esfahbod | 7e08f12 | 2013-05-27 14:48:34 -0400 | [diff] [blame] | 908 | } |
Behdad Esfahbod | a016174 | 2013-10-18 00:06:30 +0200 | [diff] [blame] | 909 | c->replace_glyph_with_ligature (lig_glyph, klass); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 910 | |
| 911 | for (unsigned int i = 1; i < count; i++) |
| 912 | { |
Behdad Esfahbod | 7185b27 | 2018-05-31 20:03:00 -0700 | [diff] [blame] | 913 | while (buffer->idx < match_positions[i] && buffer->successful) |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 914 | { |
| 915 | if (!is_mark_ligature) { |
Behdad Esfahbod | 2f02fc7 | 2015-12-17 15:21:14 +0000 | [diff] [blame] | 916 | unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->cur()); |
| 917 | if (this_comp == 0) |
Behdad Esfahbod | 100fbea | 2015-12-17 15:23:09 +0000 | [diff] [blame] | 918 | this_comp = last_num_components; |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 919 | unsigned int new_lig_comp = components_so_far - last_num_components + |
Behdad Esfahbod | 2f02fc7 | 2015-12-17 15:21:14 +0000 | [diff] [blame] | 920 | MIN (this_comp, last_num_components); |
| 921 | _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] | 922 | } |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 923 | buffer->next_glyph (); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 924 | } |
| 925 | |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 926 | last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); |
| 927 | last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur()); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 928 | components_so_far += last_num_components; |
| 929 | |
| 930 | /* Skip the base glyph */ |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 931 | buffer->idx++; |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | if (!is_mark_ligature && last_lig_id) { |
| 935 | /* Re-adjust components for any marks following. */ |
Behdad Esfahbod | 3c3df9c | 2013-10-17 13:58:31 +0200 | [diff] [blame] | 936 | for (unsigned int i = buffer->idx; i < buffer->len; i++) { |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 937 | if (last_lig_id == _hb_glyph_info_get_lig_id (&buffer->info[i])) { |
Behdad Esfahbod | 2f02fc7 | 2015-12-17 15:21:14 +0000 | [diff] [blame] | 938 | unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->info[i]); |
| 939 | if (!this_comp) |
| 940 | break; |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 941 | unsigned int new_lig_comp = components_so_far - last_num_components + |
Behdad Esfahbod | 2f02fc7 | 2015-12-17 15:21:14 +0000 | [diff] [blame] | 942 | MIN (this_comp, last_num_components); |
Behdad Esfahbod | 3ddf892 | 2013-10-18 00:02:43 +0200 | [diff] [blame] | 943 | _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] | 944 | } else |
| 945 | break; |
| 946 | } |
| 947 | } |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 948 | return_trace (true); |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 949 | } |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 950 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 951 | static inline bool match_backtrack (hb_ot_apply_context_t *c, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 952 | unsigned int count, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 953 | const HBUINT16 backtrack[], |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 954 | match_func_t match_func, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 955 | const void *match_data, |
| 956 | unsigned int *match_start) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 957 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 958 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 959 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 960 | 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] | 961 | skippy_iter.reset (c->buffer->backtrack_len (), count); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 962 | skippy_iter.set_match_func (match_func, match_data, backtrack); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 963 | |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame] | 964 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 965 | if (!skippy_iter.prev ()) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 966 | return_trace (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 967 | |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 968 | *match_start = skippy_iter.idx; |
| 969 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 970 | return_trace (true); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 971 | } |
| 972 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 973 | static inline bool match_lookahead (hb_ot_apply_context_t *c, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 974 | unsigned int count, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 975 | const HBUINT16 lookahead[], |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 976 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 977 | const void *match_data, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 978 | unsigned int offset, |
| 979 | unsigned int *end_index) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 980 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 981 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 982 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 983 | 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] | 984 | skippy_iter.reset (c->buffer->idx + offset - 1, count); |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 985 | skippy_iter.set_match_func (match_func, match_data, lookahead); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 986 | |
Behdad Esfahbod | 370f03e | 2012-01-16 17:03:55 -0500 | [diff] [blame] | 987 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 988 | if (!skippy_iter.next ()) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 989 | return_trace (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 990 | |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 991 | *end_index = skippy_iter.idx + 1; |
| 992 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 993 | return_trace (true); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 994 | } |
| 995 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 996 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 997 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 998 | struct LookupRecord |
| 999 | { |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1000 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1001 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1002 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1003 | return_trace (c->check_struct (this)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 1004 | } |
| 1005 | |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1006 | HBUINT16 sequenceIndex; /* Index into current glyph |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1007 | * sequence--first glyph = 0 */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1008 | HBUINT16 lookupListIndex; /* Lookup to apply to that |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1009 | * position--zero--based */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 1010 | public: |
| 1011 | DEFINE_SIZE_STATIC (4); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1012 | }; |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1013 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1014 | template <typename context_t> |
| 1015 | static inline void recurse_lookups (context_t *c, |
| 1016 | unsigned int lookupCount, |
| 1017 | const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */) |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1018 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1019 | for (unsigned int i = 0; i < lookupCount; i++) |
Behdad Esfahbod | 86522e4 | 2013-07-22 19:07:53 -0400 | [diff] [blame] | 1020 | c->recurse (lookupRecord[i].lookupListIndex); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1021 | } |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1022 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1023 | static inline bool apply_lookup (hb_ot_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 1024 | unsigned int count, /* Including the first glyph */ |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 1025 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */ |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 1026 | unsigned int lookupCount, |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1027 | const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ |
| 1028 | unsigned int match_length) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1029 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1030 | TRACE_APPLY (nullptr); |
Behdad Esfahbod | 902cc8a | 2012-11-23 15:06:59 -0500 | [diff] [blame] | 1031 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1032 | hb_buffer_t *buffer = c->buffer; |
jfkthame | 44f7d6e | 2017-02-17 03:03:24 +0000 | [diff] [blame] | 1033 | int end; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1034 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1035 | /* All positions are distance from beginning of *output* buffer. |
| 1036 | * Adjust. */ |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1037 | { |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1038 | unsigned int bl = buffer->backtrack_len (); |
| 1039 | end = bl + match_length; |
Behdad Esfahbod | 8751de5 | 2013-07-18 16:29:50 -0400 | [diff] [blame] | 1040 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1041 | int delta = bl - buffer->idx; |
| 1042 | /* Convert positions to new indexing. */ |
| 1043 | for (unsigned int j = 0; j < count; j++) |
| 1044 | match_positions[j] += delta; |
Behdad Esfahbod | 8820bb2 | 2013-02-14 07:41:03 -0500 | [diff] [blame] | 1045 | } |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 1046 | |
Behdad Esfahbod | 7185b27 | 2018-05-31 20:03:00 -0700 | [diff] [blame] | 1047 | for (unsigned int i = 0; i < lookupCount && buffer->successful; i++) |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1048 | { |
| 1049 | unsigned int idx = lookupRecord[i].sequenceIndex; |
| 1050 | if (idx >= count) |
| 1051 | continue; |
| 1052 | |
Behdad Esfahbod | 9cc1ed4 | 2015-11-19 12:39:09 -0800 | [diff] [blame] | 1053 | /* Don't recurse to ourself at same position. |
| 1054 | * Note that this test is too naive, it doesn't catch longer loops. */ |
| 1055 | if (idx == 0 && lookupRecord[i].lookupListIndex == c->lookup_index) |
| 1056 | continue; |
| 1057 | |
Behdad Esfahbod | e593072 | 2017-11-14 15:47:55 -0800 | [diff] [blame] | 1058 | if (unlikely (!buffer->move_to (match_positions[idx]))) |
| 1059 | break; |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1060 | |
Behdad Esfahbod | baf7779 | 2017-11-14 21:53:48 -0800 | [diff] [blame] | 1061 | if (unlikely (buffer->max_ops <= 0)) |
| 1062 | break; |
| 1063 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1064 | unsigned int orig_len = buffer->backtrack_len () + buffer->lookahead_len (); |
| 1065 | if (!c->recurse (lookupRecord[i].lookupListIndex)) |
| 1066 | continue; |
| 1067 | |
| 1068 | unsigned int new_len = buffer->backtrack_len () + buffer->lookahead_len (); |
| 1069 | int delta = new_len - orig_len; |
| 1070 | |
| 1071 | if (!delta) |
| 1072 | continue; |
| 1073 | |
Behdad Esfahbod | 9ac9af7 | 2017-03-05 13:51:01 -0800 | [diff] [blame] | 1074 | /* Recursed lookup changed buffer len. Adjust. |
| 1075 | * |
| 1076 | * TODO: |
| 1077 | * |
| 1078 | * Right now, if buffer length increased by n, we assume n new glyphs |
| 1079 | * were added right after the current position, and if buffer length |
| 1080 | * was decreased by n, we assume n match positions after the current |
| 1081 | * one where removed. The former (buffer length increased) case is |
| 1082 | * fine, but the decrease case can be improved in at least two ways, |
| 1083 | * both of which are significant: |
| 1084 | * |
| 1085 | * - If recursed-to lookup is MultipleSubst and buffer length |
| 1086 | * decreased, then it's current match position that was deleted, |
| 1087 | * NOT the one after it. |
| 1088 | * |
| 1089 | * - If buffer length was decreased by n, it does not necessarily |
| 1090 | * mean that n match positions where removed, as there might |
| 1091 | * have been marks and default-ignorables in the sequence. We |
| 1092 | * should instead drop match positions between current-position |
| 1093 | * and current-position + n instead. |
| 1094 | * |
| 1095 | * It should be possible to construct tests for both of these cases. |
| 1096 | */ |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1097 | |
jfkthame | 44f7d6e | 2017-02-17 03:03:24 +0000 | [diff] [blame] | 1098 | end += delta; |
Behdad Esfahbod | 47e7a18 | 2017-03-10 13:23:02 -0800 | [diff] [blame] | 1099 | if (end <= int (match_positions[idx])) |
Behdad Esfahbod | 359dead | 2016-05-06 16:19:19 +0100 | [diff] [blame] | 1100 | { |
Behdad Esfahbod | 4b4a1b9 | 2016-12-21 23:10:43 -0600 | [diff] [blame] | 1101 | /* 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] | 1102 | * lookup ended up removing many items, more than we have had matched. |
Behdad Esfahbod | 4b4a1b9 | 2016-12-21 23:10:43 -0600 | [diff] [blame] | 1103 | * Just never rewind end back and get out of here. |
| 1104 | * https://bugs.chromium.org/p/chromium/issues/detail?id=659496 */ |
| 1105 | end = match_positions[idx]; |
Behdad Esfahbod | 47e7a18 | 2017-03-10 13:23:02 -0800 | [diff] [blame] | 1106 | /* There can't be any further changes. */ |
Behdad Esfahbod | 359dead | 2016-05-06 16:19:19 +0100 | [diff] [blame] | 1107 | break; |
| 1108 | } |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1109 | |
| 1110 | unsigned int next = idx + 1; /* next now is the position after the recursed lookup. */ |
| 1111 | |
| 1112 | if (delta > 0) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1113 | { |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 1114 | if (unlikely (delta + count > HB_MAX_CONTEXT_LENGTH)) |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1115 | break; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1116 | } |
| 1117 | else |
| 1118 | { |
Behdad Esfahbod | 47e7a18 | 2017-03-10 13:23:02 -0800 | [diff] [blame] | 1119 | /* NOTE: delta is negative. */ |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1120 | delta = MAX (delta, (int) next - (int) count); |
| 1121 | next -= delta; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1122 | } |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1123 | |
| 1124 | /* Shift! */ |
| 1125 | memmove (match_positions + next + delta, match_positions + next, |
| 1126 | (count - next) * sizeof (match_positions[0])); |
| 1127 | next += delta; |
| 1128 | count += delta; |
| 1129 | |
| 1130 | /* Fill in new entries. */ |
| 1131 | for (unsigned int j = idx + 1; j < next; j++) |
| 1132 | match_positions[j] = match_positions[j - 1] + 1; |
| 1133 | |
| 1134 | /* And fixup the rest. */ |
| 1135 | for (; next < count; next++) |
| 1136 | match_positions[next] += delta; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1137 | } |
| 1138 | |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1139 | buffer->move_to (end); |
| 1140 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1141 | return_trace (true); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1142 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1143 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1144 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1145 | |
| 1146 | /* Contextual lookups */ |
| 1147 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1148 | struct ContextClosureLookupContext |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1149 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1150 | ContextClosureFuncs funcs; |
| 1151 | const void *intersects_data; |
| 1152 | }; |
| 1153 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1154 | struct ContextCollectGlyphsLookupContext |
| 1155 | { |
| 1156 | ContextCollectGlyphsFuncs funcs; |
| 1157 | const void *collect_data; |
| 1158 | }; |
| 1159 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1160 | struct ContextApplyLookupContext |
| 1161 | { |
| 1162 | ContextApplyFuncs funcs; |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1163 | const void *match_data; |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1164 | }; |
| 1165 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1166 | static inline bool context_intersects (const hb_set_t *glyphs, |
| 1167 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 1168 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
| 1169 | ContextClosureLookupContext &lookup_context) |
| 1170 | { |
| 1171 | return intersects_array (glyphs, |
| 1172 | inputCount ? inputCount - 1 : 0, input, |
| 1173 | lookup_context.funcs.intersects, lookup_context.intersects_data); |
| 1174 | } |
| 1175 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1176 | static inline void context_closure_lookup (hb_closure_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1177 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1178 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1179 | unsigned int lookupCount, |
| 1180 | const LookupRecord lookupRecord[], |
| 1181 | ContextClosureLookupContext &lookup_context) |
| 1182 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1183 | if (context_intersects (c->glyphs, |
| 1184 | inputCount, input, |
| 1185 | lookup_context)) |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1186 | recurse_lookups (c, |
| 1187 | lookupCount, lookupRecord); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1188 | } |
| 1189 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1190 | static inline void context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c, |
| 1191 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1192 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1193 | unsigned int lookupCount, |
| 1194 | const LookupRecord lookupRecord[], |
| 1195 | ContextCollectGlyphsLookupContext &lookup_context) |
| 1196 | { |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1197 | collect_array (c, c->input, |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1198 | inputCount ? inputCount - 1 : 0, input, |
| 1199 | lookup_context.funcs.collect, lookup_context.collect_data); |
| 1200 | recurse_lookups (c, |
| 1201 | lookupCount, lookupRecord); |
| 1202 | } |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1203 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1204 | static inline bool context_would_apply_lookup (hb_would_apply_context_t *c, |
| 1205 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1206 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 1207 | unsigned int lookupCount HB_UNUSED, |
| 1208 | const LookupRecord lookupRecord[] HB_UNUSED, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1209 | ContextApplyLookupContext &lookup_context) |
| 1210 | { |
| 1211 | return would_match_input (c, |
| 1212 | inputCount, input, |
| 1213 | lookup_context.funcs.match, lookup_context.match_data); |
| 1214 | } |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1215 | static inline bool context_apply_lookup (hb_ot_apply_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1216 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1217 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1218 | unsigned int lookupCount, |
| 1219 | const LookupRecord lookupRecord[], |
| 1220 | ContextApplyLookupContext &lookup_context) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1221 | { |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1222 | unsigned int match_length = 0; |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 1223 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH]; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1224 | return match_input (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 1225 | inputCount, input, |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1226 | lookup_context.funcs.match, lookup_context.match_data, |
| 1227 | &match_length, match_positions) |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1228 | && (c->buffer->unsafe_to_break (c->buffer->idx, c->buffer->idx + match_length), |
| 1229 | apply_lookup (c, |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1230 | inputCount, match_positions, |
| 1231 | lookupCount, lookupRecord, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1232 | match_length)); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 1233 | } |
| 1234 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1235 | struct Rule |
| 1236 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1237 | inline bool intersects (const hb_set_t *glyphs, ContextClosureLookupContext &lookup_context) const |
| 1238 | { |
| 1239 | return context_intersects (glyphs, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1240 | inputCount, inputZ.arrayZ, |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1241 | lookup_context); |
| 1242 | } |
| 1243 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1244 | inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1245 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1246 | TRACE_CLOSURE (this); |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1247 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAtOffset<UnsizedArrayOf<LookupRecord> > (inputZ.arrayZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0)); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1248 | context_closure_lookup (c, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1249 | inputCount, inputZ.arrayZ, |
| 1250 | lookupCount, lookupRecord.arrayZ, |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1251 | lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1252 | } |
| 1253 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1254 | inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const |
| 1255 | { |
| 1256 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1257 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAtOffset<UnsizedArrayOf<LookupRecord> > (inputZ.arrayZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0)); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1258 | context_collect_glyphs_lookup (c, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1259 | inputCount, inputZ.arrayZ, |
| 1260 | lookupCount, lookupRecord.arrayZ, |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1261 | lookup_context); |
| 1262 | } |
| 1263 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1264 | inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const |
| 1265 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1266 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1267 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAtOffset<UnsizedArrayOf<LookupRecord> > (inputZ.arrayZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0)); |
| 1268 | return_trace (context_would_apply_lookup (c, inputCount, inputZ.arrayZ, lookupCount, lookupRecord.arrayZ, lookup_context)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1269 | } |
| 1270 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1271 | inline bool apply (hb_ot_apply_context_t *c, ContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1272 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1273 | TRACE_APPLY (this); |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1274 | const UnsizedArrayOf<LookupRecord> &lookupRecord = StructAtOffset<UnsizedArrayOf<LookupRecord> > (inputZ.arrayZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0)); |
| 1275 | 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] | 1276 | } |
| 1277 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1278 | public: |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1279 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1280 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1281 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 5aad819 | 2017-11-03 17:16:26 -0400 | [diff] [blame] | 1282 | return_trace (inputCount.sanitize (c) && |
| 1283 | lookupCount.sanitize (c) && |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1284 | c->check_range (inputZ.arrayZ, |
Behdad Esfahbod | 5dfd6e0 | 2018-09-10 15:45:32 +0200 | [diff] [blame] | 1285 | inputZ[0].static_size * (inputCount ? inputCount - 1 : 0) + |
Behdad Esfahbod | 6d7c6e1 | 2018-02-07 14:09:56 -0600 | [diff] [blame] | 1286 | LookupRecord::static_size * lookupCount)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1289 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1290 | HBUINT16 inputCount; /* Total number of glyphs in input |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1291 | * glyph sequence--includes the first |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1292 | * glyph */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1293 | HBUINT16 lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1294 | UnsizedArrayOf<HBUINT16> |
| 1295 | inputZ; /* Array of match inputs--start with |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1296 | * second glyph */ |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1297 | /*UnsizedArrayOf<LookupRecord> |
| 1298 | lookupRecordX;*/ /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1299 | * design order */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 1300 | public: |
Behdad Esfahbod | 6d7c6e1 | 2018-02-07 14:09:56 -0600 | [diff] [blame] | 1301 | DEFINE_SIZE_ARRAY (4, inputZ); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1302 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1303 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1304 | struct RuleSet |
| 1305 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1306 | inline bool intersects (const hb_set_t *glyphs, ContextClosureLookupContext &lookup_context) const |
| 1307 | { |
| 1308 | unsigned int num_rules = rule.len; |
| 1309 | for (unsigned int i = 0; i < num_rules; i++) |
| 1310 | if ((this+rule[i]).intersects (glyphs, lookup_context)) |
| 1311 | return true; |
| 1312 | return false; |
| 1313 | } |
| 1314 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1315 | inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1316 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1317 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1318 | unsigned int num_rules = rule.len; |
| 1319 | for (unsigned int i = 0; i < num_rules; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1320 | (this+rule[i]).closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1321 | } |
| 1322 | |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1323 | inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const |
| 1324 | { |
| 1325 | TRACE_COLLECT_GLYPHS (this); |
| 1326 | unsigned int num_rules = rule.len; |
| 1327 | for (unsigned int i = 0; i < num_rules; i++) |
| 1328 | (this+rule[i]).collect_glyphs (c, lookup_context); |
| 1329 | } |
| 1330 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1331 | inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const |
| 1332 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1333 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1334 | unsigned int num_rules = rule.len; |
| 1335 | for (unsigned int i = 0; i < num_rules; i++) |
| 1336 | { |
| 1337 | if ((this+rule[i]).would_apply (c, lookup_context)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1338 | return_trace (true); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1339 | } |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1340 | return_trace (false); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1343 | inline bool apply (hb_ot_apply_context_t *c, ContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1344 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1345 | TRACE_APPLY (this); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1346 | unsigned int num_rules = rule.len; |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1347 | for (unsigned int i = 0; i < num_rules; i++) |
| 1348 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1349 | if ((this+rule[i]).apply (c, lookup_context)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1350 | return_trace (true); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1351 | } |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1352 | return_trace (false); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1353 | } |
| 1354 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1355 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1356 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1357 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1358 | return_trace (rule.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1359 | } |
| 1360 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1361 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1362 | OffsetArrayOf<Rule> |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1363 | rule; /* Array of Rule tables |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1364 | * ordered by preference */ |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 1365 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1366 | DEFINE_SIZE_ARRAY (2, rule); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1367 | }; |
| 1368 | |
| 1369 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1370 | struct ContextFormat1 |
| 1371 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1372 | inline bool intersects (const hb_set_t *glyphs) const |
| 1373 | { |
| 1374 | struct ContextClosureLookupContext lookup_context = { |
| 1375 | {intersects_glyph}, |
| 1376 | nullptr |
| 1377 | }; |
| 1378 | |
| 1379 | unsigned int count = ruleSet.len; |
| 1380 | for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ()) |
| 1381 | { |
| 1382 | if (unlikely (iter.get_coverage () >= count)) |
| 1383 | break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ |
| 1384 | if (glyphs->has (iter.get_glyph ()) && |
| 1385 | (this+ruleSet[iter.get_coverage ()]).intersects (glyphs, lookup_context)) |
| 1386 | return true; |
| 1387 | } |
| 1388 | return false; |
| 1389 | } |
| 1390 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1391 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1392 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1393 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1394 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1395 | struct ContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1396 | {intersects_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1397 | nullptr |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1398 | }; |
| 1399 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1400 | unsigned int count = ruleSet.len; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1401 | for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ()) |
| 1402 | { |
| 1403 | if (unlikely (iter.get_coverage () >= count)) |
| 1404 | break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ |
| 1405 | if (c->glyphs->has (iter.get_glyph ())) |
| 1406 | (this+ruleSet[iter.get_coverage ()]).closure (c, lookup_context); |
| 1407 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1408 | } |
| 1409 | |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1410 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 1411 | { |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1412 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1413 | (this+coverage).add_coverage (c->input); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1414 | |
| 1415 | struct ContextCollectGlyphsLookupContext lookup_context = { |
| 1416 | {collect_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1417 | nullptr |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1418 | }; |
| 1419 | |
| 1420 | unsigned int count = ruleSet.len; |
| 1421 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1422 | (this+ruleSet[i]).collect_glyphs (c, lookup_context); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1423 | } |
| 1424 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1425 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1426 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1427 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1428 | |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 1429 | 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] | 1430 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1431 | {match_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1432 | nullptr |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1433 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1434 | return_trace (rule_set.would_apply (c, lookup_context)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1435 | } |
| 1436 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1437 | inline const Coverage &get_coverage (void) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1438 | { return this+coverage; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1439 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1440 | inline bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1441 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1442 | TRACE_APPLY (this); |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 1443 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 1444 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1445 | return_trace (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1446 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1447 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1448 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1449 | {match_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1450 | nullptr |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1451 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1452 | return_trace (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1453 | } |
| 1454 | |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 1455 | inline bool subset (hb_subset_context_t *c) const |
| 1456 | { |
| 1457 | TRACE_SUBSET (this); |
| 1458 | // TODO(subset) |
| 1459 | return_trace (false); |
| 1460 | } |
| 1461 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1462 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1463 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1464 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1465 | return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1466 | } |
| 1467 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1468 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1469 | HBUINT16 format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1470 | OffsetTo<Coverage> |
| 1471 | coverage; /* Offset to Coverage table--from |
| 1472 | * beginning of table */ |
| 1473 | OffsetArrayOf<RuleSet> |
| 1474 | ruleSet; /* Array of RuleSet tables |
| 1475 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1476 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1477 | DEFINE_SIZE_ARRAY (6, ruleSet); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1478 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1479 | |
| 1480 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1481 | struct ContextFormat2 |
| 1482 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1483 | inline bool intersects (const hb_set_t *glyphs) const |
| 1484 | { |
| 1485 | if (!(this+coverage).intersects (glyphs)) |
| 1486 | return false; |
| 1487 | |
| 1488 | const ClassDef &class_def = this+classDef; |
| 1489 | |
| 1490 | struct ContextClosureLookupContext lookup_context = { |
| 1491 | {intersects_class}, |
| 1492 | &class_def |
| 1493 | }; |
| 1494 | |
| 1495 | unsigned int count = ruleSet.len; |
| 1496 | for (unsigned int i = 0; i < count; i++) |
| 1497 | if (class_def.intersects_class (glyphs, i) && |
| 1498 | (this+ruleSet[i]).intersects (glyphs, lookup_context)) |
| 1499 | return true; |
| 1500 | |
| 1501 | return false; |
| 1502 | } |
| 1503 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1504 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1505 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1506 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1507 | if (!(this+coverage).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1508 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1509 | |
| 1510 | const ClassDef &class_def = this+classDef; |
| 1511 | |
| 1512 | struct ContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1513 | {intersects_class}, |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 1514 | &class_def |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1515 | }; |
| 1516 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1517 | unsigned int count = ruleSet.len; |
| 1518 | for (unsigned int i = 0; i < count; i++) |
| 1519 | if (class_def.intersects_class (c->glyphs, i)) { |
| 1520 | const RuleSet &rule_set = this+ruleSet[i]; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1521 | rule_set.closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1522 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1525 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 1526 | { |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1527 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1528 | (this+coverage).add_coverage (c->input); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1529 | |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 1530 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1531 | struct ContextCollectGlyphsLookupContext lookup_context = { |
| 1532 | {collect_class}, |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 1533 | &class_def |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1534 | }; |
| 1535 | |
| 1536 | unsigned int count = ruleSet.len; |
| 1537 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1538 | (this+ruleSet[i]).collect_glyphs (c, lookup_context); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1539 | } |
| 1540 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1541 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1542 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1543 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1544 | |
| 1545 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | 2dc1141 | 2012-11-24 19:16:34 -0500 | [diff] [blame] | 1546 | unsigned int index = class_def.get_class (c->glyphs[0]); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1547 | const RuleSet &rule_set = this+ruleSet[index]; |
| 1548 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1549 | {match_class}, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1550 | &class_def |
| 1551 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1552 | return_trace (rule_set.would_apply (c, lookup_context)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1555 | inline const Coverage &get_coverage (void) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1556 | { return this+coverage; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1557 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1558 | inline bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1559 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1560 | TRACE_APPLY (this); |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 1561 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1562 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1563 | |
| 1564 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | 2dc1141 | 2012-11-24 19:16:34 -0500 | [diff] [blame] | 1565 | index = class_def.get_class (c->buffer->cur().codepoint); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1566 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1567 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1568 | {match_class}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1569 | &class_def |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1570 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1571 | return_trace (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1572 | } |
| 1573 | |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 1574 | inline bool subset (hb_subset_context_t *c) const |
| 1575 | { |
| 1576 | TRACE_SUBSET (this); |
| 1577 | // TODO(subset) |
| 1578 | return_trace (false); |
| 1579 | } |
| 1580 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1581 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1582 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1583 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1584 | 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] | 1585 | } |
| 1586 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1587 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1588 | HBUINT16 format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1589 | OffsetTo<Coverage> |
| 1590 | coverage; /* Offset to Coverage table--from |
| 1591 | * beginning of table */ |
| 1592 | OffsetTo<ClassDef> |
| 1593 | classDef; /* Offset to glyph ClassDef table--from |
| 1594 | * beginning of table */ |
| 1595 | OffsetArrayOf<RuleSet> |
| 1596 | ruleSet; /* Array of RuleSet tables |
| 1597 | * ordered by class */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1598 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1599 | DEFINE_SIZE_ARRAY (8, ruleSet); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1600 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1601 | |
| 1602 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1603 | struct ContextFormat3 |
| 1604 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1605 | inline bool intersects (const hb_set_t *glyphs) const |
| 1606 | { |
| 1607 | if (!(this+coverageZ[0]).intersects (glyphs)) |
| 1608 | return false; |
| 1609 | |
| 1610 | struct ContextClosureLookupContext lookup_context = { |
| 1611 | {intersects_coverage}, |
| 1612 | this |
| 1613 | }; |
| 1614 | return context_intersects (glyphs, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1615 | glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1616 | lookup_context); |
| 1617 | } |
| 1618 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1619 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1620 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1621 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 093c520 | 2014-12-12 21:07:53 -0800 | [diff] [blame] | 1622 | if (!(this+coverageZ[0]).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1623 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1624 | |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1625 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ.arrayZ, coverageZ[0].static_size * glyphCount); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1626 | struct ContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1627 | {intersects_coverage}, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1628 | this |
| 1629 | }; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1630 | context_closure_lookup (c, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1631 | glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1632 | lookupCount, lookupRecord, |
| 1633 | lookup_context); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1634 | } |
| 1635 | |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1636 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 1637 | { |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1638 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 093c520 | 2014-12-12 21:07:53 -0800 | [diff] [blame] | 1639 | (this+coverageZ[0]).add_coverage (c->input); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1640 | |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1641 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ.arrayZ, coverageZ[0].static_size * glyphCount); |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1642 | struct ContextCollectGlyphsLookupContext lookup_context = { |
| 1643 | {collect_coverage}, |
Behdad Esfahbod | e75943d | 2012-11-30 08:38:24 +0200 | [diff] [blame] | 1644 | this |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1645 | }; |
| 1646 | |
| 1647 | context_collect_glyphs_lookup (c, |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1648 | glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1649 | lookupCount, lookupRecord, |
| 1650 | lookup_context); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1651 | } |
| 1652 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1653 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1654 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1655 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1656 | |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1657 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ.arrayZ, coverageZ[0].static_size * glyphCount); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1658 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1659 | {match_coverage}, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1660 | this |
| 1661 | }; |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1662 | return_trace (context_would_apply_lookup (c, glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), lookupCount, lookupRecord, lookup_context)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1665 | inline const Coverage &get_coverage (void) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1666 | { return this+coverageZ[0]; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1667 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1668 | inline bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1669 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1670 | TRACE_APPLY (this); |
Behdad Esfahbod | 093c520 | 2014-12-12 21:07:53 -0800 | [diff] [blame] | 1671 | unsigned int index = (this+coverageZ[0]).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1672 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1673 | |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1674 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ.arrayZ, coverageZ[0].static_size * glyphCount); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1675 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1676 | {match_coverage}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1677 | this |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1678 | }; |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1679 | 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] | 1680 | } |
| 1681 | |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 1682 | inline bool subset (hb_subset_context_t *c) const |
| 1683 | { |
| 1684 | TRACE_SUBSET (this); |
| 1685 | // TODO(subset) |
| 1686 | return_trace (false); |
| 1687 | } |
| 1688 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1689 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1690 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1691 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1692 | if (!c->check_struct (this)) return_trace (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1693 | unsigned int count = glyphCount; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1694 | if (!count) return_trace (false); /* We want to access coverageZ[0] freely. */ |
Behdad Esfahbod | 9507b05 | 2018-09-10 23:18:07 +0200 | [diff] [blame] | 1695 | if (!c->check_array (coverageZ.arrayZ, count)) return_trace (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1696 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1697 | if (!coverageZ[i].sanitize (c, this)) return_trace (false); |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1698 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ.arrayZ, coverageZ[0].static_size * count); |
Behdad Esfahbod | 9507b05 | 2018-09-10 23:18:07 +0200 | [diff] [blame] | 1699 | return_trace (c->check_array (lookupRecord, lookupCount)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1700 | } |
| 1701 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1702 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1703 | HBUINT16 format; /* Format identifier--format = 3 */ |
| 1704 | HBUINT16 glyphCount; /* Number of glyphs in the input glyph |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1705 | * sequence */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1706 | HBUINT16 lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1707 | UnsizedArrayOf<OffsetTo<Coverage> > |
| 1708 | coverageZ; /* Array of offsets to Coverage |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1709 | * table in glyph sequence order */ |
Behdad Esfahbod | bc485a9 | 2018-09-10 23:02:24 +0200 | [diff] [blame] | 1710 | /*UnsizedArrayOf<LookupRecord> |
| 1711 | lookupRecordX;*/ /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1712 | * design order */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 1713 | public: |
Behdad Esfahbod | 6d7c6e1 | 2018-02-07 14:09:56 -0600 | [diff] [blame] | 1714 | DEFINE_SIZE_ARRAY (6, coverageZ); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1715 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1716 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1717 | struct Context |
| 1718 | { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 1719 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1720 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1721 | { |
Behdad Esfahbod | 00f6a8e | 2014-12-12 20:36:49 -0800 | [diff] [blame] | 1722 | TRACE_DISPATCH (this, u.format); |
Behdad Esfahbod | f396fbb | 2015-10-09 12:25:55 -0400 | [diff] [blame] | 1723 | 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] | 1724 | switch (u.format) { |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1725 | case 1: return_trace (c->dispatch (u.format1)); |
| 1726 | case 2: return_trace (c->dispatch (u.format2)); |
| 1727 | case 3: return_trace (c->dispatch (u.format3)); |
| 1728 | default:return_trace (c->default_return_value ()); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1729 | } |
| 1730 | } |
| 1731 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1732 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1733 | union { |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1734 | HBUINT16 format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1735 | ContextFormat1 format1; |
| 1736 | ContextFormat2 format2; |
| 1737 | ContextFormat3 format3; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1738 | } u; |
| 1739 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1740 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1741 | |
| 1742 | /* Chaining Contextual lookups */ |
| 1743 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1744 | struct ChainContextClosureLookupContext |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1745 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1746 | ContextClosureFuncs funcs; |
| 1747 | const void *intersects_data[3]; |
| 1748 | }; |
| 1749 | |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1750 | struct ChainContextCollectGlyphsLookupContext |
| 1751 | { |
| 1752 | ContextCollectGlyphsFuncs funcs; |
| 1753 | const void *collect_data[3]; |
| 1754 | }; |
| 1755 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1756 | struct ChainContextApplyLookupContext |
| 1757 | { |
| 1758 | ContextApplyFuncs funcs; |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1759 | const void *match_data[3]; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1760 | }; |
| 1761 | |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1762 | static inline bool chain_context_intersects (const hb_set_t *glyphs, |
| 1763 | unsigned int backtrackCount, |
| 1764 | const HBUINT16 backtrack[], |
| 1765 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 1766 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
| 1767 | unsigned int lookaheadCount, |
| 1768 | const HBUINT16 lookahead[], |
| 1769 | ChainContextClosureLookupContext &lookup_context) |
| 1770 | { |
| 1771 | return intersects_array (glyphs, |
| 1772 | backtrackCount, backtrack, |
| 1773 | lookup_context.funcs.intersects, lookup_context.intersects_data[0]) |
| 1774 | && intersects_array (glyphs, |
| 1775 | inputCount ? inputCount - 1 : 0, input, |
| 1776 | lookup_context.funcs.intersects, lookup_context.intersects_data[1]) |
| 1777 | && intersects_array (glyphs, |
| 1778 | lookaheadCount, lookahead, |
| 1779 | lookup_context.funcs.intersects, lookup_context.intersects_data[2]); |
| 1780 | } |
| 1781 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1782 | static inline void chain_context_closure_lookup (hb_closure_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1783 | unsigned int backtrackCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1784 | const HBUINT16 backtrack[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1785 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1786 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1787 | unsigned int lookaheadCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1788 | const HBUINT16 lookahead[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1789 | unsigned int lookupCount, |
| 1790 | const LookupRecord lookupRecord[], |
| 1791 | ChainContextClosureLookupContext &lookup_context) |
| 1792 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1793 | if (chain_context_intersects (c->glyphs, |
| 1794 | backtrackCount, backtrack, |
| 1795 | inputCount, input, |
| 1796 | lookaheadCount, lookahead, |
| 1797 | lookup_context)) |
Behdad Esfahbod | d0a5233 | 2012-11-23 18:54:59 -0500 | [diff] [blame] | 1798 | recurse_lookups (c, |
| 1799 | lookupCount, lookupRecord); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1800 | } |
| 1801 | |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1802 | static inline void chain_context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c, |
| 1803 | unsigned int backtrackCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1804 | const HBUINT16 backtrack[], |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1805 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1806 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1807 | unsigned int lookaheadCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1808 | const HBUINT16 lookahead[], |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1809 | unsigned int lookupCount, |
| 1810 | const LookupRecord lookupRecord[], |
| 1811 | ChainContextCollectGlyphsLookupContext &lookup_context) |
| 1812 | { |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1813 | collect_array (c, c->before, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1814 | backtrackCount, backtrack, |
| 1815 | lookup_context.funcs.collect, lookup_context.collect_data[0]); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1816 | collect_array (c, c->input, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1817 | inputCount ? inputCount - 1 : 0, input, |
| 1818 | lookup_context.funcs.collect, lookup_context.collect_data[1]); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1819 | collect_array (c, c->after, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1820 | lookaheadCount, lookahead, |
| 1821 | lookup_context.funcs.collect, lookup_context.collect_data[2]); |
| 1822 | recurse_lookups (c, |
| 1823 | lookupCount, lookupRecord); |
| 1824 | } |
| 1825 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1826 | static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c, |
| 1827 | unsigned int backtrackCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1828 | const HBUINT16 backtrack[] HB_UNUSED, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1829 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1830 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1831 | unsigned int lookaheadCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1832 | const HBUINT16 lookahead[] HB_UNUSED, |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 1833 | unsigned int lookupCount HB_UNUSED, |
| 1834 | const LookupRecord lookupRecord[] HB_UNUSED, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1835 | ChainContextApplyLookupContext &lookup_context) |
| 1836 | { |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 1837 | return (c->zero_context ? !backtrackCount && !lookaheadCount : true) |
Behdad Esfahbod | 1f2bb17 | 2012-08-23 16:10:37 -0400 | [diff] [blame] | 1838 | && would_match_input (c, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1839 | inputCount, input, |
| 1840 | lookup_context.funcs.match, lookup_context.match_data[1]); |
| 1841 | } |
| 1842 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1843 | 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] | 1844 | unsigned int backtrackCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1845 | const HBUINT16 backtrack[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1846 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1847 | const HBUINT16 input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1848 | unsigned int lookaheadCount, |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1849 | const HBUINT16 lookahead[], |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1850 | unsigned int lookupCount, |
| 1851 | const LookupRecord lookupRecord[], |
| 1852 | ChainContextApplyLookupContext &lookup_context) |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1853 | { |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1854 | unsigned int start_index = 0, match_length = 0, end_index = 0; |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 1855 | unsigned int match_positions[HB_MAX_CONTEXT_LENGTH]; |
Behdad Esfahbod | f19e0b0 | 2012-06-09 02:26:57 -0400 | [diff] [blame] | 1856 | return match_input (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 1857 | inputCount, input, |
| 1858 | lookup_context.funcs.match, lookup_context.match_data[1], |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1859 | &match_length, match_positions) |
Behdad Esfahbod | f19e0b0 | 2012-06-09 02:26:57 -0400 | [diff] [blame] | 1860 | && match_backtrack (c, |
| 1861 | backtrackCount, backtrack, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1862 | lookup_context.funcs.match, lookup_context.match_data[0], |
| 1863 | &start_index) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1864 | && match_lookahead (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 1865 | lookaheadCount, lookahead, |
| 1866 | lookup_context.funcs.match, lookup_context.match_data[2], |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1867 | match_length, &end_index) |
| 1868 | && (c->buffer->unsafe_to_break_from_outbuffer (start_index, end_index), |
| 1869 | apply_lookup (c, |
Behdad Esfahbod | 6b65a76 | 2013-10-14 18:51:39 +0200 | [diff] [blame] | 1870 | inputCount, match_positions, |
| 1871 | lookupCount, lookupRecord, |
Behdad Esfahbod | 40bd7e9 | 2016-05-02 14:47:45 +0200 | [diff] [blame] | 1872 | match_length)); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1873 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1874 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1875 | struct ChainRule |
| 1876 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1877 | inline bool intersects (const hb_set_t *glyphs, ChainContextClosureLookupContext &lookup_context) const |
| 1878 | { |
| 1879 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack); |
| 1880 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input); |
| 1881 | return chain_context_intersects (glyphs, |
| 1882 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 1883 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1884 | lookahead.len, lookahead.arrayZ, |
| 1885 | lookup_context); |
| 1886 | } |
| 1887 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1888 | inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1889 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1890 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1891 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack); |
| 1892 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1893 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1894 | chain_context_closure_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 1895 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 1896 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 1897 | lookahead.len, lookahead.arrayZ, |
| 1898 | lookup.len, lookup.arrayZ, |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1899 | lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1900 | } |
| 1901 | |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1902 | inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const |
| 1903 | { |
| 1904 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1905 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack); |
| 1906 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1907 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
| 1908 | chain_context_collect_glyphs_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 1909 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 1910 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 1911 | lookahead.len, lookahead.arrayZ, |
| 1912 | lookup.len, lookup.arrayZ, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1913 | lookup_context); |
| 1914 | } |
| 1915 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1916 | inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
| 1917 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1918 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1919 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack); |
| 1920 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1921 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1922 | return_trace (chain_context_would_apply_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 1923 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 1924 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 1925 | lookahead.len, lookahead.arrayZ, lookup.len, |
| 1926 | lookup.arrayZ, lookup_context)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1927 | } |
| 1928 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1929 | inline bool apply (hb_ot_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1930 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1931 | TRACE_APPLY (this); |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1932 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack); |
| 1933 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1934 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1935 | return_trace (chain_context_apply_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 1936 | backtrack.len, backtrack.arrayZ, |
Behdad Esfahbod | effc7ce | 2018-09-13 20:21:54 +0200 | [diff] [blame] | 1937 | input.lenP1, input.arrayZ, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 1938 | lookahead.len, lookahead.arrayZ, lookup.len, |
| 1939 | lookup.arrayZ, lookup_context)); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1940 | } |
| 1941 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1942 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1943 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1944 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1945 | if (!backtrack.sanitize (c)) return_trace (false); |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1946 | const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1947 | if (!input.sanitize (c)) return_trace (false); |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1948 | const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1949 | if (!lookahead.sanitize (c)) return_trace (false); |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1950 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1951 | return_trace (lookup.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1952 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1953 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1954 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1955 | ArrayOf<HBUINT16> |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1956 | backtrack; /* Array of backtracking values |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1957 | * (to be matched before the input |
| 1958 | * sequence) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1959 | HeadlessArrayOf<HBUINT16> |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 1960 | inputX; /* Array of input values (start with |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1961 | * second glyph) */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 1962 | ArrayOf<HBUINT16> |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1963 | lookaheadX; /* Array of lookahead values's (to be |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1964 | * matched after the input sequence) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1965 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1966 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1967 | * design order) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1968 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 1969 | DEFINE_SIZE_MIN (8); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1970 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1971 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1972 | struct ChainRuleSet |
| 1973 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 1974 | inline bool intersects (const hb_set_t *glyphs, ChainContextClosureLookupContext &lookup_context) const |
| 1975 | { |
| 1976 | unsigned int num_rules = rule.len; |
| 1977 | for (unsigned int i = 0; i < num_rules; i++) |
| 1978 | if ((this+rule[i]).intersects (glyphs, lookup_context)) |
| 1979 | return true; |
| 1980 | return false; |
| 1981 | } |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1982 | inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1983 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1984 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1985 | unsigned int num_rules = rule.len; |
| 1986 | for (unsigned int i = 0; i < num_rules; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1987 | (this+rule[i]).closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1988 | } |
| 1989 | |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 1990 | inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const |
| 1991 | { |
| 1992 | TRACE_COLLECT_GLYPHS (this); |
| 1993 | unsigned int num_rules = rule.len; |
| 1994 | for (unsigned int i = 0; i < num_rules; i++) |
| 1995 | (this+rule[i]).collect_glyphs (c, lookup_context); |
| 1996 | } |
| 1997 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1998 | inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
| 1999 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2000 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2001 | unsigned int num_rules = rule.len; |
| 2002 | for (unsigned int i = 0; i < num_rules; i++) |
| 2003 | if ((this+rule[i]).would_apply (c, lookup_context)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2004 | return_trace (true); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2005 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2006 | return_trace (false); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2007 | } |
| 2008 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 2009 | inline bool apply (hb_ot_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2010 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2011 | TRACE_APPLY (this); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2012 | unsigned int num_rules = rule.len; |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2013 | for (unsigned int i = 0; i < num_rules; i++) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 2014 | if ((this+rule[i]).apply (c, lookup_context)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2015 | return_trace (true); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2016 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2017 | return_trace (false); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2018 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2019 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2020 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 2021 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2022 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2023 | return_trace (rule.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2024 | } |
| 2025 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2026 | protected: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2027 | OffsetArrayOf<ChainRule> |
| 2028 | rule; /* Array of ChainRule tables |
| 2029 | * ordered by preference */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2030 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 2031 | DEFINE_SIZE_ARRAY (2, rule); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2032 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2033 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2034 | struct ChainContextFormat1 |
| 2035 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2036 | inline bool intersects (const hb_set_t *glyphs) const |
| 2037 | { |
| 2038 | struct ChainContextClosureLookupContext lookup_context = { |
| 2039 | {intersects_glyph}, |
| 2040 | {nullptr, nullptr, nullptr} |
| 2041 | }; |
| 2042 | |
| 2043 | unsigned int count = ruleSet.len; |
| 2044 | for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ()) |
| 2045 | { |
| 2046 | if (unlikely (iter.get_coverage () >= count)) |
| 2047 | break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ |
| 2048 | if (glyphs->has (iter.get_glyph ()) && |
| 2049 | (this+ruleSet[iter.get_coverage ()]).intersects (glyphs, lookup_context)) |
| 2050 | return true; |
| 2051 | } |
| 2052 | return false; |
| 2053 | } |
| 2054 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2055 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2056 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2057 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2058 | |
| 2059 | struct ChainContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2060 | {intersects_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 2061 | {nullptr, nullptr, nullptr} |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2062 | }; |
| 2063 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2064 | unsigned int count = ruleSet.len; |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2065 | for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ()) |
| 2066 | { |
| 2067 | if (unlikely (iter.get_coverage () >= count)) |
| 2068 | break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ |
| 2069 | if (c->glyphs->has (iter.get_glyph ())) |
| 2070 | (this+ruleSet[iter.get_coverage ()]).closure (c, lookup_context); |
| 2071 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2072 | } |
| 2073 | |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2074 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 2075 | { |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2076 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 2077 | (this+coverage).add_coverage (c->input); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2078 | |
| 2079 | struct ChainContextCollectGlyphsLookupContext lookup_context = { |
| 2080 | {collect_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 2081 | {nullptr, nullptr, nullptr} |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2082 | }; |
| 2083 | |
| 2084 | unsigned int count = ruleSet.len; |
| 2085 | for (unsigned int i = 0; i < count; i++) |
| 2086 | (this+ruleSet[i]).collect_glyphs (c, lookup_context); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2087 | } |
| 2088 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2089 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 2090 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2091 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2092 | |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 2093 | 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] | 2094 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2095 | {match_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 2096 | {nullptr, nullptr, nullptr} |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2097 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2098 | return_trace (rule_set.would_apply (c, lookup_context)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2099 | } |
| 2100 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2101 | inline const Coverage &get_coverage (void) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2102 | { return this+coverage; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2103 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 2104 | inline bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2105 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2106 | TRACE_APPLY (this); |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 2107 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2108 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2109 | |
| 2110 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2111 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2112 | {match_glyph}, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 2113 | {nullptr, nullptr, nullptr} |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2114 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2115 | return_trace (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2116 | } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2117 | |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 2118 | inline bool subset (hb_subset_context_t *c) const |
| 2119 | { |
| 2120 | TRACE_SUBSET (this); |
| 2121 | // TODO(subset) |
| 2122 | return_trace (false); |
| 2123 | } |
| 2124 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2125 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 2126 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2127 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2128 | return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2129 | } |
| 2130 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2131 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2132 | HBUINT16 format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 2133 | OffsetTo<Coverage> |
| 2134 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2135 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2136 | OffsetArrayOf<ChainRuleSet> |
| 2137 | ruleSet; /* Array of ChainRuleSet tables |
| 2138 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2139 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 2140 | DEFINE_SIZE_ARRAY (6, ruleSet); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2141 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2142 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2143 | struct ChainContextFormat2 |
| 2144 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2145 | inline bool intersects (const hb_set_t *glyphs) const |
| 2146 | { |
| 2147 | if (!(this+coverage).intersects (glyphs)) |
| 2148 | return false; |
| 2149 | |
| 2150 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 2151 | const ClassDef &input_class_def = this+inputClassDef; |
| 2152 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 2153 | |
| 2154 | struct ChainContextClosureLookupContext lookup_context = { |
| 2155 | {intersects_class}, |
| 2156 | {&backtrack_class_def, |
| 2157 | &input_class_def, |
| 2158 | &lookahead_class_def} |
| 2159 | }; |
| 2160 | |
| 2161 | unsigned int count = ruleSet.len; |
| 2162 | for (unsigned int i = 0; i < count; i++) |
| 2163 | if (input_class_def.intersects_class (glyphs, i) && |
| 2164 | (this+ruleSet[i]).intersects (glyphs, lookup_context)) |
| 2165 | return true; |
| 2166 | |
| 2167 | return false; |
| 2168 | } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2169 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2170 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2171 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2172 | if (!(this+coverage).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2173 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2174 | |
| 2175 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 2176 | const ClassDef &input_class_def = this+inputClassDef; |
| 2177 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 2178 | |
| 2179 | struct ChainContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2180 | {intersects_class}, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2181 | {&backtrack_class_def, |
| 2182 | &input_class_def, |
| 2183 | &lookahead_class_def} |
| 2184 | }; |
| 2185 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2186 | unsigned int count = ruleSet.len; |
| 2187 | for (unsigned int i = 0; i < count; i++) |
| 2188 | if (input_class_def.intersects_class (c->glyphs, i)) { |
| 2189 | const ChainRuleSet &rule_set = this+ruleSet[i]; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2190 | rule_set.closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2191 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2192 | } |
| 2193 | |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2194 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 2195 | { |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2196 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 2197 | (this+coverage).add_coverage (c->input); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2198 | |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2199 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 2200 | const ClassDef &input_class_def = this+inputClassDef; |
| 2201 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 2202 | |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2203 | struct ChainContextCollectGlyphsLookupContext lookup_context = { |
| 2204 | {collect_class}, |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2205 | {&backtrack_class_def, |
| 2206 | &input_class_def, |
| 2207 | &lookahead_class_def} |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2208 | }; |
| 2209 | |
| 2210 | unsigned int count = ruleSet.len; |
| 2211 | for (unsigned int i = 0; i < count; i++) |
| 2212 | (this+ruleSet[i]).collect_glyphs (c, lookup_context); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2213 | } |
| 2214 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2215 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 2216 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2217 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2218 | |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2219 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2220 | const ClassDef &input_class_def = this+inputClassDef; |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2221 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2222 | |
Behdad Esfahbod | 2dc1141 | 2012-11-24 19:16:34 -0500 | [diff] [blame] | 2223 | unsigned int index = input_class_def.get_class (c->glyphs[0]); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2224 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
| 2225 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2226 | {match_class}, |
Behdad Esfahbod | 11fba79 | 2013-01-02 23:36:37 -0600 | [diff] [blame] | 2227 | {&backtrack_class_def, |
| 2228 | &input_class_def, |
| 2229 | &lookahead_class_def} |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2230 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2231 | return_trace (rule_set.would_apply (c, lookup_context)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2232 | } |
| 2233 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2234 | inline const Coverage &get_coverage (void) const |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2235 | { return this+coverage; } |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2236 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 2237 | inline bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2238 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2239 | TRACE_APPLY (this); |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 2240 | unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2241 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2242 | |
| 2243 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 2244 | const ClassDef &input_class_def = this+inputClassDef; |
| 2245 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 2246 | |
Behdad Esfahbod | 2dc1141 | 2012-11-24 19:16:34 -0500 | [diff] [blame] | 2247 | index = input_class_def.get_class (c->buffer->cur().codepoint); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2248 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2249 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2250 | {match_class}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 2251 | {&backtrack_class_def, |
| 2252 | &input_class_def, |
| 2253 | &lookahead_class_def} |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2254 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2255 | return_trace (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2256 | } |
| 2257 | |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 2258 | inline bool subset (hb_subset_context_t *c) const |
| 2259 | { |
| 2260 | TRACE_SUBSET (this); |
| 2261 | // TODO(subset) |
| 2262 | return_trace (false); |
| 2263 | } |
| 2264 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2265 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 2266 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2267 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2268 | return_trace (coverage.sanitize (c, this) && |
| 2269 | backtrackClassDef.sanitize (c, this) && |
| 2270 | inputClassDef.sanitize (c, this) && |
| 2271 | lookaheadClassDef.sanitize (c, this) && |
| 2272 | ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2273 | } |
| 2274 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2275 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2276 | HBUINT16 format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2277 | OffsetTo<Coverage> |
| 2278 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2279 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2280 | OffsetTo<ClassDef> |
| 2281 | backtrackClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2282 | * containing backtrack sequence |
| 2283 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2284 | OffsetTo<ClassDef> |
| 2285 | inputClassDef; /* Offset to glyph ClassDef |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2286 | * table containing input sequence |
| 2287 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2288 | OffsetTo<ClassDef> |
| 2289 | lookaheadClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2290 | * containing lookahead sequence |
| 2291 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 2292 | OffsetArrayOf<ChainRuleSet> |
| 2293 | ruleSet; /* Array of ChainRuleSet tables |
| 2294 | * ordered by class */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2295 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 2296 | DEFINE_SIZE_ARRAY (12, ruleSet); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2297 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2298 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2299 | struct ChainContextFormat3 |
| 2300 | { |
Behdad Esfahbod | 7c9cfa2 | 2018-09-02 19:47:50 -0700 | [diff] [blame] | 2301 | inline bool intersects (const hb_set_t *glyphs) const |
| 2302 | { |
| 2303 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
| 2304 | |
| 2305 | if (!(this+input[0]).intersects (glyphs)) |
| 2306 | return false; |
| 2307 | |
| 2308 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 2309 | struct ChainContextClosureLookupContext lookup_context = { |
| 2310 | {intersects_coverage}, |
| 2311 | {this, this, this} |
| 2312 | }; |
| 2313 | return chain_context_intersects (glyphs, |
| 2314 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2315 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2316 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2317 | lookup_context); |
| 2318 | } |
| 2319 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2320 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2321 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2322 | TRACE_CLOSURE (this); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2323 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
| 2324 | |
| 2325 | if (!(this+input[0]).intersects (c->glyphs)) |
| 2326 | return; |
| 2327 | |
| 2328 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 2329 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
| 2330 | struct ChainContextClosureLookupContext lookup_context = { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2331 | {intersects_coverage}, |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2332 | {this, this, this} |
| 2333 | }; |
| 2334 | chain_context_closure_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2335 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2336 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2337 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2338 | lookup.len, lookup.arrayZ, |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 2339 | lookup_context); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2340 | } |
| 2341 | |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2342 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 2343 | { |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2344 | TRACE_COLLECT_GLYPHS (this); |
| 2345 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
| 2346 | |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 2347 | (this+input[0]).add_coverage (c->input); |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2348 | |
| 2349 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 2350 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
| 2351 | struct ChainContextCollectGlyphsLookupContext lookup_context = { |
| 2352 | {collect_coverage}, |
| 2353 | {this, this, this} |
| 2354 | }; |
| 2355 | chain_context_collect_glyphs_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2356 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2357 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2358 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2359 | lookup.len, lookup.arrayZ, |
Behdad Esfahbod | f1b1278 | 2012-11-24 01:55:34 -0500 | [diff] [blame] | 2360 | lookup_context); |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 2361 | } |
| 2362 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2363 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 2364 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2365 | TRACE_WOULD_APPLY (this); |
Behdad Esfahbod | e6f7479 | 2012-07-28 18:34:58 -0400 | [diff] [blame] | 2366 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2367 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2368 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 2369 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
| 2370 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2371 | {match_coverage}, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2372 | {this, this, this} |
| 2373 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2374 | return_trace (chain_context_would_apply_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2375 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2376 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2377 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2378 | lookup.len, lookup.arrayZ, lookup_context)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2379 | } |
| 2380 | |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2381 | inline const Coverage &get_coverage (void) const |
| 2382 | { |
| 2383 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
| 2384 | return this+input[0]; |
| 2385 | } |
| 2386 | |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 2387 | inline bool apply (hb_ot_apply_context_t *c) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2388 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2389 | TRACE_APPLY (this); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 2390 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 2391 | |
Behdad Esfahbod | b67881b | 2012-11-24 19:13:55 -0500 | [diff] [blame] | 2392 | unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2393 | if (likely (index == NOT_COVERED)) return_trace (false); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2394 | |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 2395 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 2396 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 2397 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 2398 | {match_coverage}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 2399 | {this, this, this} |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 2400 | }; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2401 | return_trace (chain_context_apply_lookup (c, |
Behdad Esfahbod | 63f57f4 | 2018-05-08 16:56:11 -0700 | [diff] [blame] | 2402 | backtrack.len, (const HBUINT16 *) backtrack.arrayZ, |
| 2403 | input.len, (const HBUINT16 *) input.arrayZ + 1, |
| 2404 | lookahead.len, (const HBUINT16 *) lookahead.arrayZ, |
| 2405 | lookup.len, lookup.arrayZ, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2406 | } |
| 2407 | |
Behdad Esfahbod | 339d360 | 2018-09-03 17:33:34 -0700 | [diff] [blame] | 2408 | inline bool subset (hb_subset_context_t *c) const |
| 2409 | { |
| 2410 | TRACE_SUBSET (this); |
| 2411 | // TODO(subset) |
| 2412 | return_trace (false); |
| 2413 | } |
| 2414 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2415 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 2416 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2417 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2418 | if (!backtrack.sanitize (c, this)) return_trace (false); |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2419 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2420 | if (!input.sanitize (c, this)) return_trace (false); |
| 2421 | if (!input.len) return_trace (false); /* To be consistent with Context. */ |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2422 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2423 | if (!lookahead.sanitize (c, this)) return_trace (false); |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2424 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2425 | return_trace (lookup.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2426 | } |
| 2427 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2428 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2429 | HBUINT16 format; /* Format identifier--format = 3 */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 2430 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 2431 | backtrack; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2432 | * in backtracking sequence, in glyph |
| 2433 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 2434 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 2435 | inputX ; /* Array of coverage |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2436 | * tables in input sequence, in glyph |
| 2437 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 2438 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 2439 | lookaheadX; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2440 | * in lookahead sequence, in glyph |
| 2441 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 2442 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 2443 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 2444 | * design order) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2445 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 2446 | DEFINE_SIZE_MIN (10); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2447 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2448 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2449 | struct ChainContext |
| 2450 | { |
Behdad Esfahbod | 44fc237 | 2012-11-21 23:33:13 -0500 | [diff] [blame] | 2451 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 2452 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 2453 | { |
Behdad Esfahbod | 00f6a8e | 2014-12-12 20:36:49 -0800 | [diff] [blame] | 2454 | TRACE_DISPATCH (this, u.format); |
Behdad Esfahbod | f396fbb | 2015-10-09 12:25:55 -0400 | [diff] [blame] | 2455 | 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] | 2456 | switch (u.format) { |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2457 | case 1: return_trace (c->dispatch (u.format1)); |
| 2458 | case 2: return_trace (c->dispatch (u.format2)); |
| 2459 | case 3: return_trace (c->dispatch (u.format3)); |
| 2460 | default:return_trace (c->default_return_value ()); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 2461 | } |
| 2462 | } |
| 2463 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2464 | protected: |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2465 | union { |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2466 | HBUINT16 format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 2467 | ChainContextFormat1 format1; |
| 2468 | ChainContextFormat2 format2; |
| 2469 | ChainContextFormat3 format3; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2470 | } u; |
| 2471 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 2472 | |
| 2473 | |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 2474 | template <typename T> |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2475 | struct ExtensionFormat1 |
| 2476 | { |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2477 | inline unsigned int get_type (void) const { return extensionLookupType; } |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2478 | |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 2479 | template <typename X> |
| 2480 | inline const X& get_subtable (void) const |
| 2481 | { |
| 2482 | unsigned int offset = extensionOffset; |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 2483 | if (unlikely (!offset)) return Null(typename T::SubTable); |
| 2484 | return StructAtOffset<typename T::SubTable> (this, offset); |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | template <typename context_t> |
| 2488 | inline typename context_t::return_t dispatch (context_t *c) const |
| 2489 | { |
| 2490 | TRACE_DISPATCH (this, format); |
Behdad Esfahbod | f396fbb | 2015-10-09 12:25:55 -0400 | [diff] [blame] | 2491 | if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ()); |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 2492 | return_trace (get_subtable<typename T::SubTable> ().dispatch (c, get_type ())); |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | /* This is called from may_dispatch() above with hb_sanitize_context_t. */ |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2496 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 2497 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2498 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 949f6af | 2018-01-15 20:44:10 -0500 | [diff] [blame] | 2499 | return_trace (c->check_struct (this) && |
| 2500 | extensionOffset != 0 && |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 2501 | extensionLookupType != T::SubTable::Extension); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2502 | } |
| 2503 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2504 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2505 | HBUINT16 format; /* Format identifier. Set to 1. */ |
| 2506 | HBUINT16 extensionLookupType; /* Lookup type of subtable referenced |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2507 | * by ExtensionOffset (i.e. the |
| 2508 | * extension subtable). */ |
Behdad Esfahbod | bcb6f1a | 2018-01-15 20:34:05 -0500 | [diff] [blame] | 2509 | HBUINT32 extensionOffset; /* Offset to the extension subtable, |
Behdad Esfahbod | 81f2af4 | 2010-04-22 00:58:49 -0400 | [diff] [blame] | 2510 | * of lookup type subtable. */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2511 | public: |
| 2512 | DEFINE_SIZE_STATIC (8); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2513 | }; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2514 | |
Behdad Esfahbod | 653eeb2 | 2012-11-23 16:57:36 -0500 | [diff] [blame] | 2515 | template <typename T> |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2516 | struct Extension |
| 2517 | { |
| 2518 | inline unsigned int get_type (void) const |
| 2519 | { |
| 2520 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 2521 | case 1: return u.format1.get_type (); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2522 | default:return 0; |
| 2523 | } |
| 2524 | } |
Behdad Esfahbod | 7dddd4e | 2012-11-23 17:04:55 -0500 | [diff] [blame] | 2525 | template <typename X> |
| 2526 | inline const X& get_subtable (void) const |
| 2527 | { |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 2528 | switch (u.format) { |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 2529 | case 1: return u.format1.template get_subtable<typename T::SubTable> (); |
| 2530 | default:return Null(typename T::SubTable); |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 2531 | } |
Behdad Esfahbod | 7dddd4e | 2012-11-23 17:04:55 -0500 | [diff] [blame] | 2532 | } |
| 2533 | |
Behdad Esfahbod | 653eeb2 | 2012-11-23 16:57:36 -0500 | [diff] [blame] | 2534 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 2535 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | 653eeb2 | 2012-11-23 16:57:36 -0500 | [diff] [blame] | 2536 | { |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 2537 | TRACE_DISPATCH (this, u.format); |
Behdad Esfahbod | f396fbb | 2015-10-09 12:25:55 -0400 | [diff] [blame] | 2538 | 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] | 2539 | switch (u.format) { |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2540 | case 1: return_trace (u.format1.dispatch (c)); |
| 2541 | default:return_trace (c->default_return_value ()); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 2542 | } |
| 2543 | } |
| 2544 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 2545 | protected: |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2546 | union { |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 2547 | HBUINT16 format; /* Format identifier */ |
Behdad Esfahbod | 095a125 | 2015-02-19 10:29:41 +0300 | [diff] [blame] | 2548 | ExtensionFormat1<T> format1; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2549 | } u; |
| 2550 | }; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 2551 | |
| 2552 | |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 2553 | /* |
| 2554 | * GSUB/GPOS Common |
| 2555 | */ |
| 2556 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 2557 | struct GSUBGPOS |
| 2558 | { |
Behdad Esfahbod | b912fbe | 2018-08-06 06:30:12 -0700 | [diff] [blame] | 2559 | inline bool has_data (void) const { return version.to_int () != 0; } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 2560 | inline unsigned int get_script_count (void) const |
| 2561 | { return (this+scriptList).len; } |
| 2562 | inline const Tag& get_script_tag (unsigned int i) const |
| 2563 | { return (this+scriptList).get_tag (i); } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 2564 | inline unsigned int get_script_tags (unsigned int start_offset, |
| 2565 | unsigned int *script_count /* IN/OUT */, |
| 2566 | hb_tag_t *script_tags /* OUT */) const |
| 2567 | { return (this+scriptList).get_tags (start_offset, script_count, script_tags); } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 2568 | inline const Script& get_script (unsigned int i) const |
| 2569 | { return (this+scriptList)[i]; } |
| 2570 | inline bool find_script_index (hb_tag_t tag, unsigned int *index) const |
| 2571 | { return (this+scriptList).find_index (tag, index); } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 2572 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 2573 | inline unsigned int get_feature_count (void) const |
| 2574 | { return (this+featureList).len; } |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 2575 | inline hb_tag_t get_feature_tag (unsigned int i) const |
| 2576 | { return i == Index::NOT_FOUND_INDEX ? HB_TAG_NONE : (this+featureList).get_tag (i); } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 2577 | inline unsigned int get_feature_tags (unsigned int start_offset, |
| 2578 | unsigned int *feature_count /* IN/OUT */, |
| 2579 | hb_tag_t *feature_tags /* OUT */) const |
| 2580 | { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 2581 | inline const Feature& get_feature (unsigned int i) const |
| 2582 | { return (this+featureList)[i]; } |
| 2583 | inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const |
| 2584 | { return (this+featureList).find_index (tag, index); } |
| 2585 | |
| 2586 | inline unsigned int get_lookup_count (void) const |
| 2587 | { return (this+lookupList).len; } |
| 2588 | inline const Lookup& get_lookup (unsigned int i) const |
| 2589 | { return (this+lookupList)[i]; } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 2590 | |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 2591 | inline bool find_variations_index (const int *coords, unsigned int num_coords, |
| 2592 | unsigned int *index) const |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 2593 | { return (version.to_int () >= 0x00010001u ? this+featureVars : Null(FeatureVariations)) |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 2594 | .find_index (coords, num_coords, index); } |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 2595 | inline const Feature& get_feature_variation (unsigned int feature_index, |
| 2596 | unsigned int variations_index) const |
| 2597 | { |
| 2598 | if (FeatureVariations::NOT_FOUND_INDEX != variations_index && |
| 2599 | version.to_int () >= 0x00010001u) |
| 2600 | { |
Behdad Esfahbod | 4ebbeb7 | 2016-09-10 04:52:34 -0700 | [diff] [blame] | 2601 | const Feature *feature = (this+featureVars).find_substitute (variations_index, |
| 2602 | feature_index); |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 2603 | if (feature) |
| 2604 | return *feature; |
| 2605 | } |
| 2606 | return get_feature (feature_index); |
| 2607 | } |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 2608 | |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 2609 | template <typename TLookup> |
Behdad Esfahbod | bfa72a9 | 2018-09-01 18:34:50 -0700 | [diff] [blame] | 2610 | inline bool subset (hb_subset_context_t *c) const |
| 2611 | { |
| 2612 | TRACE_SUBSET (this); |
| 2613 | struct GSUBGPOS *out = c->serializer->embed (*this); |
| 2614 | if (unlikely (!out)) return_trace (false); |
Behdad Esfahbod | 49c44b5 | 2018-09-03 16:37:17 -0700 | [diff] [blame] | 2615 | out->scriptList.serialize_subset (c, this+scriptList, out); |
| 2616 | out->featureList.serialize_subset (c, this+featureList, out); |
Behdad Esfahbod | 9c3747c | 2018-09-03 16:53:03 -0700 | [diff] [blame] | 2617 | |
| 2618 | typedef OffsetListOf<TLookup> TLookupList; |
| 2619 | /* TODO Use intersects() to count how many subtables survive? */ |
| 2620 | CastR<OffsetTo<TLookupList> > (out->lookupList) |
| 2621 | .serialize_subset (c, |
| 2622 | this+CastR<const OffsetTo<TLookupList> > (lookupList), |
| 2623 | out); |
| 2624 | |
Behdad Esfahbod | bfa72a9 | 2018-09-01 18:34:50 -0700 | [diff] [blame] | 2625 | if (version.to_int () >= 0x00010001u) |
Behdad Esfahbod | 49c44b5 | 2018-09-03 16:37:17 -0700 | [diff] [blame] | 2626 | out->featureVars.serialize_subset (c, this+featureVars, out); |
Behdad Esfahbod | bfa72a9 | 2018-09-01 18:34:50 -0700 | [diff] [blame] | 2627 | return_trace (true); |
| 2628 | } |
| 2629 | |
| 2630 | inline unsigned int get_size (void) const |
| 2631 | { |
| 2632 | return min_size + |
| 2633 | (version.to_int () >= 0x00010001u ? featureVars.static_size : 0); |
| 2634 | } |
| 2635 | |
Behdad Esfahbod | 6d61852 | 2018-09-03 16:41:28 -0700 | [diff] [blame] | 2636 | template <typename TLookup> |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 2637 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 2638 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 2639 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 6d61852 | 2018-09-03 16:41:28 -0700 | [diff] [blame] | 2640 | typedef OffsetListOf<TLookup> TLookupList; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 2641 | return_trace (version.sanitize (c) && |
| 2642 | likely (version.major == 1) && |
| 2643 | scriptList.sanitize (c, this) && |
| 2644 | featureList.sanitize (c, this) && |
Behdad Esfahbod | 6d61852 | 2018-09-03 16:41:28 -0700 | [diff] [blame] | 2645 | CastR<OffsetTo<TLookupList> > (lookupList).sanitize (c, this) && |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 2646 | (version.to_int () < 0x00010001u || featureVars.sanitize (c, this))); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 2647 | } |
| 2648 | |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 2649 | template <typename T> |
| 2650 | struct accelerator_t |
| 2651 | { |
| 2652 | inline void init (hb_face_t *face) |
| 2653 | { |
| 2654 | this->blob = hb_sanitize_context_t().reference_table<T> (face); |
Behdad Esfahbod | 453e0c6 | 2018-08-26 01:30:52 -0700 | [diff] [blame] | 2655 | table = this->blob->template as<T> (); |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 2656 | |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 2657 | this->lookup_count = table->get_lookup_count (); |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 2658 | |
| 2659 | this->accels = (hb_ot_layout_lookup_accelerator_t *) calloc (this->lookup_count, sizeof (hb_ot_layout_lookup_accelerator_t)); |
| 2660 | if (unlikely (!this->accels)) |
| 2661 | this->lookup_count = 0; |
| 2662 | |
| 2663 | for (unsigned int i = 0; i < this->lookup_count; i++) |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 2664 | this->accels[i].init (table->get_lookup (i)); |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | inline void fini (void) |
| 2668 | { |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 2669 | for (unsigned int i = 0; i < this->lookup_count; i++) |
| 2670 | this->accels[i].fini (); |
| 2671 | free (this->accels); |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 2672 | hb_blob_destroy (this->blob); |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 2675 | hb_blob_t *blob; |
| 2676 | const T *table; |
| 2677 | unsigned int lookup_count; |
| 2678 | hb_ot_layout_lookup_accelerator_t *accels; |
Behdad Esfahbod | 963413f | 2018-08-26 00:47:55 -0700 | [diff] [blame] | 2679 | }; |
| 2680 | |
Behdad Esfahbod | 212aba6 | 2009-05-24 00:50:27 -0400 | [diff] [blame] | 2681 | protected: |
Behdad Esfahbod | 9a13ed4 | 2016-02-22 11:44:45 +0900 | [diff] [blame] | 2682 | FixedVersion<>version; /* Version of the GSUB/GPOS table--initially set |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 2683 | * to 0x00010000u */ |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 2684 | OffsetTo<ScriptList> |
| 2685 | scriptList; /* ScriptList table */ |
| 2686 | OffsetTo<FeatureList> |
| 2687 | featureList; /* FeatureList table */ |
| 2688 | OffsetTo<LookupList> |
| 2689 | lookupList; /* LookupList table */ |
Behdad Esfahbod | 5e156fa | 2017-01-22 20:28:56 -0800 | [diff] [blame] | 2690 | LOffsetTo<FeatureVariations> |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 2691 | featureVars; /* Offset to Feature Variations |
| 2692 | table--from beginning of table |
| 2693 | * (may be NULL). Introduced |
| 2694 | * in version 0x00010001. */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 2695 | public: |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 2696 | DEFINE_SIZE_MIN (10); |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 2697 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 2698 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 2699 | |
Behdad Esfahbod | 7d52e66 | 2012-11-16 18:49:54 -0800 | [diff] [blame] | 2700 | } /* namespace OT */ |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 2701 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 2702 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 2703 | #endif /* HB_OT_LAYOUT_GSUBGPOS_HH */ |