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