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