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