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