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. |
| 3 | * Copyright © 2010 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 | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 34 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 35 | |
Behdad Esfahbod | c270911 | 2010-10-27 23:18:51 -0400 | [diff] [blame] | 36 | /* buffer var allocations */ |
Behdad Esfahbod | 18c4285 | 2011-07-25 00:36:58 -0400 | [diff] [blame] | 37 | #define lig_id() var2.u8[2] /* unique ligature id */ |
| 38 | #define lig_comp() var2.u8[3] /* component number in the ligature (0 = base) */ |
Behdad Esfahbod | c270911 | 2010-10-27 23:18:51 -0400 | [diff] [blame] | 39 | |
Behdad Esfahbod | 18c4285 | 2011-07-25 00:36:58 -0400 | [diff] [blame] | 40 | static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) { |
| 41 | uint8_t lig_id = buffer->next_serial (); |
Behdad Esfahbod | d878749 | 2011-07-25 00:36:01 -0400 | [diff] [blame] | 42 | if (unlikely (!lig_id)) lig_id = buffer->next_serial (); /* in case of overflow */ |
| 43 | return lig_id; |
| 44 | } |
| 45 | |
| 46 | |
Behdad Esfahbod | c270911 | 2010-10-27 23:18:51 -0400 | [diff] [blame] | 47 | |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 48 | #ifndef HB_DEBUG_APPLY |
Behdad Esfahbod | 11e3ec4 | 2010-11-03 15:11:04 -0400 | [diff] [blame] | 49 | #define HB_DEBUG_APPLY (HB_DEBUG+0) |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 50 | #endif |
| 51 | |
Behdad Esfahbod | bc20045 | 2010-04-29 01:40:26 -0400 | [diff] [blame] | 52 | #define TRACE_APPLY() \ |
Behdad Esfahbod | cc06c24 | 2011-07-25 20:25:44 -0400 | [diff] [blame] | 53 | hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", this, NULL, HB_FUNC); |
Behdad Esfahbod | 74e313c | 2010-04-28 15:15:09 -0400 | [diff] [blame] | 54 | |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 55 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 56 | |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 57 | struct hb_apply_context_t |
| 58 | { |
Behdad Esfahbod | 705e215 | 2010-05-05 01:40:25 -0400 | [diff] [blame] | 59 | unsigned int debug_depth; |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 60 | hb_font_t *font; |
| 61 | hb_face_t *face; |
Behdad Esfahbod | 94a23aa | 2010-05-05 01:13:09 -0400 | [diff] [blame] | 62 | hb_buffer_t *buffer; |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 63 | hb_direction_t direction; |
Behdad Esfahbod | f7acd8d | 2010-05-20 17:26:35 +0100 | [diff] [blame] | 64 | hb_mask_t lookup_mask; |
Behdad Esfahbod | 969c970 | 2010-05-05 01:23:44 -0400 | [diff] [blame] | 65 | unsigned int context_length; |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 66 | unsigned int nesting_level_left; |
Behdad Esfahbod | 8c69e65 | 2010-10-27 22:07:49 -0400 | [diff] [blame] | 67 | unsigned int lookup_props; |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 68 | unsigned int property; /* propety of first glyph */ |
| 69 | |
| 70 | |
| 71 | inline void replace_glyph (hb_codepoint_t glyph_index) const |
| 72 | { |
| 73 | clear_property (); |
| 74 | buffer->replace_glyph (glyph_index); |
| 75 | } |
| 76 | inline void replace_glyphs_be16 (unsigned int num_in, |
| 77 | unsigned int num_out, |
| 78 | const uint16_t *glyph_data_be) const |
| 79 | { |
| 80 | clear_property (); |
| 81 | buffer->replace_glyphs_be16 (num_in, num_out, glyph_data_be); |
| 82 | } |
| 83 | |
| 84 | inline void guess_glyph_class (unsigned int klass) |
| 85 | { |
Behdad Esfahbod | 300cb41 | 2010-11-17 12:57:23 -0500 | [diff] [blame] | 86 | /* XXX if ! has gdef */ |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 87 | buffer->info[buffer->idx].props_cache() = klass; |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | private: |
| 91 | inline void clear_property (void) const |
| 92 | { |
Behdad Esfahbod | 300cb41 | 2010-11-17 12:57:23 -0500 | [diff] [blame] | 93 | /* XXX if has gdef */ |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 94 | buffer->info[buffer->idx].props_cache() = 0; |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 95 | } |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 98 | |
Behdad Esfahbod | 94a23aa | 2010-05-05 01:13:09 -0400 | [diff] [blame] | 99 | |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 100 | typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 101 | 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] | 102 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 103 | struct ContextFuncs |
| 104 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 105 | match_func_t match; |
| 106 | apply_lookup_func_t apply; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 107 | }; |
| 108 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 109 | |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 110 | 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] | 111 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 112 | return glyph_id == value; |
| 113 | } |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 114 | |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 115 | 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] | 116 | { |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 117 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 118 | return class_def.get_class (glyph_id) == value; |
| 119 | } |
| 120 | |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 121 | 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] | 122 | { |
Behdad Esfahbod | 6b54c5d | 2009-05-18 18:30:25 -0400 | [diff] [blame] | 123 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 124 | return (data+coverage) (glyph_id) != NOT_COVERED; |
| 125 | } |
| 126 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 127 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 128 | static inline bool match_input (hb_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 129 | unsigned int count, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 130 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 131 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 132 | const void *match_data, |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 133 | unsigned int *context_length_out) |
| 134 | { |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 135 | unsigned int i; |
| 136 | unsigned int j = c->buffer->idx; |
| 137 | unsigned int end = MIN (c->buffer->len, j + c->context_length); |
| 138 | if (unlikely (j + count > end)) |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 139 | return false; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 140 | |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 141 | for (i = 1; i < count; i++) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 142 | { |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 143 | do |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 144 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 145 | j++; |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 146 | if (unlikely (j >= end)) |
| 147 | return false; |
| 148 | } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 149 | |
Behdad Esfahbod | 7e7007a | 2010-05-14 22:02:37 -0400 | [diff] [blame] | 150 | if (likely (!match_func (c->buffer->info[j].codepoint, input[i - 1], match_data))) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 151 | return false; |
| 152 | } |
| 153 | |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 154 | *context_length_out = j - c->buffer->idx + 1; |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 155 | |
| 156 | return true; |
| 157 | } |
| 158 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 159 | static inline bool match_backtrack (hb_apply_context_t *c, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 160 | unsigned int count, |
| 161 | const USHORT backtrack[], |
| 162 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 163 | const void *match_data) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 164 | { |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 165 | unsigned int j = c->buffer->backtrack_len (); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 166 | |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 167 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 168 | { |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 169 | do |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 170 | { |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 171 | if (unlikely (!j)) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 172 | return false; |
| 173 | j--; |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 174 | } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->out_info[j], c->lookup_props, NULL)); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 175 | |
Behdad Esfahbod | 9d5e26d | 2010-05-14 22:03:11 -0400 | [diff] [blame] | 176 | if (likely (!match_func (c->buffer->out_info[j].codepoint, backtrack[i], match_data))) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 177 | return false; |
| 178 | } |
| 179 | |
| 180 | return true; |
| 181 | } |
| 182 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 183 | static inline bool match_lookahead (hb_apply_context_t *c, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 184 | unsigned int count, |
| 185 | const USHORT lookahead[], |
| 186 | match_func_t match_func, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 187 | const void *match_data, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 188 | unsigned int offset) |
| 189 | { |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 190 | unsigned int i; |
| 191 | unsigned int j = c->buffer->idx + offset - 1; |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 192 | unsigned int end = MIN (c->buffer->len, c->buffer->idx + c->context_length); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 193 | |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 194 | for (i = 0; i < count; i++) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 195 | { |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 196 | do |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 197 | { |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 198 | j++; |
Behdad Esfahbod | 4d3aeb8 | 2012-01-16 16:43:26 -0500 | [diff] [blame^] | 199 | if (unlikely (j >= end)) |
| 200 | return false; |
| 201 | } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL)); |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 202 | |
Behdad Esfahbod | 7e7007a | 2010-05-14 22:02:37 -0400 | [diff] [blame] | 203 | if (likely (!match_func (c->buffer->info[j].codepoint, lookahead[i], match_data))) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 204 | return false; |
| 205 | } |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 206 | |
| 207 | return true; |
| 208 | } |
| 209 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 210 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 211 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 212 | struct LookupRecord |
| 213 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 214 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 215 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 216 | return c->check_struct (this); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 217 | } |
| 218 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 219 | USHORT sequenceIndex; /* Index into current glyph |
| 220 | * sequence--first glyph = 0 */ |
| 221 | USHORT lookupListIndex; /* Lookup to apply to that |
| 222 | * position--zero--based */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 223 | public: |
| 224 | DEFINE_SIZE_STATIC (4); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 225 | }; |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 226 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 227 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 228 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 229 | static inline bool apply_lookup (hb_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 230 | unsigned int count, /* Including the first glyph */ |
| 231 | unsigned int lookupCount, |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 232 | const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ |
| 233 | apply_lookup_func_t apply_func) |
| 234 | { |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 235 | unsigned int end = MIN (c->buffer->len, c->buffer->idx + c->context_length); |
| 236 | if (unlikely (count == 0 || c->buffer->idx + count > end)) |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 237 | return false; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 238 | |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 239 | /* TODO We don't support lookupRecord arrays that are not increasing: |
| 240 | * Should be easy for in_place ones at least. */ |
Behdad Esfahbod | 52e9a71 | 2009-09-21 13:58:56 -0400 | [diff] [blame] | 241 | |
Behdad Esfahbod | 7eb8751 | 2010-12-13 14:13:35 -0500 | [diff] [blame] | 242 | /* Note: If sublookup is reverse, it will underflow after the first loop |
Behdad Esfahbod | 52e9a71 | 2009-09-21 13:58:56 -0400 | [diff] [blame] | 243 | * and we jump out of it. Not entirely disastrous. So we don't check |
| 244 | * for reverse lookup here. |
| 245 | */ |
Behdad Esfahbod | f9c0a2d | 2009-09-21 13:43:54 -0400 | [diff] [blame] | 246 | for (unsigned int i = 0; i < count; /* NOP */) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 247 | { |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 248 | while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[c->buffer->idx], c->lookup_props, NULL)) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 249 | { |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 250 | if (unlikely (c->buffer->idx == end)) |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 251 | return true; |
| 252 | /* No lookup applied for this index */ |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 253 | c->buffer->next_glyph (); |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Behdad Esfahbod | 47958de | 2009-05-18 04:17:47 -0400 | [diff] [blame] | 256 | if (lookupCount && i == lookupRecord->sequenceIndex) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 257 | { |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 258 | unsigned int old_pos = c->buffer->idx; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 259 | |
| 260 | /* Apply a lookup */ |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 261 | bool done = apply_func (c, lookupRecord->lookupListIndex); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 262 | |
Behdad Esfahbod | 47958de | 2009-05-18 04:17:47 -0400 | [diff] [blame] | 263 | lookupRecord++; |
| 264 | lookupCount--; |
Behdad Esfahbod | f9c0a2d | 2009-09-21 13:43:54 -0400 | [diff] [blame] | 265 | /* Err, this is wrong if the lookup jumped over some glyphs */ |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 266 | i += c->buffer->idx - old_pos; |
| 267 | if (unlikely (c->buffer->idx == end)) |
Behdad Esfahbod | 2e8fb6c | 2009-05-18 04:37:37 -0400 | [diff] [blame] | 268 | return true; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 269 | |
| 270 | if (!done) |
| 271 | goto not_applied; |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | not_applied: |
| 276 | /* No lookup applied for this index */ |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 277 | c->buffer->next_glyph (); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 278 | i++; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return true; |
| 283 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 284 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 285 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 286 | |
| 287 | /* Contextual lookups */ |
| 288 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 289 | struct ContextLookupContext |
| 290 | { |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 291 | ContextFuncs funcs; |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 292 | const void *match_data; |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 293 | }; |
| 294 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 295 | static inline bool context_lookup (hb_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 296 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 297 | const USHORT input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 298 | unsigned int lookupCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 299 | const LookupRecord lookupRecord[], |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 300 | ContextLookupContext &lookup_context) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 301 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 302 | hb_apply_context_t new_context = *c; |
| 303 | return match_input (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 304 | inputCount, input, |
| 305 | lookup_context.funcs.match, lookup_context.match_data, |
| 306 | &new_context.context_length) |
| 307 | && apply_lookup (&new_context, |
| 308 | inputCount, |
| 309 | lookupCount, lookupRecord, |
| 310 | lookup_context.funcs.apply); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 313 | struct Rule |
| 314 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 315 | friend struct RuleSet; |
| 316 | |
| 317 | private: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 318 | inline bool apply (hb_apply_context_t *c, ContextLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 319 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 320 | TRACE_APPLY (); |
Behdad Esfahbod | e45d3f8 | 2010-05-06 19:33:31 -0400 | [diff] [blame] | 321 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 322 | return context_lookup (c, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 323 | inputCount, input, |
Behdad Esfahbod | fff9aa2 | 2010-05-05 00:32:21 -0400 | [diff] [blame] | 324 | lookupCount, lookupRecord, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 325 | lookup_context); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 326 | } |
| 327 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 328 | public: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 329 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 330 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 331 | return inputCount.sanitize (c) |
| 332 | && lookupCount.sanitize (c) |
| 333 | && c->check_range (input, |
Behdad Esfahbod | e45d3f8 | 2010-05-06 19:33:31 -0400 | [diff] [blame] | 334 | input[0].static_size * inputCount |
| 335 | + lookupRecordX[0].static_size * lookupCount); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 338 | private: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 339 | USHORT inputCount; /* Total number of glyphs in input |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 340 | * glyph sequence--includes the first |
| 341 | * glyph */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 342 | USHORT lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 343 | USHORT input[VAR]; /* Array of match inputs--start with |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 344 | * second glyph */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 345 | LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 346 | * design order */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 347 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 348 | DEFINE_SIZE_ARRAY2 (4, input, lookupRecordX); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 349 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 350 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 351 | struct RuleSet |
| 352 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 353 | inline bool apply (hb_apply_context_t *c, ContextLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 354 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 355 | TRACE_APPLY (); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 356 | unsigned int num_rules = rule.len; |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 357 | for (unsigned int i = 0; i < num_rules; i++) |
| 358 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 359 | if ((this+rule[i]).apply (c, lookup_context)) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 360 | return true; |
| 361 | } |
| 362 | |
| 363 | return false; |
| 364 | } |
| 365 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 366 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 367 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 368 | return rule.sanitize (c, this); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 369 | } |
| 370 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 371 | private: |
| 372 | OffsetArrayOf<Rule> |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 373 | rule; /* Array of Rule tables |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 374 | * ordered by preference */ |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 375 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 376 | DEFINE_SIZE_ARRAY (2, rule); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 380 | struct ContextFormat1 |
| 381 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 382 | friend struct Context; |
| 383 | |
| 384 | private: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 385 | 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] | 386 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 387 | TRACE_APPLY (); |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 388 | unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 389 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 390 | return false; |
| 391 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 392 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 393 | struct ContextLookupContext lookup_context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 394 | {match_glyph, apply_func}, |
| 395 | NULL |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 396 | }; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 397 | return rule_set.apply (c, lookup_context); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 398 | } |
| 399 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 400 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 401 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 402 | return coverage.sanitize (c, this) |
| 403 | && ruleSet.sanitize (c, this); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 404 | } |
| 405 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 406 | private: |
| 407 | USHORT format; /* Format identifier--format = 1 */ |
| 408 | OffsetTo<Coverage> |
| 409 | coverage; /* Offset to Coverage table--from |
| 410 | * beginning of table */ |
| 411 | OffsetArrayOf<RuleSet> |
| 412 | ruleSet; /* Array of RuleSet tables |
| 413 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 414 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 415 | DEFINE_SIZE_ARRAY (6, ruleSet); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 416 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 417 | |
| 418 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 419 | struct ContextFormat2 |
| 420 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 421 | friend struct Context; |
| 422 | |
| 423 | private: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 424 | 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] | 425 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 426 | TRACE_APPLY (); |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 427 | unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 428 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 429 | return false; |
| 430 | |
| 431 | const ClassDef &class_def = this+classDef; |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 432 | index = class_def (c->buffer->info[c->buffer->idx].codepoint); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 433 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 434 | struct ContextLookupContext lookup_context = { |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 435 | {match_class, apply_func}, |
| 436 | &class_def |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 437 | }; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 438 | return rule_set.apply (c, lookup_context); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 439 | } |
| 440 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 441 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 442 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 443 | return coverage.sanitize (c, this) |
| 444 | && classDef.sanitize (c, this) |
| 445 | && ruleSet.sanitize (c, this); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 446 | } |
| 447 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 448 | private: |
| 449 | USHORT format; /* Format identifier--format = 2 */ |
| 450 | OffsetTo<Coverage> |
| 451 | coverage; /* Offset to Coverage table--from |
| 452 | * beginning of table */ |
| 453 | OffsetTo<ClassDef> |
| 454 | classDef; /* Offset to glyph ClassDef table--from |
| 455 | * beginning of table */ |
| 456 | OffsetArrayOf<RuleSet> |
| 457 | ruleSet; /* Array of RuleSet tables |
| 458 | * ordered by class */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 459 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 460 | DEFINE_SIZE_ARRAY (8, ruleSet); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 461 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 462 | |
| 463 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 464 | struct ContextFormat3 |
| 465 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 466 | friend struct Context; |
| 467 | |
| 468 | private: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 469 | 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] | 470 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 471 | TRACE_APPLY (); |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 472 | unsigned int index = (this+coverage[0]) (c->buffer->info[c->buffer->idx].codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 473 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 474 | return false; |
| 475 | |
Behdad Esfahbod | e45d3f8 | 2010-05-06 19:33:31 -0400 | [diff] [blame] | 476 | const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount); |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 477 | struct ContextLookupContext lookup_context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 478 | {match_coverage, apply_func}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 479 | this |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 480 | }; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 481 | return context_lookup (c, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 482 | glyphCount, (const USHORT *) (coverage + 1), |
Behdad Esfahbod | fff9aa2 | 2010-05-05 00:32:21 -0400 | [diff] [blame] | 483 | lookupCount, lookupRecord, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 484 | lookup_context); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 485 | } |
| 486 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 487 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 488 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 489 | if (!c->check_struct (this)) return false; |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 490 | unsigned int count = glyphCount; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 491 | if (!c->check_array (coverage, coverage[0].static_size, count)) return false; |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 492 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 493 | if (!coverage[i].sanitize (c, this)) return false; |
Behdad Esfahbod | e45d3f8 | 2010-05-06 19:33:31 -0400 | [diff] [blame] | 494 | LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * count); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 495 | return c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 496 | } |
| 497 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 498 | private: |
| 499 | USHORT format; /* Format identifier--format = 3 */ |
| 500 | USHORT glyphCount; /* Number of glyphs in the input glyph |
| 501 | * sequence */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 502 | USHORT lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 503 | OffsetTo<Coverage> |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 504 | coverage[VAR]; /* Array of offsets to Coverage |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 505 | * table in glyph sequence order */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 506 | LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 507 | * design order */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 508 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 509 | DEFINE_SIZE_ARRAY2 (6, coverage, lookupRecordX); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 510 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 511 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 512 | struct Context |
| 513 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 514 | protected: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 515 | 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] | 516 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 517 | TRACE_APPLY (); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 518 | switch (u.format) { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 519 | case 1: return u.format1.apply (c, apply_func); |
| 520 | case 2: return u.format2.apply (c, apply_func); |
| 521 | case 3: return u.format3.apply (c, apply_func); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 522 | default:return false; |
| 523 | } |
| 524 | } |
| 525 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 526 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 527 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 528 | if (!u.format.sanitize (c)) return false; |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 529 | switch (u.format) { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 530 | case 1: return u.format1.sanitize (c); |
| 531 | case 2: return u.format2.sanitize (c); |
| 532 | case 3: return u.format3.sanitize (c); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 533 | default:return true; |
| 534 | } |
| 535 | } |
| 536 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 537 | private: |
| 538 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 539 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 540 | ContextFormat1 format1; |
| 541 | ContextFormat2 format2; |
| 542 | ContextFormat3 format3; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 543 | } u; |
| 544 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 545 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 546 | |
| 547 | /* Chaining Contextual lookups */ |
| 548 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 549 | struct ChainContextLookupContext |
| 550 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 551 | ContextFuncs funcs; |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 552 | const void *match_data[3]; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 553 | }; |
| 554 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 555 | static inline bool chain_context_lookup (hb_apply_context_t *c, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 556 | unsigned int backtrackCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 557 | const USHORT backtrack[], |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 558 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 559 | const USHORT input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 560 | unsigned int lookaheadCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 561 | const USHORT lookahead[], |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 562 | unsigned int lookupCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 563 | const LookupRecord lookupRecord[], |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 564 | ChainContextLookupContext &lookup_context) |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 565 | { |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 566 | /* First guess */ |
Behdad Esfahbod | cc1a8a9 | 2011-01-06 14:58:52 -0500 | [diff] [blame] | 567 | if (unlikely (c->buffer->backtrack_len () < backtrackCount || |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 568 | c->buffer->idx + inputCount + lookaheadCount > c->buffer->len || |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 569 | inputCount + lookaheadCount > c->context_length)) |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 570 | return false; |
| 571 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 572 | hb_apply_context_t new_context = *c; |
| 573 | return match_backtrack (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 574 | backtrackCount, backtrack, |
| 575 | lookup_context.funcs.match, lookup_context.match_data[0]) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 576 | && match_input (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 577 | inputCount, input, |
| 578 | lookup_context.funcs.match, lookup_context.match_data[1], |
| 579 | &new_context.context_length) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 580 | && match_lookahead (c, |
Behdad Esfahbod | 4169710 | 2010-05-05 01:37:58 -0400 | [diff] [blame] | 581 | lookaheadCount, lookahead, |
| 582 | lookup_context.funcs.match, lookup_context.match_data[2], |
| 583 | new_context.context_length) |
| 584 | && apply_lookup (&new_context, |
| 585 | inputCount, |
| 586 | lookupCount, lookupRecord, |
| 587 | lookup_context.funcs.apply); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 588 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 589 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 590 | struct ChainRule |
| 591 | { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 592 | friend struct ChainRuleSet; |
| 593 | |
| 594 | private: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 595 | inline bool apply (hb_apply_context_t *c, ChainContextLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 596 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 597 | TRACE_APPLY (); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 598 | const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); |
| 599 | const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); |
| 600 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 601 | return chain_context_lookup (c, |
Behdad Esfahbod | b961518 | 2010-05-10 18:20:54 -0400 | [diff] [blame] | 602 | backtrack.len, backtrack.array, |
| 603 | input.len, input.array, |
| 604 | lookahead.len, lookahead.array, |
| 605 | lookup.len, lookup.array, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 606 | lookup_context); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 609 | public: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 610 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 611 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 612 | if (!backtrack.sanitize (c)) return false; |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 613 | HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 614 | if (!input.sanitize (c)) return false; |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 615 | ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 616 | if (!lookahead.sanitize (c)) return false; |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 617 | ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 618 | return lookup.sanitize (c); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 619 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 620 | |
| 621 | private: |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 622 | ArrayOf<USHORT> |
| 623 | backtrack; /* Array of backtracking values |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 624 | * (to be matched before the input |
| 625 | * sequence) */ |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 626 | HeadlessArrayOf<USHORT> |
| 627 | inputX; /* Array of input values (start with |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 628 | * second glyph) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 629 | ArrayOf<USHORT> |
| 630 | lookaheadX; /* Array of lookahead values's (to be |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 631 | * matched after the input sequence) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 632 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 633 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 634 | * design order) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 635 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 636 | DEFINE_SIZE_MIN (8); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 637 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 638 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 639 | struct ChainRuleSet |
| 640 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 641 | inline bool apply (hb_apply_context_t *c, ChainContextLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 642 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 643 | TRACE_APPLY (); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 644 | unsigned int num_rules = rule.len; |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 645 | for (unsigned int i = 0; i < num_rules; i++) |
| 646 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 647 | if ((this+rule[i]).apply (c, lookup_context)) |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 648 | return true; |
| 649 | } |
| 650 | |
| 651 | return false; |
| 652 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 653 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 654 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 655 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 656 | return rule.sanitize (c, this); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 657 | } |
| 658 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 659 | private: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 660 | OffsetArrayOf<ChainRule> |
| 661 | rule; /* Array of ChainRule tables |
| 662 | * ordered by preference */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 663 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 664 | DEFINE_SIZE_ARRAY (2, rule); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 665 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 666 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 667 | struct ChainContextFormat1 |
| 668 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 669 | friend struct ChainContext; |
| 670 | |
| 671 | private: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 672 | 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] | 673 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 674 | TRACE_APPLY (); |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 675 | unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 676 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 677 | return false; |
| 678 | |
| 679 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 680 | struct ChainContextLookupContext lookup_context = { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 681 | {match_glyph, apply_func}, |
| 682 | {NULL, NULL, NULL} |
| 683 | }; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 684 | return rule_set.apply (c, lookup_context); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 685 | } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 686 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 687 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 688 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 689 | return coverage.sanitize (c, this) |
| 690 | && ruleSet.sanitize (c, this); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 691 | } |
| 692 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 693 | private: |
| 694 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 695 | OffsetTo<Coverage> |
| 696 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 697 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 698 | OffsetArrayOf<ChainRuleSet> |
| 699 | ruleSet; /* Array of ChainRuleSet tables |
| 700 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 701 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 702 | DEFINE_SIZE_ARRAY (6, ruleSet); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 703 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 704 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 705 | struct ChainContextFormat2 |
| 706 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 707 | friend struct ChainContext; |
| 708 | |
| 709 | private: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 710 | 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] | 711 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 712 | TRACE_APPLY (); |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 713 | unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 714 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 715 | return false; |
| 716 | |
| 717 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 718 | const ClassDef &input_class_def = this+inputClassDef; |
| 719 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 720 | |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 721 | index = input_class_def (c->buffer->info[c->buffer->idx].codepoint); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 722 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 723 | struct ChainContextLookupContext lookup_context = { |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 724 | {match_class, apply_func}, |
| 725 | {&backtrack_class_def, |
| 726 | &input_class_def, |
| 727 | &lookahead_class_def} |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 728 | }; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 729 | return rule_set.apply (c, lookup_context); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 732 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 733 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 734 | return coverage.sanitize (c, this) |
| 735 | && backtrackClassDef.sanitize (c, this) |
| 736 | && inputClassDef.sanitize (c, this) |
| 737 | && lookaheadClassDef.sanitize (c, this) |
| 738 | && ruleSet.sanitize (c, this); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 739 | } |
| 740 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 741 | private: |
| 742 | USHORT format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 743 | OffsetTo<Coverage> |
| 744 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 745 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 746 | OffsetTo<ClassDef> |
| 747 | backtrackClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 748 | * containing backtrack sequence |
| 749 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 750 | OffsetTo<ClassDef> |
| 751 | inputClassDef; /* Offset to glyph ClassDef |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 752 | * table containing input sequence |
| 753 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 754 | OffsetTo<ClassDef> |
| 755 | lookaheadClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 756 | * containing lookahead sequence |
| 757 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 758 | OffsetArrayOf<ChainRuleSet> |
| 759 | ruleSet; /* Array of ChainRuleSet tables |
| 760 | * ordered by class */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 761 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 762 | DEFINE_SIZE_ARRAY (12, ruleSet); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 763 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 764 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 765 | struct ChainContextFormat3 |
| 766 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 767 | friend struct ChainContext; |
| 768 | |
| 769 | private: |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 770 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 771 | 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] | 772 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 773 | TRACE_APPLY (); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 774 | const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 775 | |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 776 | unsigned int index = (this+input[0]) (c->buffer->info[c->buffer->idx].codepoint); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 777 | if (likely (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 778 | return false; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 779 | |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 780 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
| 781 | const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 782 | struct ChainContextLookupContext lookup_context = { |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 783 | {match_coverage, apply_func}, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 784 | {this, this, this} |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 785 | }; |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 786 | return chain_context_lookup (c, |
Behdad Esfahbod | b961518 | 2010-05-10 18:20:54 -0400 | [diff] [blame] | 787 | backtrack.len, (const USHORT *) backtrack.array, |
| 788 | input.len, (const USHORT *) input.array + 1, |
| 789 | lookahead.len, (const USHORT *) lookahead.array, |
| 790 | lookup.len, lookup.array, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 791 | lookup_context); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 792 | } |
| 793 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 794 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 795 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 796 | if (!backtrack.sanitize (c, this)) return false; |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 797 | OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 798 | if (!input.sanitize (c, this)) return false; |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 799 | OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 800 | if (!lookahead.sanitize (c, this)) return false; |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 801 | ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 802 | return lookup.sanitize (c); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 803 | } |
| 804 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 805 | private: |
| 806 | USHORT format; /* Format identifier--format = 3 */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 807 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 808 | backtrack; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 809 | * in backtracking sequence, in glyph |
| 810 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 811 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 812 | inputX ; /* Array of coverage |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 813 | * tables in input sequence, in glyph |
| 814 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 815 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 816 | lookaheadX; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 817 | * in lookahead sequence, in glyph |
| 818 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 819 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 820 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 821 | * design order) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 822 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 823 | DEFINE_SIZE_MIN (10); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 824 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 825 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 826 | struct ChainContext |
| 827 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 828 | protected: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 829 | 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] | 830 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 831 | TRACE_APPLY (); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 832 | switch (u.format) { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 833 | case 1: return u.format1.apply (c, apply_func); |
| 834 | case 2: return u.format2.apply (c, apply_func); |
| 835 | case 3: return u.format3.apply (c, apply_func); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 836 | default:return false; |
| 837 | } |
| 838 | } |
| 839 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 840 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 841 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 842 | if (!u.format.sanitize (c)) return false; |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 843 | switch (u.format) { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 844 | case 1: return u.format1.sanitize (c); |
| 845 | case 2: return u.format2.sanitize (c); |
| 846 | case 3: return u.format3.sanitize (c); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 847 | default:return true; |
| 848 | } |
| 849 | } |
| 850 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 851 | private: |
| 852 | union { |
| 853 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 854 | ChainContextFormat1 format1; |
| 855 | ChainContextFormat2 format2; |
| 856 | ChainContextFormat3 format3; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 857 | } u; |
| 858 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 859 | |
| 860 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 861 | struct ExtensionFormat1 |
| 862 | { |
| 863 | friend struct Extension; |
| 864 | |
Behdad Esfahbod | 1893948 | 2009-08-04 14:27:56 -0400 | [diff] [blame] | 865 | protected: |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 866 | inline unsigned int get_type (void) const { return extensionLookupType; } |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 867 | inline unsigned int get_offset (void) const { return extensionOffset; } |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 868 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 869 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 870 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 871 | return c->check_struct (this); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 872 | } |
| 873 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 874 | private: |
| 875 | USHORT format; /* Format identifier. Set to 1. */ |
| 876 | USHORT extensionLookupType; /* Lookup type of subtable referenced |
| 877 | * by ExtensionOffset (i.e. the |
| 878 | * extension subtable). */ |
Behdad Esfahbod | 81f2af4 | 2010-04-22 00:58:49 -0400 | [diff] [blame] | 879 | ULONG extensionOffset; /* Offset to the extension subtable, |
| 880 | * of lookup type subtable. */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 881 | public: |
| 882 | DEFINE_SIZE_STATIC (8); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 883 | }; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 884 | |
| 885 | struct Extension |
| 886 | { |
| 887 | inline unsigned int get_type (void) const |
| 888 | { |
| 889 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 890 | case 1: return u.format1.get_type (); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 891 | default:return 0; |
| 892 | } |
| 893 | } |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 894 | inline unsigned int get_offset (void) const |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 895 | { |
| 896 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 897 | case 1: return u.format1.get_offset (); |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 898 | default:return 0; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 902 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 903 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 904 | if (!u.format.sanitize (c)) return false; |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 905 | switch (u.format) { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 906 | case 1: return u.format1.sanitize (c); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 907 | default:return true; |
| 908 | } |
| 909 | } |
| 910 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 911 | private: |
| 912 | union { |
| 913 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 914 | ExtensionFormat1 format1; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 915 | } u; |
| 916 | }; |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 917 | |
| 918 | |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 919 | /* |
| 920 | * GSUB/GPOS Common |
| 921 | */ |
| 922 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 923 | struct GSUBGPOS |
| 924 | { |
Behdad Esfahbod | a328d66 | 2009-08-04 20:27:05 -0400 | [diff] [blame] | 925 | static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB; |
| 926 | static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS; |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 927 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 928 | inline unsigned int get_script_count (void) const |
| 929 | { return (this+scriptList).len; } |
| 930 | inline const Tag& get_script_tag (unsigned int i) const |
| 931 | { return (this+scriptList).get_tag (i); } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 932 | inline unsigned int get_script_tags (unsigned int start_offset, |
| 933 | unsigned int *script_count /* IN/OUT */, |
| 934 | hb_tag_t *script_tags /* OUT */) const |
| 935 | { return (this+scriptList).get_tags (start_offset, script_count, script_tags); } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 936 | inline const Script& get_script (unsigned int i) const |
| 937 | { return (this+scriptList)[i]; } |
| 938 | inline bool find_script_index (hb_tag_t tag, unsigned int *index) const |
| 939 | { return (this+scriptList).find_index (tag, index); } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 940 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 941 | inline unsigned int get_feature_count (void) const |
| 942 | { return (this+featureList).len; } |
| 943 | inline const Tag& get_feature_tag (unsigned int i) const |
| 944 | { return (this+featureList).get_tag (i); } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 945 | inline unsigned int get_feature_tags (unsigned int start_offset, |
| 946 | unsigned int *feature_count /* IN/OUT */, |
| 947 | hb_tag_t *feature_tags /* OUT */) const |
| 948 | { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 949 | inline const Feature& get_feature (unsigned int i) const |
| 950 | { return (this+featureList)[i]; } |
| 951 | inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const |
| 952 | { return (this+featureList).find_index (tag, index); } |
| 953 | |
| 954 | inline unsigned int get_lookup_count (void) const |
| 955 | { return (this+lookupList).len; } |
| 956 | inline const Lookup& get_lookup (unsigned int i) const |
| 957 | { return (this+lookupList)[i]; } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 958 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 959 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 960 | TRACE_SANITIZE (); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 961 | return version.sanitize (c) && likely (version.major == 1) |
| 962 | && scriptList.sanitize (c, this) |
| 963 | && featureList.sanitize (c, this) |
| 964 | && lookupList.sanitize (c, this); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 965 | } |
| 966 | |
Behdad Esfahbod | 212aba6 | 2009-05-24 00:50:27 -0400 | [diff] [blame] | 967 | protected: |
Behdad Esfahbod | 87fcdcb | 2009-05-24 01:03:24 -0400 | [diff] [blame] | 968 | FixedVersion version; /* Version of the GSUB/GPOS table--initially set |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 969 | * to 0x00010000 */ |
| 970 | OffsetTo<ScriptList> |
| 971 | scriptList; /* ScriptList table */ |
| 972 | OffsetTo<FeatureList> |
| 973 | featureList; /* FeatureList table */ |
| 974 | OffsetTo<LookupList> |
| 975 | lookupList; /* LookupList table */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 976 | public: |
| 977 | DEFINE_SIZE_STATIC (10); |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 978 | }; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 979 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 980 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 981 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 982 | #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */ |