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