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