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 | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 40 | #ifndef HB_DEBUG_CLOSURE |
| 41 | #define HB_DEBUG_CLOSURE (HB_DEBUG+0) |
| 42 | #endif |
| 43 | |
| 44 | #define TRACE_CLOSURE() \ |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 45 | hb_auto_trace_t<HB_DEBUG_CLOSURE> trace (&c->debug_depth, "CLOSURE", this, HB_FUNC, ""); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 46 | |
| 47 | |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 48 | struct hb_closure_context_t |
| 49 | { |
| 50 | hb_face_t *face; |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 51 | hb_set_t *glyphs; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 52 | unsigned int nesting_level_left; |
| 53 | unsigned int debug_depth; |
| 54 | |
| 55 | |
| 56 | hb_closure_context_t (hb_face_t *face_, |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 57 | hb_set_t *glyphs_, |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 58 | unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) : |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 59 | face (face_), |
| 60 | glyphs (glyphs_), |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 61 | nesting_level_left (nesting_level_left_), |
| 62 | debug_depth (0) {} |
| 63 | }; |
| 64 | |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 65 | |
| 66 | |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 67 | /* TODO Add TRACE_RETURN annotation to gsub. */ |
| 68 | #ifndef HB_DEBUG_WOULD_APPLY |
| 69 | #define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0) |
| 70 | #endif |
| 71 | |
| 72 | #define TRACE_WOULD_APPLY() \ |
| 73 | hb_auto_trace_t<HB_DEBUG_WOULD_APPLY> trace (&c->debug_depth, "WOULD_APPLY", this, HB_FUNC, "%d glyphs", c->len); |
| 74 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 75 | |
| 76 | struct hb_would_apply_context_t |
| 77 | { |
| 78 | hb_face_t *face; |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 79 | const hb_codepoint_t *glyphs; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 80 | unsigned int len; |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 81 | bool zero_context; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 82 | unsigned int debug_depth; |
| 83 | |
| 84 | hb_would_apply_context_t (hb_face_t *face_, |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 85 | const hb_codepoint_t *glyphs_, |
| 86 | unsigned int len_, |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 87 | bool zero_context_) : |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 88 | face (face_), |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 89 | glyphs (glyphs_), |
| 90 | len (len_), |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 91 | zero_context (zero_context_), |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 92 | debug_depth (0) {}; |
| 93 | }; |
| 94 | |
| 95 | |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 96 | #ifndef HB_DEBUG_APPLY |
Behdad Esfahbod | 11e3ec4 | 2010-11-03 15:11:04 -0400 | [diff] [blame] | 97 | #define HB_DEBUG_APPLY (HB_DEBUG+0) |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 98 | #endif |
| 99 | |
Behdad Esfahbod | bc20045 | 2010-04-29 01:40:26 -0400 | [diff] [blame] | 100 | #define TRACE_APPLY() \ |
Behdad Esfahbod | 68b7612 | 2012-06-08 10:43:49 -0400 | [diff] [blame] | 101 | hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", this, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); |
Behdad Esfahbod | 74e313c | 2010-04-28 15:15:09 -0400 | [diff] [blame] | 102 | |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 103 | |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 104 | struct hb_apply_context_t |
| 105 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 106 | hb_font_t *font; |
| 107 | hb_face_t *face; |
Behdad Esfahbod | 94a23aa | 2010-05-05 01:13:09 -0400 | [diff] [blame] | 108 | hb_buffer_t *buffer; |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 109 | hb_direction_t direction; |
Behdad Esfahbod | f7acd8d | 2010-05-20 17:26:35 +0100 | [diff] [blame] | 110 | hb_mask_t lookup_mask; |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 111 | unsigned int nesting_level_left; |
Behdad Esfahbod | 8c69e65 | 2010-10-27 22:07:49 -0400 | [diff] [blame] | 112 | unsigned int lookup_props; |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 113 | unsigned int property; /* propety of first glyph */ |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 114 | unsigned int debug_depth; |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 115 | const GDEF &gdef; |
Behdad Esfahbod | 300c730 | 2012-07-30 19:37:44 -0400 | [diff] [blame] | 116 | bool has_glyph_classes; |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 117 | |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 118 | |
| 119 | hb_apply_context_t (hb_font_t *font_, |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 120 | hb_buffer_t *buffer_, |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 121 | hb_mask_t lookup_mask_) : |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 122 | font (font_), face (font->face), buffer (buffer_), |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 123 | direction (buffer_->props.direction), |
| 124 | lookup_mask (lookup_mask_), |
Behdad Esfahbod | 6736f3c | 2012-05-13 15:21:06 +0200 | [diff] [blame] | 125 | nesting_level_left (MAX_NESTING_LEVEL), |
Behdad Esfahbod | 60da763 | 2012-07-16 16:13:32 -0400 | [diff] [blame] | 126 | lookup_props (0), property (0), debug_depth (0), |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 127 | gdef (*hb_ot_layout_from_face (face)->gdef), |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 128 | has_glyph_classes (gdef.has_glyph_classes ()) {} |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 129 | |
Behdad Esfahbod | 2fcbbdb | 2012-08-29 11:11:54 -0400 | [diff] [blame] | 130 | void set_lookup_props (unsigned int lookup_props_) { |
| 131 | lookup_props = lookup_props_; |
| 132 | } |
| 133 | |
Behdad Esfahbod | 650ac00 | 2012-04-23 13:17:09 -0400 | [diff] [blame] | 134 | void set_lookup (const Lookup &l) { |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 135 | lookup_props = l.get_props (); |
| 136 | } |
| 137 | |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 138 | struct mark_skipping_forward_iterator_t |
| 139 | { |
| 140 | inline mark_skipping_forward_iterator_t (hb_apply_context_t *c_, |
| 141 | unsigned int start_index_, |
Behdad Esfahbod | 203d710 | 2012-05-11 16:01:44 +0200 | [diff] [blame] | 142 | unsigned int num_items_, |
Behdad Esfahbod | 28b9d50 | 2012-05-13 15:04:00 +0200 | [diff] [blame] | 143 | bool context_match = false) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 144 | { |
| 145 | c = c_; |
| 146 | idx = start_index_; |
| 147 | num_items = num_items_; |
Behdad Esfahbod | 28b9d50 | 2012-05-13 15:04:00 +0200 | [diff] [blame] | 148 | mask = context_match ? -1 : c->lookup_mask; |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 149 | syllable = context_match ? 0 : c->buffer->cur().syllable (); |
Behdad Esfahbod | 5df809b | 2012-05-13 15:17:51 +0200 | [diff] [blame] | 150 | end = c->buffer->len; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 151 | } |
| 152 | inline bool has_no_chance (void) const |
| 153 | { |
| 154 | return unlikely (num_items && idx + num_items >= end); |
| 155 | } |
Behdad Esfahbod | b12e254 | 2012-06-09 03:05:20 -0400 | [diff] [blame] | 156 | inline void reject (void) |
Behdad Esfahbod | 7b84c53 | 2012-06-08 22:04:23 -0400 | [diff] [blame] | 157 | { |
| 158 | num_items++; |
| 159 | } |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 160 | inline bool next (unsigned int *property_out, |
Behdad Esfahbod | 8932858 | 2012-07-19 21:02:38 -0400 | [diff] [blame] | 161 | unsigned int lookup_props) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 162 | { |
Behdad Esfahbod | 506ffeb | 2012-01-18 16:07:53 -0500 | [diff] [blame] | 163 | assert (num_items > 0); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 164 | do |
| 165 | { |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 166 | if (has_no_chance ()) |
| 167 | return false; |
Behdad Esfahbod | a4a48fe | 2012-01-17 18:08:41 -0500 | [diff] [blame] | 168 | idx++; |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 169 | } while (c->should_skip_mark (&c->buffer->info[idx], lookup_props, property_out)); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 170 | num_items--; |
Behdad Esfahbod | 5f131d3 | 2012-05-11 17:29:40 +0200 | [diff] [blame] | 171 | return (c->buffer->info[idx].mask & mask) && (!syllable || syllable == c->buffer->info[idx].syllable ()); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 172 | } |
| 173 | inline bool next (unsigned int *property_out = NULL) |
| 174 | { |
| 175 | return next (property_out, c->lookup_props); |
| 176 | } |
| 177 | |
| 178 | unsigned int idx; |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 179 | protected: |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 180 | hb_apply_context_t *c; |
| 181 | unsigned int num_items; |
Behdad Esfahbod | 203d710 | 2012-05-11 16:01:44 +0200 | [diff] [blame] | 182 | hb_mask_t mask; |
Behdad Esfahbod | 5f131d3 | 2012-05-11 17:29:40 +0200 | [diff] [blame] | 183 | uint8_t syllable; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 184 | unsigned int end; |
| 185 | }; |
| 186 | |
| 187 | struct mark_skipping_backward_iterator_t |
| 188 | { |
| 189 | inline mark_skipping_backward_iterator_t (hb_apply_context_t *c_, |
| 190 | unsigned int start_index_, |
Behdad Esfahbod | 203d710 | 2012-05-11 16:01:44 +0200 | [diff] [blame] | 191 | unsigned int num_items_, |
Behdad Esfahbod | 5f131d3 | 2012-05-11 17:29:40 +0200 | [diff] [blame] | 192 | hb_mask_t mask_ = 0, |
Behdad Esfahbod | 6736f3c | 2012-05-13 15:21:06 +0200 | [diff] [blame] | 193 | bool match_syllable_ = true) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 194 | { |
| 195 | c = c_; |
| 196 | idx = start_index_; |
| 197 | num_items = num_items_; |
Behdad Esfahbod | 203d710 | 2012-05-11 16:01:44 +0200 | [diff] [blame] | 198 | mask = mask_ ? mask_ : c->lookup_mask; |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 199 | syllable = match_syllable_ ? c->buffer->cur().syllable () : 0; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 200 | } |
| 201 | inline bool has_no_chance (void) const |
| 202 | { |
Behdad Esfahbod | 506ffeb | 2012-01-18 16:07:53 -0500 | [diff] [blame] | 203 | return unlikely (idx < num_items); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 204 | } |
Behdad Esfahbod | b12e254 | 2012-06-09 03:05:20 -0400 | [diff] [blame] | 205 | inline void reject (void) |
Behdad Esfahbod | 7b84c53 | 2012-06-08 22:04:23 -0400 | [diff] [blame] | 206 | { |
| 207 | num_items++; |
| 208 | } |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 209 | inline bool prev (unsigned int *property_out, |
Behdad Esfahbod | 8932858 | 2012-07-19 21:02:38 -0400 | [diff] [blame] | 210 | unsigned int lookup_props) |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 211 | { |
Behdad Esfahbod | 506ffeb | 2012-01-18 16:07:53 -0500 | [diff] [blame] | 212 | assert (num_items > 0); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 213 | do |
| 214 | { |
| 215 | if (has_no_chance ()) |
| 216 | return false; |
| 217 | idx--; |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 218 | } while (c->should_skip_mark (&c->buffer->out_info[idx], lookup_props, property_out)); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 219 | num_items--; |
Behdad Esfahbod | 5f131d3 | 2012-05-11 17:29:40 +0200 | [diff] [blame] | 220 | return (c->buffer->out_info[idx].mask & mask) && (!syllable || syllable == c->buffer->out_info[idx].syllable ()); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 221 | } |
| 222 | inline bool prev (unsigned int *property_out = NULL) |
| 223 | { |
| 224 | return prev (property_out, c->lookup_props); |
| 225 | } |
| 226 | |
| 227 | unsigned int idx; |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 228 | protected: |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 229 | hb_apply_context_t *c; |
| 230 | unsigned int num_items; |
Behdad Esfahbod | 203d710 | 2012-05-11 16:01:44 +0200 | [diff] [blame] | 231 | hb_mask_t mask; |
Behdad Esfahbod | 5f131d3 | 2012-05-11 17:29:40 +0200 | [diff] [blame] | 232 | uint8_t syllable; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 233 | }; |
| 234 | |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 235 | inline bool |
| 236 | match_properties_mark (hb_codepoint_t glyph, |
| 237 | unsigned int glyph_props, |
| 238 | unsigned int lookup_props) const |
| 239 | { |
| 240 | /* If using mark filtering sets, the high short of |
| 241 | * lookup_props has the set index. |
| 242 | */ |
| 243 | if (lookup_props & LookupFlag::UseMarkFilteringSet) |
| 244 | return gdef.mark_set_covers (lookup_props >> 16, glyph); |
| 245 | |
| 246 | /* The second byte of lookup_props has the meaning |
| 247 | * "ignore marks of attachment type different than |
| 248 | * the attachment type specified." |
| 249 | */ |
| 250 | if (lookup_props & LookupFlag::MarkAttachmentType) |
| 251 | return (lookup_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType); |
| 252 | |
| 253 | return true; |
| 254 | } |
| 255 | |
| 256 | inline bool |
| 257 | match_properties (hb_codepoint_t glyph, |
| 258 | unsigned int glyph_props, |
| 259 | unsigned int lookup_props) const |
| 260 | { |
| 261 | /* Not covered, if, for example, glyph class is ligature and |
| 262 | * lookup_props includes LookupFlags::IgnoreLigatures |
| 263 | */ |
| 264 | if (glyph_props & lookup_props & LookupFlag::IgnoreFlags) |
| 265 | return false; |
| 266 | |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 267 | if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 268 | return match_properties_mark (glyph, glyph_props, lookup_props); |
| 269 | |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | inline bool |
| 274 | check_glyph_property (hb_glyph_info_t *info, |
| 275 | unsigned int lookup_props, |
| 276 | unsigned int *property_out) const |
Behdad Esfahbod | 7d47990 | 2012-01-18 21:19:32 -0500 | [diff] [blame] | 277 | { |
Behdad Esfahbod | ce47613 | 2012-06-09 01:10:26 -0400 | [diff] [blame] | 278 | unsigned int property; |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 279 | |
Behdad Esfahbod | c2e42c3 | 2012-07-30 19:54:50 -0400 | [diff] [blame] | 280 | property = info->glyph_props(); |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 281 | *property_out = property; |
| 282 | |
| 283 | return match_properties (info->codepoint, property, lookup_props); |
| 284 | } |
| 285 | |
| 286 | inline bool |
| 287 | should_skip_mark (hb_glyph_info_t *info, |
| 288 | unsigned int lookup_props, |
| 289 | unsigned int *property_out) const |
| 290 | { |
| 291 | unsigned int property; |
| 292 | |
Behdad Esfahbod | c2e42c3 | 2012-07-30 19:54:50 -0400 | [diff] [blame] | 293 | property = info->glyph_props(); |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 294 | if (property_out) |
| 295 | *property_out = property; |
| 296 | |
| 297 | /* If it's a mark, skip it if we don't accept it. */ |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 298 | if (unlikely (property & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 299 | return !match_properties (info->codepoint, property, lookup_props); |
| 300 | |
| 301 | /* If not a mark, don't skip. */ |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | inline bool should_mark_skip_current_glyph (void) const |
| 307 | { |
| 308 | return should_skip_mark (&buffer->cur(), lookup_props, NULL); |
Behdad Esfahbod | 7d47990 | 2012-01-18 21:19:32 -0500 | [diff] [blame] | 309 | } |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 310 | |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 311 | 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] | 312 | { |
Behdad Esfahbod | 2fca142 | 2012-07-30 18:46:41 -0400 | [diff] [blame] | 313 | if (likely (has_glyph_classes)) |
Behdad Esfahbod | c2e42c3 | 2012-07-30 19:54:50 -0400 | [diff] [blame] | 314 | buffer->cur().glyph_props() = gdef.get_glyph_props (glyph_index); |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 315 | else if (class_guess) |
Behdad Esfahbod | c2e42c3 | 2012-07-30 19:54:50 -0400 | [diff] [blame] | 316 | buffer->cur().glyph_props() = class_guess; |
Behdad Esfahbod | 60da763 | 2012-07-16 16:13:32 -0400 | [diff] [blame] | 317 | } |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 318 | |
Behdad Esfahbod | 3ec77d6 | 2012-06-08 21:44:06 -0400 | [diff] [blame] | 319 | inline void output_glyph (hb_codepoint_t glyph_index, |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 320 | unsigned int class_guess = 0) const |
Behdad Esfahbod | 3ec77d6 | 2012-06-08 21:44:06 -0400 | [diff] [blame] | 321 | { |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 322 | set_class (glyph_index, class_guess); |
Behdad Esfahbod | 3ec77d6 | 2012-06-08 21:44:06 -0400 | [diff] [blame] | 323 | buffer->output_glyph (glyph_index); |
| 324 | } |
Behdad Esfahbod | ed2f136 | 2012-05-22 22:12:22 -0400 | [diff] [blame] | 325 | inline void replace_glyph (hb_codepoint_t glyph_index, |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 326 | unsigned int class_guess = 0) const |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 327 | { |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 328 | set_class (glyph_index, class_guess); |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 329 | buffer->replace_glyph (glyph_index); |
| 330 | } |
Behdad Esfahbod | 7fbbf86 | 2012-07-30 18:36:42 -0400 | [diff] [blame] | 331 | inline void replace_glyph_inplace (hb_codepoint_t glyph_index, |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 332 | unsigned int class_guess = 0) const |
Behdad Esfahbod | 7fbbf86 | 2012-07-30 18:36:42 -0400 | [diff] [blame] | 333 | { |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 334 | set_class (glyph_index, class_guess); |
Behdad Esfahbod | 7fbbf86 | 2012-07-30 18:36:42 -0400 | [diff] [blame] | 335 | buffer->cur().codepoint = glyph_index; |
| 336 | } |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 337 | }; |
| 338 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 339 | |
Behdad Esfahbod | 94a23aa | 2010-05-05 01:13:09 -0400 | [diff] [blame] | 340 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 341 | typedef bool (*intersects_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data); |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 342 | typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 343 | typedef void (*closure_lookup_func_t) (hb_closure_context_t *c, unsigned int lookup_index); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 344 | typedef bool (*apply_lookup_func_t) (hb_apply_context_t *c, unsigned int lookup_index); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 345 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 346 | struct ContextClosureFuncs |
| 347 | { |
| 348 | intersects_func_t intersects; |
| 349 | closure_lookup_func_t closure; |
| 350 | }; |
| 351 | struct ContextApplyFuncs |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 352 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 353 | match_func_t match; |
| 354 | apply_lookup_func_t apply; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 355 | }; |
| 356 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 357 | 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] | 358 | { |
| 359 | return glyphs->has (value); |
| 360 | } |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 361 | 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] | 362 | { |
| 363 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
| 364 | return class_def.intersects_class (glyphs, value); |
| 365 | } |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 366 | 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] | 367 | { |
| 368 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
| 369 | return (data+coverage).intersects (glyphs); |
| 370 | } |
| 371 | |
| 372 | static inline bool intersects_array (hb_closure_context_t *c, |
| 373 | unsigned int count, |
| 374 | const USHORT values[], |
| 375 | intersects_func_t intersects_func, |
| 376 | const void *intersects_data) |
| 377 | { |
| 378 | for (unsigned int i = 0; i < count; i++) |
| 379 | if (likely (!intersects_func (c->glyphs, values[i], intersects_data))) |
| 380 | return false; |
| 381 | return true; |
| 382 | } |
| 383 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 384 | |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 385 | 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] | 386 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 387 | return glyph_id == value; |
| 388 | } |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 389 | 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] | 390 | { |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 391 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 392 | return class_def.get_class (glyph_id) == value; |
| 393 | } |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 394 | 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] | 395 | { |
Behdad Esfahbod | 6b54c5d | 2009-05-18 18:30:25 -0400 | [diff] [blame] | 396 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 397 | return (data+coverage).get_coverage (glyph_id) != NOT_COVERED; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 398 | } |
| 399 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 400 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 401 | static inline bool would_match_input (hb_would_apply_context_t *c, |
| 402 | unsigned int count, /* Including the first glyph (not matched) */ |
| 403 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 404 | match_func_t match_func, |
| 405 | const void *match_data) |
| 406 | { |
| 407 | if (count != c->len) |
| 408 | return false; |
| 409 | |
| 410 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 411 | if (likely (!match_func (c->glyphs[i], input[i - 1], match_data))) |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 412 | return false; |
| 413 | |
| 414 | return true; |
| 415 | } |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 416 | static inline bool match_input (hb_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 417 | unsigned int count, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 418 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 419 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 420 | const void *match_data, |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 421 | unsigned int *end_offset = NULL, |
| 422 | bool *p_is_mark_ligature = NULL, |
| 423 | unsigned int *p_total_component_count = NULL) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 424 | { |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 425 | hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); |
| 426 | |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 427 | hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 428 | if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); |
| 429 | |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 430 | /* |
| 431 | * This is perhaps the trickiest part of OpenType... Remarks: |
| 432 | * |
| 433 | * - If all components of the ligature were marks, we call this a mark ligature. |
| 434 | * |
| 435 | * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize |
| 436 | * it as a ligature glyph. |
| 437 | * |
| 438 | * - Ligatures cannot be formed across glyphs attached to different components |
| 439 | * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and |
| 440 | * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother. |
| 441 | * However, it would be wrong to ligate that SHADDA,FATHA sequence.o |
| 442 | * There is an exception to this: If a ligature tries ligating with marks that |
| 443 | * belong to it itself, go ahead, assuming that the font designer knows what |
| 444 | * they are doing (otherwise it can break Indic stuff when a matra wants to |
| 445 | * ligate with a conjunct...) |
| 446 | */ |
| 447 | |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 448 | bool is_mark_ligature = !!(c->property & HB_OT_LAYOUT_GLYPH_PROPS_MARK); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 449 | |
| 450 | unsigned int total_component_count = 0; |
| 451 | total_component_count += get_lig_num_comps (c->buffer->cur()); |
| 452 | |
| 453 | unsigned int first_lig_id = get_lig_id (c->buffer->cur()); |
| 454 | unsigned int first_lig_comp = get_lig_comp (c->buffer->cur()); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 455 | |
Behdad Esfahbod | 370f03e | 2012-01-16 17:03:55 -0500 | [diff] [blame] | 456 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 457 | { |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 458 | unsigned int property; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 459 | |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 460 | if (!skippy_iter.next (&property)) return TRACE_RETURN (false); |
| 461 | |
Behdad Esfahbod | 2616689 | 2012-10-29 21:51:56 -0700 | [diff] [blame] | 462 | if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, input[i - 1], match_data))) return TRACE_RETURN (false); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 463 | |
| 464 | unsigned int this_lig_id = get_lig_id (c->buffer->info[skippy_iter.idx]); |
| 465 | unsigned int this_lig_comp = get_lig_comp (c->buffer->info[skippy_iter.idx]); |
| 466 | |
| 467 | if (first_lig_id && first_lig_comp) { |
| 468 | /* If first component was attached to a previous ligature component, |
| 469 | * all subsequent components should be attached to the same ligature |
| 470 | * component, otherwise we shouldn't ligate them. */ |
| 471 | if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp) |
| 472 | return TRACE_RETURN (false); |
| 473 | } else { |
| 474 | /* If first component was NOT attached to a previous ligature component, |
| 475 | * all subsequent components should also NOT be attached to any ligature |
| 476 | * component, unless they are attached to the first component itself! */ |
| 477 | if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id)) |
| 478 | return TRACE_RETURN (false); |
| 479 | } |
| 480 | |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 481 | is_mark_ligature = is_mark_ligature && (property & HB_OT_LAYOUT_GLYPH_PROPS_MARK); |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 482 | 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] | 483 | } |
| 484 | |
Behdad Esfahbod | 5df809b | 2012-05-13 15:17:51 +0200 | [diff] [blame] | 485 | if (end_offset) |
| 486 | *end_offset = skippy_iter.idx - c->buffer->idx + 1; |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 487 | |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 488 | if (p_is_mark_ligature) |
| 489 | *p_is_mark_ligature = is_mark_ligature; |
| 490 | |
| 491 | if (p_total_component_count) |
| 492 | *p_total_component_count = total_component_count; |
| 493 | |
Behdad Esfahbod | bc513ad | 2012-10-29 19:03:55 -0700 | [diff] [blame] | 494 | return TRACE_RETURN (true); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 495 | } |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 496 | static inline void ligate_input (hb_apply_context_t *c, |
| 497 | unsigned int count, /* Including the first glyph (not matched) */ |
| 498 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 499 | hb_codepoint_t lig_glyph, |
| 500 | match_func_t match_func, |
| 501 | const void *match_data, |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 502 | bool is_mark_ligature, |
| 503 | unsigned int total_component_count) |
| 504 | { |
| 505 | /* |
| 506 | * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave |
| 507 | * the ligature to keep its old ligature id. This will allow it to attach to |
| 508 | * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH, |
| 509 | * and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a |
| 510 | * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature |
| 511 | * later, we don't want them to lose their ligature id/component, otherwise |
| 512 | * GPOS will fail to correctly position the mark ligature on top of the |
| 513 | * LAM,LAM,HEH ligature. See: |
| 514 | * https://bugzilla.gnome.org/show_bug.cgi?id=676343 |
| 515 | * |
| 516 | * - If a ligature is formed of components that some of which are also ligatures |
| 517 | * themselves, and those ligature components had marks attached to *their* |
| 518 | * components, we have to attach the marks to the new ligature component |
| 519 | * positions! Now *that*'s tricky! And these marks may be following the |
| 520 | * last component of the whole sequence, so we should loop forward looking |
| 521 | * for them and update them. |
| 522 | * |
| 523 | * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a |
| 524 | * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature |
| 525 | * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature |
| 526 | * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to |
| 527 | * the new ligature with a component value of 2. |
| 528 | * |
| 529 | * This in fact happened to a font... See: |
| 530 | * https://bugzilla.gnome.org/show_bug.cgi?id=437633 |
| 531 | */ |
| 532 | |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 533 | 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] | 534 | unsigned int lig_id = is_mark_ligature ? 0 : allocate_lig_id (c->buffer); |
| 535 | unsigned int last_lig_id = get_lig_id (c->buffer->cur()); |
| 536 | unsigned int last_num_components = get_lig_num_comps (c->buffer->cur()); |
| 537 | unsigned int components_so_far = last_num_components; |
| 538 | |
| 539 | if (!is_mark_ligature) |
| 540 | set_lig_props_for_ligature (c->buffer->cur(), lig_id, total_component_count); |
| 541 | c->replace_glyph (lig_glyph, klass); |
| 542 | |
| 543 | for (unsigned int i = 1; i < count; i++) |
| 544 | { |
| 545 | while (c->should_mark_skip_current_glyph ()) |
| 546 | { |
| 547 | if (!is_mark_ligature) { |
| 548 | unsigned int new_lig_comp = components_so_far - last_num_components + |
| 549 | MIN (MAX (get_lig_comp (c->buffer->cur()), 1u), last_num_components); |
| 550 | set_lig_props_for_mark (c->buffer->cur(), lig_id, new_lig_comp); |
| 551 | } |
| 552 | c->buffer->next_glyph (); |
| 553 | } |
| 554 | |
| 555 | last_lig_id = get_lig_id (c->buffer->cur()); |
| 556 | last_num_components = get_lig_num_comps (c->buffer->cur()); |
| 557 | components_so_far += last_num_components; |
| 558 | |
| 559 | /* Skip the base glyph */ |
| 560 | c->buffer->idx++; |
| 561 | } |
| 562 | |
| 563 | if (!is_mark_ligature && last_lig_id) { |
| 564 | /* Re-adjust components for any marks following. */ |
| 565 | for (unsigned int i = c->buffer->idx; i < c->buffer->len; i++) { |
| 566 | if (last_lig_id == get_lig_id (c->buffer->info[i])) { |
| 567 | unsigned int new_lig_comp = components_so_far - last_num_components + |
| 568 | MIN (MAX (get_lig_comp (c->buffer->info[i]), 1u), last_num_components); |
| 569 | set_lig_props_for_mark (c->buffer->info[i], lig_id, new_lig_comp); |
| 570 | } else |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | } |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 575 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 576 | static inline bool match_backtrack (hb_apply_context_t *c, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 577 | unsigned int count, |
| 578 | const USHORT backtrack[], |
| 579 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 580 | const void *match_data) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 581 | { |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 582 | hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); |
| 583 | |
Behdad Esfahbod | 28b9d50 | 2012-05-13 15:04:00 +0200 | [diff] [blame] | 584 | hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 585 | if (skippy_iter.has_no_chance ()) |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 586 | return TRACE_RETURN (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 587 | |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame] | 588 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 589 | { |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 590 | if (!skippy_iter.prev ()) |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 591 | return TRACE_RETURN (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 592 | |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 593 | if (likely (!match_func (c->buffer->out_info[skippy_iter.idx].codepoint, backtrack[i], match_data))) |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 594 | return TRACE_RETURN (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 595 | } |
| 596 | |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 597 | return TRACE_RETURN (true); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 598 | } |
| 599 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 600 | static inline bool match_lookahead (hb_apply_context_t *c, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 601 | unsigned int count, |
| 602 | const USHORT lookahead[], |
| 603 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 604 | const void *match_data, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 605 | unsigned int offset) |
| 606 | { |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 607 | hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); |
| 608 | |
Behdad Esfahbod | 28b9d50 | 2012-05-13 15:04:00 +0200 | [diff] [blame] | 609 | hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 610 | if (skippy_iter.has_no_chance ()) |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 611 | return TRACE_RETURN (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 612 | |
Behdad Esfahbod | 370f03e | 2012-01-16 17:03:55 -0500 | [diff] [blame] | 613 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 614 | { |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 615 | if (!skippy_iter.next ()) |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 616 | return TRACE_RETURN (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 617 | |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 618 | if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, lookahead[i], match_data))) |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 619 | return TRACE_RETURN (false); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 620 | } |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 621 | |
Behdad Esfahbod | 93814ca | 2012-08-28 22:24:51 -0400 | [diff] [blame] | 622 | return TRACE_RETURN (true); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 623 | } |
| 624 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 625 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 626 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 627 | struct LookupRecord |
| 628 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 629 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 630 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 631 | return TRACE_RETURN (c->check_struct (this)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 632 | } |
| 633 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 634 | USHORT sequenceIndex; /* Index into current glyph |
| 635 | * sequence--first glyph = 0 */ |
| 636 | USHORT lookupListIndex; /* Lookup to apply to that |
| 637 | * position--zero--based */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 638 | public: |
| 639 | DEFINE_SIZE_STATIC (4); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 640 | }; |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 641 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 642 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 643 | static inline void closure_lookup (hb_closure_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 644 | unsigned int lookupCount, |
| 645 | const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ |
| 646 | closure_lookup_func_t closure_func) |
| 647 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 648 | for (unsigned int i = 0; i < lookupCount; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 649 | closure_func (c, lookupRecord->lookupListIndex); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 650 | } |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 651 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 652 | static inline bool apply_lookup (hb_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 653 | unsigned int count, /* Including the first glyph */ |
| 654 | unsigned int lookupCount, |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 655 | const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ |
| 656 | apply_lookup_func_t apply_func) |
| 657 | { |
Behdad Esfahbod | 2616689 | 2012-10-29 21:51:56 -0700 | [diff] [blame] | 658 | hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); |
Behdad Esfahbod | 5df809b | 2012-05-13 15:17:51 +0200 | [diff] [blame] | 659 | unsigned int end = c->buffer->len; |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 660 | if (unlikely (count == 0 || c->buffer->idx + count > end)) |
Behdad Esfahbod | 2616689 | 2012-10-29 21:51:56 -0700 | [diff] [blame] | 661 | return TRACE_RETURN (false); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 662 | |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 663 | /* TODO We don't support lookupRecord arrays that are not increasing: |
| 664 | * Should be easy for in_place ones at least. */ |
Behdad Esfahbod | 52e9a71 | 2009-09-21 13:58:56 -0400 | [diff] [blame] | 665 | |
Behdad Esfahbod | 7eb8751 | 2010-12-13 14:13:35 -0500 | [diff] [blame] | 666 | /* Note: If sublookup is reverse, it will underflow after the first loop |
Behdad Esfahbod | 52e9a71 | 2009-09-21 13:58:56 -0400 | [diff] [blame] | 667 | * and we jump out of it. Not entirely disastrous. So we don't check |
| 668 | * for reverse lookup here. |
| 669 | */ |
Behdad Esfahbod | f9c0a2d | 2009-09-21 13:43:54 -0400 | [diff] [blame] | 670 | for (unsigned int i = 0; i < count; /* NOP */) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 671 | { |
Behdad Esfahbod | 03408ce | 2012-01-18 21:28:34 -0500 | [diff] [blame] | 672 | if (unlikely (c->buffer->idx == end)) |
Behdad Esfahbod | 2616689 | 2012-10-29 21:51:56 -0700 | [diff] [blame] | 673 | return TRACE_RETURN (true); |
Behdad Esfahbod | 7d47990 | 2012-01-18 21:19:32 -0500 | [diff] [blame] | 674 | while (c->should_mark_skip_current_glyph ()) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 675 | { |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 676 | /* No lookup applied for this index */ |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 677 | c->buffer->next_glyph (); |
Behdad Esfahbod | 03408ce | 2012-01-18 21:28:34 -0500 | [diff] [blame] | 678 | if (unlikely (c->buffer->idx == end)) |
Behdad Esfahbod | 2616689 | 2012-10-29 21:51:56 -0700 | [diff] [blame] | 679 | return TRACE_RETURN (true); |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 680 | } |
| 681 | |
Behdad Esfahbod | 47958de | 2009-05-18 04:17:47 -0400 | [diff] [blame] | 682 | if (lookupCount && i == lookupRecord->sequenceIndex) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 683 | { |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 684 | unsigned int old_pos = c->buffer->idx; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 685 | |
| 686 | /* Apply a lookup */ |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 687 | bool done = apply_func (c, lookupRecord->lookupListIndex); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 688 | |
Behdad Esfahbod | 47958de | 2009-05-18 04:17:47 -0400 | [diff] [blame] | 689 | lookupRecord++; |
| 690 | lookupCount--; |
Behdad Esfahbod | f9c0a2d | 2009-09-21 13:43:54 -0400 | [diff] [blame] | 691 | /* Err, this is wrong if the lookup jumped over some glyphs */ |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 692 | i += c->buffer->idx - old_pos; |
| 693 | if (unlikely (c->buffer->idx == end)) |
Behdad Esfahbod | 2616689 | 2012-10-29 21:51:56 -0700 | [diff] [blame] | 694 | return TRACE_RETURN (true); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 695 | |
| 696 | if (!done) |
| 697 | goto not_applied; |
| 698 | } |
| 699 | else |
| 700 | { |
| 701 | not_applied: |
| 702 | /* No lookup applied for this index */ |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 703 | c->buffer->next_glyph (); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 704 | i++; |
| 705 | } |
| 706 | } |
| 707 | |
Behdad Esfahbod | 2616689 | 2012-10-29 21:51:56 -0700 | [diff] [blame] | 708 | return TRACE_RETURN (true); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 709 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 710 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 711 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 712 | |
| 713 | /* Contextual lookups */ |
| 714 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 715 | struct ContextClosureLookupContext |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 716 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 717 | ContextClosureFuncs funcs; |
| 718 | const void *intersects_data; |
| 719 | }; |
| 720 | |
| 721 | struct ContextApplyLookupContext |
| 722 | { |
| 723 | ContextApplyFuncs funcs; |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 724 | const void *match_data; |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 725 | }; |
| 726 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 727 | static inline void context_closure_lookup (hb_closure_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 728 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 729 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 730 | unsigned int lookupCount, |
| 731 | const LookupRecord lookupRecord[], |
| 732 | ContextClosureLookupContext &lookup_context) |
| 733 | { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 734 | if (intersects_array (c, |
| 735 | inputCount ? inputCount - 1 : 0, input, |
| 736 | lookup_context.funcs.intersects, lookup_context.intersects_data)) |
| 737 | closure_lookup (c, |
| 738 | lookupCount, lookupRecord, |
| 739 | lookup_context.funcs.closure); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 743 | static inline bool context_would_apply_lookup (hb_would_apply_context_t *c, |
| 744 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 745 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 746 | unsigned int lookupCount, |
| 747 | const LookupRecord lookupRecord[], |
| 748 | ContextApplyLookupContext &lookup_context) |
| 749 | { |
| 750 | return would_match_input (c, |
| 751 | inputCount, input, |
| 752 | lookup_context.funcs.match, lookup_context.match_data); |
| 753 | } |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 754 | static inline bool context_apply_lookup (hb_apply_context_t *c, |
| 755 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 756 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 757 | unsigned int lookupCount, |
| 758 | const LookupRecord lookupRecord[], |
| 759 | ContextApplyLookupContext &lookup_context) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 760 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 761 | return match_input (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 762 | inputCount, input, |
Behdad Esfahbod | 5df809b | 2012-05-13 15:17:51 +0200 | [diff] [blame] | 763 | lookup_context.funcs.match, lookup_context.match_data) |
| 764 | && apply_lookup (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 765 | inputCount, |
| 766 | lookupCount, lookupRecord, |
| 767 | lookup_context.funcs.apply); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 768 | } |
| 769 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 770 | struct Rule |
| 771 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 772 | friend struct RuleSet; |
| 773 | |
| 774 | private: |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 775 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 776 | inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 777 | { |
| 778 | TRACE_CLOSURE (); |
| 779 | 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] | 780 | context_closure_lookup (c, |
| 781 | inputCount, input, |
| 782 | lookupCount, lookupRecord, |
| 783 | lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 784 | } |
| 785 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 786 | inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const |
| 787 | { |
| 788 | TRACE_WOULD_APPLY (); |
| 789 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); |
| 790 | return TRACE_RETURN (context_would_apply_lookup (c, inputCount, input, lookupCount, lookupRecord, lookup_context)); |
| 791 | } |
| 792 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 793 | inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 794 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 795 | TRACE_APPLY (); |
Behdad Esfahbod | e45d3f8 | 2010-05-06 19:33:31 -0400 | [diff] [blame] | 796 | 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] | 797 | 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] | 798 | } |
| 799 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 800 | public: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 801 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 802 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 803 | return inputCount.sanitize (c) |
| 804 | && lookupCount.sanitize (c) |
| 805 | && c->check_range (input, |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 806 | input[0].static_size * inputCount |
| 807 | + lookupRecordX[0].static_size * lookupCount); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 808 | } |
| 809 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 810 | protected: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 811 | USHORT inputCount; /* Total number of glyphs in input |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 812 | * glyph sequence--includes the first |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 813 | * glyph */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 814 | USHORT lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 815 | USHORT input[VAR]; /* Array of match inputs--start with |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 816 | * second glyph */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 817 | LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 818 | * design order */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 819 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 820 | DEFINE_SIZE_ARRAY2 (4, input, lookupRecordX); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 821 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 822 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 823 | struct RuleSet |
| 824 | { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 825 | inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 826 | { |
| 827 | TRACE_CLOSURE (); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 828 | unsigned int num_rules = rule.len; |
| 829 | for (unsigned int i = 0; i < num_rules; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 830 | (this+rule[i]).closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 831 | } |
| 832 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 833 | inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const |
| 834 | { |
| 835 | TRACE_WOULD_APPLY (); |
| 836 | unsigned int num_rules = rule.len; |
| 837 | for (unsigned int i = 0; i < num_rules; i++) |
| 838 | { |
| 839 | if ((this+rule[i]).would_apply (c, lookup_context)) |
| 840 | return TRACE_RETURN (true); |
| 841 | } |
| 842 | return TRACE_RETURN (false); |
| 843 | } |
| 844 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 845 | inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 846 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 847 | TRACE_APPLY (); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 848 | unsigned int num_rules = rule.len; |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 849 | for (unsigned int i = 0; i < num_rules; i++) |
| 850 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 851 | if ((this+rule[i]).apply (c, lookup_context)) |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 852 | return TRACE_RETURN (true); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 853 | } |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 854 | return TRACE_RETURN (false); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 855 | } |
| 856 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 857 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 858 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 859 | return TRACE_RETURN (rule.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 860 | } |
| 861 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 862 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 863 | OffsetArrayOf<Rule> |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 864 | rule; /* Array of Rule tables |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 865 | * ordered by preference */ |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 866 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 867 | DEFINE_SIZE_ARRAY (2, rule); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 868 | }; |
| 869 | |
| 870 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 871 | struct ContextFormat1 |
| 872 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 873 | friend struct Context; |
| 874 | |
| 875 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 876 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 877 | inline void closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 878 | { |
| 879 | TRACE_CLOSURE (); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 880 | |
| 881 | const Coverage &cov = (this+coverage); |
| 882 | |
| 883 | struct ContextClosureLookupContext lookup_context = { |
| 884 | {intersects_glyph, closure_func}, |
| 885 | NULL |
| 886 | }; |
| 887 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 888 | unsigned int count = ruleSet.len; |
| 889 | for (unsigned int i = 0; i < count; i++) |
| 890 | if (cov.intersects_coverage (c->glyphs, i)) { |
| 891 | const RuleSet &rule_set = this+ruleSet[i]; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 892 | rule_set.closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 893 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 894 | } |
| 895 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 896 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 897 | { |
| 898 | TRACE_WOULD_APPLY (); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 899 | |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 900 | const RuleSet &rule_set = this+ruleSet[(this+coverage) (c->glyphs[0])]; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 901 | struct ContextApplyLookupContext lookup_context = { |
| 902 | {match_glyph, NULL}, |
| 903 | NULL |
| 904 | }; |
| 905 | return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); |
| 906 | } |
| 907 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 908 | inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 909 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 910 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 911 | unsigned int index = (this+coverage) (c->buffer->cur().codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 912 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 913 | return TRACE_RETURN (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 914 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 915 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 916 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 917 | {match_glyph, apply_func}, |
| 918 | NULL |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 919 | }; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 920 | return TRACE_RETURN (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 921 | } |
| 922 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 923 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 924 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 925 | return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 926 | } |
| 927 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 928 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 929 | USHORT format; /* Format identifier--format = 1 */ |
| 930 | OffsetTo<Coverage> |
| 931 | coverage; /* Offset to Coverage table--from |
| 932 | * beginning of table */ |
| 933 | OffsetArrayOf<RuleSet> |
| 934 | ruleSet; /* Array of RuleSet tables |
| 935 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 936 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 937 | DEFINE_SIZE_ARRAY (6, ruleSet); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 938 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 939 | |
| 940 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 941 | struct ContextFormat2 |
| 942 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 943 | friend struct Context; |
| 944 | |
| 945 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 946 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 947 | inline void closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 948 | { |
| 949 | TRACE_CLOSURE (); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 950 | if (!(this+coverage).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 951 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 952 | |
| 953 | const ClassDef &class_def = this+classDef; |
| 954 | |
| 955 | struct ContextClosureLookupContext lookup_context = { |
| 956 | {intersects_class, closure_func}, |
| 957 | NULL |
| 958 | }; |
| 959 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 960 | unsigned int count = ruleSet.len; |
| 961 | for (unsigned int i = 0; i < count; i++) |
| 962 | if (class_def.intersects_class (c->glyphs, i)) { |
| 963 | const RuleSet &rule_set = this+ruleSet[i]; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 964 | rule_set.closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 965 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 966 | } |
| 967 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 968 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 969 | { |
| 970 | TRACE_WOULD_APPLY (); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 971 | |
| 972 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 973 | unsigned int index = class_def (c->glyphs[0]); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 974 | const RuleSet &rule_set = this+ruleSet[index]; |
| 975 | struct ContextApplyLookupContext lookup_context = { |
| 976 | {match_class, NULL}, |
| 977 | &class_def |
| 978 | }; |
| 979 | return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); |
| 980 | } |
| 981 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 982 | inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 983 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 984 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 985 | unsigned int index = (this+coverage) (c->buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 986 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 987 | |
| 988 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 989 | index = class_def (c->buffer->cur().codepoint); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 990 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 991 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 992 | {match_class, apply_func}, |
| 993 | &class_def |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 994 | }; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 995 | return TRACE_RETURN (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 996 | } |
| 997 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 998 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 999 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1000 | 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] | 1001 | } |
| 1002 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1003 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1004 | USHORT format; /* Format identifier--format = 2 */ |
| 1005 | OffsetTo<Coverage> |
| 1006 | coverage; /* Offset to Coverage table--from |
| 1007 | * beginning of table */ |
| 1008 | OffsetTo<ClassDef> |
| 1009 | classDef; /* Offset to glyph ClassDef table--from |
| 1010 | * beginning of table */ |
| 1011 | OffsetArrayOf<RuleSet> |
| 1012 | ruleSet; /* Array of RuleSet tables |
| 1013 | * ordered by class */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1014 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1015 | DEFINE_SIZE_ARRAY (8, ruleSet); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1016 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1017 | |
| 1018 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1019 | struct ContextFormat3 |
| 1020 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1021 | friend struct Context; |
| 1022 | |
| 1023 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1024 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1025 | inline void closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1026 | { |
| 1027 | TRACE_CLOSURE (); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1028 | if (!(this+coverage[0]).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1029 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1030 | |
| 1031 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount); |
| 1032 | struct ContextClosureLookupContext lookup_context = { |
| 1033 | {intersects_coverage, closure_func}, |
| 1034 | this |
| 1035 | }; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1036 | context_closure_lookup (c, |
| 1037 | glyphCount, (const USHORT *) (coverage + 1), |
| 1038 | lookupCount, lookupRecord, |
| 1039 | lookup_context); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1042 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1043 | { |
| 1044 | TRACE_WOULD_APPLY (); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1045 | |
| 1046 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount); |
| 1047 | struct ContextApplyLookupContext lookup_context = { |
| 1048 | {match_coverage, NULL}, |
| 1049 | this |
| 1050 | }; |
| 1051 | return TRACE_RETURN (context_would_apply_lookup (c, glyphCount, (const USHORT *) (coverage + 1), lookupCount, lookupRecord, lookup_context)); |
| 1052 | } |
| 1053 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1054 | inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1055 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1056 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 1057 | unsigned int index = (this+coverage[0]) (c->buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1058 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1059 | |
Behdad Esfahbod | e45d3f8 | 2010-05-06 19:33:31 -0400 | [diff] [blame] | 1060 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1061 | struct ContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1062 | {match_coverage, apply_func}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1063 | this |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1064 | }; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1065 | 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] | 1066 | } |
| 1067 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1068 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1069 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1070 | if (!c->check_struct (this)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1071 | unsigned int count = glyphCount; |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1072 | 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] | 1073 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1074 | if (!coverage[i].sanitize (c, this)) return TRACE_RETURN (false); |
Behdad Esfahbod | e45d3f8 | 2010-05-06 19:33:31 -0400 | [diff] [blame] | 1075 | LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * count); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1076 | return TRACE_RETURN (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1077 | } |
| 1078 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1079 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1080 | USHORT format; /* Format identifier--format = 3 */ |
| 1081 | USHORT glyphCount; /* Number of glyphs in the input glyph |
| 1082 | * sequence */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1083 | USHORT lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1084 | OffsetTo<Coverage> |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 1085 | coverage[VAR]; /* Array of offsets to Coverage |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1086 | * table in glyph sequence order */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 1087 | LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1088 | * design order */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 1089 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1090 | DEFINE_SIZE_ARRAY2 (6, coverage, lookupRecordX); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1091 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1092 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1093 | struct Context |
| 1094 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1095 | protected: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1096 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1097 | inline void closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1098 | { |
| 1099 | TRACE_CLOSURE (); |
| 1100 | switch (u.format) { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1101 | case 1: u.format1.closure (c, closure_func); break; |
| 1102 | case 2: u.format2.closure (c, closure_func); break; |
| 1103 | case 3: u.format3.closure (c, closure_func); break; |
| 1104 | default: break; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1108 | inline const Coverage &get_coverage (void) const |
| 1109 | { |
| 1110 | switch (u.format) { |
| 1111 | case 1: return this + u.format1.coverage; |
| 1112 | case 2: return this + u.format2.coverage; |
| 1113 | case 3: return this + u.format3.coverage[0]; |
| 1114 | default:return Null(Coverage); |
| 1115 | } |
| 1116 | } |
| 1117 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1118 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1119 | { |
| 1120 | switch (u.format) { |
| 1121 | case 1: return u.format1.would_apply (c); |
| 1122 | case 2: return u.format2.would_apply (c); |
| 1123 | case 3: return u.format3.would_apply (c); |
| 1124 | default:return false; |
| 1125 | } |
| 1126 | } |
| 1127 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1128 | inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1129 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1130 | TRACE_APPLY (); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1131 | switch (u.format) { |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1132 | case 1: return TRACE_RETURN (u.format1.apply (c, apply_func)); |
| 1133 | case 2: return TRACE_RETURN (u.format2.apply (c, apply_func)); |
| 1134 | case 3: return TRACE_RETURN (u.format3.apply (c, apply_func)); |
| 1135 | default:return TRACE_RETURN (false); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1136 | } |
| 1137 | } |
| 1138 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1139 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1140 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1141 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1142 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1143 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 1144 | case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
| 1145 | case 3: return TRACE_RETURN (u.format3.sanitize (c)); |
| 1146 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1150 | protected: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1151 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 1152 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1153 | ContextFormat1 format1; |
| 1154 | ContextFormat2 format2; |
| 1155 | ContextFormat3 format3; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1156 | } u; |
| 1157 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1158 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1159 | |
| 1160 | /* Chaining Contextual lookups */ |
| 1161 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1162 | struct ChainContextClosureLookupContext |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1163 | { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1164 | ContextClosureFuncs funcs; |
| 1165 | const void *intersects_data[3]; |
| 1166 | }; |
| 1167 | |
| 1168 | struct ChainContextApplyLookupContext |
| 1169 | { |
| 1170 | ContextApplyFuncs funcs; |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1171 | const void *match_data[3]; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1172 | }; |
| 1173 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1174 | static inline void chain_context_closure_lookup (hb_closure_context_t *c, |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1175 | unsigned int backtrackCount, |
| 1176 | const USHORT backtrack[], |
| 1177 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 1178 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 1179 | unsigned int lookaheadCount, |
| 1180 | const USHORT lookahead[], |
| 1181 | unsigned int lookupCount, |
| 1182 | const LookupRecord lookupRecord[], |
| 1183 | ChainContextClosureLookupContext &lookup_context) |
| 1184 | { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1185 | if (intersects_array (c, |
| 1186 | backtrackCount, backtrack, |
| 1187 | lookup_context.funcs.intersects, lookup_context.intersects_data[0]) |
| 1188 | && intersects_array (c, |
| 1189 | inputCount ? inputCount - 1 : 0, input, |
| 1190 | lookup_context.funcs.intersects, lookup_context.intersects_data[1]) |
| 1191 | && intersects_array (c, |
| 1192 | lookaheadCount, lookahead, |
| 1193 | lookup_context.funcs.intersects, lookup_context.intersects_data[2])) |
| 1194 | closure_lookup (c, |
| 1195 | lookupCount, lookupRecord, |
| 1196 | lookup_context.funcs.closure); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1199 | static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c, |
| 1200 | unsigned int backtrackCount, |
| 1201 | const USHORT backtrack[], |
| 1202 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 1203 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 1204 | unsigned int lookaheadCount, |
| 1205 | const USHORT lookahead[], |
| 1206 | unsigned int lookupCount, |
| 1207 | const LookupRecord lookupRecord[], |
| 1208 | ChainContextApplyLookupContext &lookup_context) |
| 1209 | { |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 1210 | return (c->zero_context ? !backtrackCount && !lookaheadCount : true) |
Behdad Esfahbod | 1f2bb17 | 2012-08-23 16:10:37 -0400 | [diff] [blame] | 1211 | && would_match_input (c, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1212 | inputCount, input, |
| 1213 | lookup_context.funcs.match, lookup_context.match_data[1]); |
| 1214 | } |
| 1215 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1216 | static inline bool chain_context_apply_lookup (hb_apply_context_t *c, |
| 1217 | unsigned int backtrackCount, |
| 1218 | const USHORT backtrack[], |
| 1219 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
| 1220 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 1221 | unsigned int lookaheadCount, |
| 1222 | const USHORT lookahead[], |
| 1223 | unsigned int lookupCount, |
| 1224 | const LookupRecord lookupRecord[], |
| 1225 | ChainContextApplyLookupContext &lookup_context) |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1226 | { |
Behdad Esfahbod | 5df809b | 2012-05-13 15:17:51 +0200 | [diff] [blame] | 1227 | unsigned int lookahead_offset; |
Behdad Esfahbod | f19e0b0 | 2012-06-09 02:26:57 -0400 | [diff] [blame] | 1228 | return match_input (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 1229 | inputCount, input, |
| 1230 | lookup_context.funcs.match, lookup_context.match_data[1], |
Behdad Esfahbod | 5df809b | 2012-05-13 15:17:51 +0200 | [diff] [blame] | 1231 | &lookahead_offset) |
Behdad Esfahbod | f19e0b0 | 2012-06-09 02:26:57 -0400 | [diff] [blame] | 1232 | && match_backtrack (c, |
| 1233 | backtrackCount, backtrack, |
| 1234 | lookup_context.funcs.match, lookup_context.match_data[0]) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1235 | && match_lookahead (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 1236 | lookaheadCount, lookahead, |
| 1237 | lookup_context.funcs.match, lookup_context.match_data[2], |
Behdad Esfahbod | 5df809b | 2012-05-13 15:17:51 +0200 | [diff] [blame] | 1238 | lookahead_offset) |
| 1239 | && apply_lookup (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 1240 | inputCount, |
| 1241 | lookupCount, lookupRecord, |
| 1242 | lookup_context.funcs.apply); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1243 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1244 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1245 | struct ChainRule |
| 1246 | { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1247 | friend struct ChainRuleSet; |
| 1248 | |
| 1249 | private: |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1250 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1251 | inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1252 | { |
| 1253 | TRACE_CLOSURE (); |
| 1254 | const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); |
| 1255 | const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); |
| 1256 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1257 | chain_context_closure_lookup (c, |
| 1258 | backtrack.len, backtrack.array, |
| 1259 | input.len, input.array, |
| 1260 | lookahead.len, lookahead.array, |
| 1261 | lookup.len, lookup.array, |
| 1262 | lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1265 | inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
| 1266 | { |
| 1267 | TRACE_WOULD_APPLY (); |
| 1268 | const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); |
| 1269 | const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); |
| 1270 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
| 1271 | return TRACE_RETURN (chain_context_would_apply_lookup (c, |
| 1272 | backtrack.len, backtrack.array, |
| 1273 | input.len, input.array, |
| 1274 | lookahead.len, lookahead.array, lookup.len, |
| 1275 | lookup.array, lookup_context)); |
| 1276 | } |
| 1277 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1278 | inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1279 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1280 | TRACE_APPLY (); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1281 | const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); |
| 1282 | const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); |
| 1283 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1284 | return TRACE_RETURN (chain_context_apply_lookup (c, |
| 1285 | backtrack.len, backtrack.array, |
| 1286 | input.len, input.array, |
| 1287 | lookahead.len, lookahead.array, lookup.len, |
| 1288 | lookup.array, lookup_context)); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1289 | } |
| 1290 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1291 | public: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1292 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1293 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1294 | if (!backtrack.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1295 | HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1296 | if (!input.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1297 | ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1298 | if (!lookahead.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1299 | ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1300 | return TRACE_RETURN (lookup.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1301 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1302 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1303 | protected: |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1304 | ArrayOf<USHORT> |
| 1305 | backtrack; /* Array of backtracking values |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1306 | * (to be matched before the input |
| 1307 | * sequence) */ |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 1308 | HeadlessArrayOf<USHORT> |
| 1309 | inputX; /* Array of input values (start with |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1310 | * second glyph) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1311 | ArrayOf<USHORT> |
| 1312 | lookaheadX; /* Array of lookahead values's (to be |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1313 | * matched after the input sequence) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1314 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1315 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1316 | * design order) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1317 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 1318 | DEFINE_SIZE_MIN (8); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1319 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1320 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1321 | struct ChainRuleSet |
| 1322 | { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1323 | inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1324 | { |
| 1325 | TRACE_CLOSURE (); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1326 | unsigned int num_rules = rule.len; |
| 1327 | for (unsigned int i = 0; i < num_rules; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1328 | (this+rule[i]).closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1329 | } |
| 1330 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1331 | inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
| 1332 | { |
| 1333 | TRACE_WOULD_APPLY (); |
| 1334 | unsigned int num_rules = rule.len; |
| 1335 | for (unsigned int i = 0; i < num_rules; i++) |
| 1336 | if ((this+rule[i]).would_apply (c, lookup_context)) |
| 1337 | return TRACE_RETURN (true); |
| 1338 | |
| 1339 | return TRACE_RETURN (false); |
| 1340 | } |
| 1341 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1342 | inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1343 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1344 | TRACE_APPLY (); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1345 | unsigned int num_rules = rule.len; |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1346 | for (unsigned int i = 0; i < num_rules; i++) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1347 | if ((this+rule[i]).apply (c, lookup_context)) |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1348 | return TRACE_RETURN (true); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1349 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1350 | return TRACE_RETURN (false); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1351 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1352 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1353 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1354 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1355 | return TRACE_RETURN (rule.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1356 | } |
| 1357 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1358 | protected: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1359 | OffsetArrayOf<ChainRule> |
| 1360 | rule; /* Array of ChainRule tables |
| 1361 | * ordered by preference */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1362 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1363 | DEFINE_SIZE_ARRAY (2, rule); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1364 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1365 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1366 | struct ChainContextFormat1 |
| 1367 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1368 | friend struct ChainContext; |
| 1369 | |
| 1370 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1371 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1372 | inline void closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1373 | { |
| 1374 | TRACE_CLOSURE (); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1375 | const Coverage &cov = (this+coverage); |
| 1376 | |
| 1377 | struct ChainContextClosureLookupContext lookup_context = { |
| 1378 | {intersects_glyph, closure_func}, |
| 1379 | {NULL, NULL, NULL} |
| 1380 | }; |
| 1381 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1382 | unsigned int count = ruleSet.len; |
| 1383 | for (unsigned int i = 0; i < count; i++) |
| 1384 | if (cov.intersects_coverage (c->glyphs, i)) { |
| 1385 | const ChainRuleSet &rule_set = this+ruleSet[i]; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1386 | rule_set.closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1387 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1390 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1391 | { |
| 1392 | TRACE_WOULD_APPLY (); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1393 | |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 1394 | const ChainRuleSet &rule_set = this+ruleSet[(this+coverage) (c->glyphs[0])]; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1395 | struct ChainContextApplyLookupContext lookup_context = { |
| 1396 | {match_glyph, NULL}, |
| 1397 | {NULL, NULL, NULL} |
| 1398 | }; |
| 1399 | return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); |
| 1400 | } |
| 1401 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1402 | inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1403 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1404 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 1405 | unsigned int index = (this+coverage) (c->buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1406 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1407 | |
| 1408 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1409 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1410 | {match_glyph, apply_func}, |
| 1411 | {NULL, NULL, NULL} |
| 1412 | }; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1413 | return TRACE_RETURN (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1414 | } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1415 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1416 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1417 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1418 | return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1419 | } |
| 1420 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1421 | protected: |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1422 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 1423 | OffsetTo<Coverage> |
| 1424 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1425 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1426 | OffsetArrayOf<ChainRuleSet> |
| 1427 | ruleSet; /* Array of ChainRuleSet tables |
| 1428 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1429 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1430 | DEFINE_SIZE_ARRAY (6, ruleSet); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1431 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1432 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1433 | struct ChainContextFormat2 |
| 1434 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1435 | friend struct ChainContext; |
| 1436 | |
| 1437 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1438 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1439 | inline void closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1440 | { |
| 1441 | TRACE_CLOSURE (); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1442 | if (!(this+coverage).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1443 | return; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1444 | |
| 1445 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 1446 | const ClassDef &input_class_def = this+inputClassDef; |
| 1447 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 1448 | |
| 1449 | struct ChainContextClosureLookupContext lookup_context = { |
| 1450 | {intersects_class, closure_func}, |
| 1451 | {&backtrack_class_def, |
| 1452 | &input_class_def, |
| 1453 | &lookahead_class_def} |
| 1454 | }; |
| 1455 | |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1456 | unsigned int count = ruleSet.len; |
| 1457 | for (unsigned int i = 0; i < count; i++) |
| 1458 | if (input_class_def.intersects_class (c->glyphs, i)) { |
| 1459 | const ChainRuleSet &rule_set = this+ruleSet[i]; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1460 | rule_set.closure (c, lookup_context); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1461 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1462 | } |
| 1463 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1464 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1465 | { |
| 1466 | TRACE_WOULD_APPLY (); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1467 | |
| 1468 | const ClassDef &input_class_def = this+inputClassDef; |
| 1469 | |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 1470 | unsigned int index = input_class_def (c->glyphs[0]); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1471 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
| 1472 | struct ChainContextApplyLookupContext lookup_context = { |
| 1473 | {match_class, NULL}, |
| 1474 | {NULL, &input_class_def, NULL} |
| 1475 | }; |
| 1476 | return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); |
| 1477 | } |
| 1478 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1479 | inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1480 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1481 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 1482 | unsigned int index = (this+coverage) (c->buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1483 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1484 | |
| 1485 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 1486 | const ClassDef &input_class_def = this+inputClassDef; |
| 1487 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 1488 | |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 1489 | index = input_class_def (c->buffer->cur().codepoint); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1490 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1491 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1492 | {match_class, apply_func}, |
| 1493 | {&backtrack_class_def, |
| 1494 | &input_class_def, |
| 1495 | &lookahead_class_def} |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1496 | }; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1497 | return TRACE_RETURN (rule_set.apply (c, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1498 | } |
| 1499 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1500 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1501 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1502 | return TRACE_RETURN (coverage.sanitize (c, this) && backtrackClassDef.sanitize (c, this) && |
| 1503 | inputClassDef.sanitize (c, this) && lookaheadClassDef.sanitize (c, this) && |
| 1504 | ruleSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1505 | } |
| 1506 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1507 | protected: |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1508 | USHORT format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1509 | OffsetTo<Coverage> |
| 1510 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1511 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1512 | OffsetTo<ClassDef> |
| 1513 | backtrackClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1514 | * containing backtrack sequence |
| 1515 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1516 | OffsetTo<ClassDef> |
| 1517 | inputClassDef; /* Offset to glyph ClassDef |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1518 | * table containing input sequence |
| 1519 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1520 | OffsetTo<ClassDef> |
| 1521 | lookaheadClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1522 | * containing lookahead sequence |
| 1523 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1524 | OffsetArrayOf<ChainRuleSet> |
| 1525 | ruleSet; /* Array of ChainRuleSet tables |
| 1526 | * ordered by class */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1527 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1528 | DEFINE_SIZE_ARRAY (12, ruleSet); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1529 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1530 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1531 | struct ChainContextFormat3 |
| 1532 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1533 | friend struct ChainContext; |
| 1534 | |
| 1535 | private: |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1536 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1537 | inline void closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1538 | { |
| 1539 | TRACE_CLOSURE (); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1540 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
| 1541 | |
| 1542 | if (!(this+input[0]).intersects (c->glyphs)) |
| 1543 | return; |
| 1544 | |
| 1545 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 1546 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
| 1547 | struct ChainContextClosureLookupContext lookup_context = { |
| 1548 | {intersects_coverage, closure_func}, |
| 1549 | {this, this, this} |
| 1550 | }; |
| 1551 | chain_context_closure_lookup (c, |
| 1552 | backtrack.len, (const USHORT *) backtrack.array, |
| 1553 | input.len, (const USHORT *) input.array + 1, |
| 1554 | lookahead.len, (const USHORT *) lookahead.array, |
| 1555 | lookup.len, lookup.array, |
| 1556 | lookup_context); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1557 | } |
| 1558 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1559 | inline const Coverage &get_coverage (void) const |
| 1560 | { |
| 1561 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
| 1562 | return this+input[0]; |
| 1563 | } |
| 1564 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1565 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1566 | { |
| 1567 | TRACE_WOULD_APPLY (); |
Behdad Esfahbod | e6f7479 | 2012-07-28 18:34:58 -0400 | [diff] [blame] | 1568 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1569 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1570 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 1571 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
| 1572 | struct ChainContextApplyLookupContext lookup_context = { |
| 1573 | {match_coverage, NULL}, |
| 1574 | {this, this, this} |
| 1575 | }; |
| 1576 | return TRACE_RETURN (chain_context_would_apply_lookup (c, |
| 1577 | backtrack.len, (const USHORT *) backtrack.array, |
| 1578 | input.len, (const USHORT *) input.array + 1, |
| 1579 | lookahead.len, (const USHORT *) lookahead.array, |
| 1580 | lookup.len, lookup.array, lookup_context)); |
| 1581 | } |
| 1582 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1583 | inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1584 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1585 | TRACE_APPLY (); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1586 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1587 | |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 1588 | unsigned int index = (this+input[0]) (c->buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1589 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1590 | |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1591 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 1592 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1593 | struct ChainContextApplyLookupContext lookup_context = { |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1594 | {match_coverage, apply_func}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1595 | {this, this, this} |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1596 | }; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1597 | return TRACE_RETURN (chain_context_apply_lookup (c, |
| 1598 | backtrack.len, (const USHORT *) backtrack.array, |
| 1599 | input.len, (const USHORT *) input.array + 1, |
| 1600 | lookahead.len, (const USHORT *) lookahead.array, |
| 1601 | lookup.len, lookup.array, lookup_context)); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1602 | } |
| 1603 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1604 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1605 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1606 | if (!backtrack.sanitize (c, this)) return TRACE_RETURN (false); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1607 | OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1608 | if (!input.sanitize (c, this)) return TRACE_RETURN (false); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1609 | OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1610 | if (!lookahead.sanitize (c, this)) return TRACE_RETURN (false); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1611 | ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1612 | return TRACE_RETURN (lookup.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1613 | } |
| 1614 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1615 | protected: |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1616 | USHORT format; /* Format identifier--format = 3 */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1617 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 1618 | backtrack; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1619 | * in backtracking sequence, in glyph |
| 1620 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1621 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 1622 | inputX ; /* Array of coverage |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1623 | * tables in input sequence, in glyph |
| 1624 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1625 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 1626 | lookaheadX; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1627 | * in lookahead sequence, in glyph |
| 1628 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1629 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 1630 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 1631 | * design order) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1632 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 1633 | DEFINE_SIZE_MIN (10); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1634 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1635 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1636 | struct ChainContext |
| 1637 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1638 | protected: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1639 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1640 | inline void closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1641 | { |
| 1642 | TRACE_CLOSURE (); |
| 1643 | switch (u.format) { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1644 | case 1: u.format1.closure (c, closure_func); break; |
| 1645 | case 2: u.format2.closure (c, closure_func); break; |
| 1646 | case 3: u.format3.closure (c, closure_func); break; |
| 1647 | default: break; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1651 | inline const Coverage &get_coverage (void) const |
| 1652 | { |
| 1653 | switch (u.format) { |
| 1654 | case 1: return this + u.format1.coverage; |
| 1655 | case 2: return this + u.format2.coverage; |
| 1656 | case 3: return u.format3.get_coverage (); |
| 1657 | default:return Null(Coverage); |
| 1658 | } |
| 1659 | } |
| 1660 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1661 | inline bool would_apply (hb_would_apply_context_t *c) const |
| 1662 | { |
| 1663 | switch (u.format) { |
| 1664 | case 1: return u.format1.would_apply (c); |
| 1665 | case 2: return u.format2.would_apply (c); |
| 1666 | case 3: return u.format3.would_apply (c); |
| 1667 | default:return false; |
| 1668 | } |
| 1669 | } |
| 1670 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1671 | inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1672 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1673 | TRACE_APPLY (); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1674 | switch (u.format) { |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1675 | case 1: return TRACE_RETURN (u.format1.apply (c, apply_func)); |
| 1676 | case 2: return TRACE_RETURN (u.format2.apply (c, apply_func)); |
| 1677 | case 3: return TRACE_RETURN (u.format3.apply (c, apply_func)); |
| 1678 | default:return TRACE_RETURN (false); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1679 | } |
| 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 | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1683 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1684 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1685 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1686 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 1687 | case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
| 1688 | case 3: return TRACE_RETURN (u.format3.sanitize (c)); |
| 1689 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1690 | } |
| 1691 | } |
| 1692 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1693 | protected: |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1694 | union { |
| 1695 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1696 | ChainContextFormat1 format1; |
| 1697 | ChainContextFormat2 format2; |
| 1698 | ChainContextFormat3 format3; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1699 | } u; |
| 1700 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1701 | |
| 1702 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1703 | struct ExtensionFormat1 |
| 1704 | { |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1705 | friend struct Extension; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1706 | |
Behdad Esfahbod | 1893948 | 2009-08-04 14:27:56 -0400 | [diff] [blame] | 1707 | protected: |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1708 | inline unsigned int get_type (void) const { return extensionLookupType; } |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 1709 | inline unsigned int get_offset (void) const { return extensionOffset; } |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1710 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1711 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1712 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1713 | return TRACE_RETURN (c->check_struct (this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1714 | } |
| 1715 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1716 | protected: |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1717 | USHORT format; /* Format identifier. Set to 1. */ |
| 1718 | USHORT extensionLookupType; /* Lookup type of subtable referenced |
| 1719 | * by ExtensionOffset (i.e. the |
| 1720 | * extension subtable). */ |
Behdad Esfahbod | 81f2af4 | 2010-04-22 00:58:49 -0400 | [diff] [blame] | 1721 | ULONG extensionOffset; /* Offset to the extension subtable, |
| 1722 | * of lookup type subtable. */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1723 | public: |
| 1724 | DEFINE_SIZE_STATIC (8); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1725 | }; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1726 | |
| 1727 | struct Extension |
| 1728 | { |
| 1729 | inline unsigned int get_type (void) const |
| 1730 | { |
| 1731 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1732 | case 1: return u.format1.get_type (); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1733 | default:return 0; |
| 1734 | } |
| 1735 | } |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 1736 | inline unsigned int get_offset (void) const |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1737 | { |
| 1738 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1739 | case 1: return u.format1.get_offset (); |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 1740 | default:return 0; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1741 | } |
| 1742 | } |
| 1743 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1744 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1745 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1746 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1747 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1748 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 1749 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1750 | } |
| 1751 | } |
| 1752 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1753 | protected: |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1754 | union { |
| 1755 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1756 | ExtensionFormat1 format1; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1757 | } u; |
| 1758 | }; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1759 | |
| 1760 | |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 1761 | /* |
| 1762 | * GSUB/GPOS Common |
| 1763 | */ |
| 1764 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1765 | struct GSUBGPOS |
| 1766 | { |
Behdad Esfahbod | a328d66 | 2009-08-04 20:27:05 -0400 | [diff] [blame] | 1767 | static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB; |
| 1768 | static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS; |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 1769 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 1770 | inline unsigned int get_script_count (void) const |
| 1771 | { return (this+scriptList).len; } |
| 1772 | inline const Tag& get_script_tag (unsigned int i) const |
| 1773 | { return (this+scriptList).get_tag (i); } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 1774 | inline unsigned int get_script_tags (unsigned int start_offset, |
| 1775 | unsigned int *script_count /* IN/OUT */, |
| 1776 | hb_tag_t *script_tags /* OUT */) const |
| 1777 | { return (this+scriptList).get_tags (start_offset, script_count, script_tags); } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 1778 | inline const Script& get_script (unsigned int i) const |
| 1779 | { return (this+scriptList)[i]; } |
| 1780 | inline bool find_script_index (hb_tag_t tag, unsigned int *index) const |
| 1781 | { return (this+scriptList).find_index (tag, index); } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 1782 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 1783 | inline unsigned int get_feature_count (void) const |
| 1784 | { return (this+featureList).len; } |
| 1785 | inline const Tag& get_feature_tag (unsigned int i) const |
| 1786 | { return (this+featureList).get_tag (i); } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 1787 | inline unsigned int get_feature_tags (unsigned int start_offset, |
| 1788 | unsigned int *feature_count /* IN/OUT */, |
| 1789 | hb_tag_t *feature_tags /* OUT */) const |
| 1790 | { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 1791 | inline const Feature& get_feature (unsigned int i) const |
| 1792 | { return (this+featureList)[i]; } |
| 1793 | inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const |
| 1794 | { return (this+featureList).find_index (tag, index); } |
| 1795 | |
| 1796 | inline unsigned int get_lookup_count (void) const |
| 1797 | { return (this+lookupList).len; } |
| 1798 | inline const Lookup& get_lookup (unsigned int i) const |
| 1799 | { return (this+lookupList)[i]; } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 1800 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1801 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1802 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1803 | return TRACE_RETURN (version.sanitize (c) && likely (version.major == 1) && |
| 1804 | scriptList.sanitize (c, this) && |
| 1805 | featureList.sanitize (c, this) && |
| 1806 | lookupList.sanitize (c, this)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 1807 | } |
| 1808 | |
Behdad Esfahbod | 212aba6 | 2009-05-24 00:50:27 -0400 | [diff] [blame] | 1809 | protected: |
Behdad Esfahbod | 87fcdcb | 2009-05-24 01:03:24 -0400 | [diff] [blame] | 1810 | FixedVersion version; /* Version of the GSUB/GPOS table--initially set |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 1811 | * to 0x00010000 */ |
| 1812 | OffsetTo<ScriptList> |
| 1813 | scriptList; /* ScriptList table */ |
| 1814 | OffsetTo<FeatureList> |
| 1815 | featureList; /* FeatureList table */ |
| 1816 | OffsetTo<LookupList> |
| 1817 | lookupList; /* LookupList table */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1818 | public: |
| 1819 | DEFINE_SIZE_STATIC (10); |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 1820 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1821 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1822 | |
Behdad Esfahbod | 7d52e66 | 2012-11-16 18:49:54 -0800 | [diff] [blame^] | 1823 | } /* namespace OT */ |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1824 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1825 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 1826 | #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */ |