Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007,2008,2009 Red Hat, Inc. |
| 3 | * |
| 4 | * This is part of HarfBuzz, an OpenType Layout engine library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Red Hat Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 27 | #ifndef HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH |
| 28 | #define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 29 | |
Behdad Esfahbod | 88a5f5a | 2009-05-25 03:39:11 -0400 | [diff] [blame] | 30 | #include "hb-buffer-private.h" |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 31 | #include "hb-ot-layout-gdef-private.hh" |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 32 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 33 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 34 | #define APPLY_ARG_DEF \ |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 35 | hb_ot_layout_context_t *context, \ |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 36 | hb_buffer_t *buffer, \ |
| 37 | unsigned int context_length HB_GNUC_UNUSED, \ |
| 38 | unsigned int nesting_level_left HB_GNUC_UNUSED, \ |
Behdad Esfahbod | ecf17e8 | 2009-05-17 09:34:41 -0400 | [diff] [blame] | 39 | unsigned int lookup_flag, \ |
| 40 | unsigned int property HB_GNUC_UNUSED /* propety of first glyph */ |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 41 | #define APPLY_ARG \ |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 42 | context, \ |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 43 | buffer, \ |
| 44 | context_length, \ |
| 45 | nesting_level_left, \ |
Behdad Esfahbod | ecf17e8 | 2009-05-17 09:34:41 -0400 | [diff] [blame] | 46 | lookup_flag, \ |
| 47 | property |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 48 | |
| 49 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 50 | typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data); |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 51 | typedef bool (*apply_lookup_func_t) (APPLY_ARG_DEF, unsigned int lookup_index); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 52 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 53 | struct ContextFuncs |
| 54 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 55 | match_func_t match; |
| 56 | apply_lookup_func_t apply; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 57 | }; |
| 58 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 59 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 60 | static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data) |
| 61 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 62 | return glyph_id == value; |
| 63 | } |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 64 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 65 | static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, char *data) |
| 66 | { |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 67 | const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 68 | return class_def.get_class (glyph_id) == value; |
| 69 | } |
| 70 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 71 | static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, char *data) |
| 72 | { |
Behdad Esfahbod | 6b54c5d | 2009-05-18 18:30:25 -0400 | [diff] [blame] | 73 | const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 74 | return (data+coverage) (glyph_id) != NOT_COVERED; |
| 75 | } |
| 76 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 77 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 78 | static inline bool match_input (APPLY_ARG_DEF, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 79 | unsigned int count, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 80 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 81 | match_func_t match_func, |
| 82 | char *match_data, |
| 83 | unsigned int *context_length_out) |
| 84 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 85 | unsigned int i, j; |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 86 | unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); |
| 87 | if (HB_UNLIKELY (buffer->in_pos + count > end)) |
| 88 | return false; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 89 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 90 | for (i = 1, j = buffer->in_pos + 1; i < count; i++, j++) |
| 91 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 92 | while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), lookup_flag, NULL)) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 93 | { |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 94 | if (HB_UNLIKELY (j + count - i == end)) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 95 | return false; |
| 96 | j++; |
| 97 | } |
| 98 | |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 99 | if (HB_LIKELY (!match_func (IN_GLYPH (j), input[i - 1], match_data))) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 103 | *context_length_out = j - buffer->in_pos; |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 108 | static inline bool match_backtrack (APPLY_ARG_DEF, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 109 | unsigned int count, |
| 110 | const USHORT backtrack[], |
| 111 | match_func_t match_func, |
| 112 | char *match_data) |
| 113 | { |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 114 | if (HB_UNLIKELY (buffer->out_pos < count)) |
| 115 | return false; |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 116 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 117 | for (unsigned int i = 0, j = buffer->out_pos - 1; i < count; i++, j--) |
| 118 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 119 | while (_hb_ot_layout_skip_mark (context->face, OUT_INFO (j), lookup_flag, NULL)) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 120 | { |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 121 | if (HB_UNLIKELY (j + 1 == count - i)) |
| 122 | return false; |
| 123 | j--; |
| 124 | } |
| 125 | |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 126 | if (HB_LIKELY (!match_func (OUT_GLYPH (j), backtrack[i], match_data))) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 127 | return false; |
| 128 | } |
| 129 | |
| 130 | return true; |
| 131 | } |
| 132 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 133 | static inline bool match_lookahead (APPLY_ARG_DEF, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 134 | unsigned int count, |
| 135 | const USHORT lookahead[], |
| 136 | match_func_t match_func, |
| 137 | char *match_data, |
| 138 | unsigned int offset) |
| 139 | { |
| 140 | unsigned int i, j; |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 141 | unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); |
| 142 | if (HB_UNLIKELY (buffer->in_pos + offset + count > end)) |
| 143 | return false; |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 144 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 145 | for (i = 0, j = buffer->in_pos + offset; i < count; i++, j++) |
| 146 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 147 | while (_hb_ot_layout_skip_mark (context->face, OUT_INFO (j), lookup_flag, NULL)) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 148 | { |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 149 | if (HB_UNLIKELY (j + count - i == end)) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 150 | return false; |
| 151 | j++; |
| 152 | } |
| 153 | |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 154 | if (HB_LIKELY (!match_func (IN_GLYPH (j), lookahead[i], match_data))) |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 155 | return false; |
| 156 | } |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 157 | |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 162 | struct LookupRecord |
| 163 | { |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 164 | public: |
| 165 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 166 | SANITIZE_DEBUG (); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 167 | return SANITIZE_SELF (); |
| 168 | } |
| 169 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 170 | USHORT sequenceIndex; /* Index into current glyph |
| 171 | * sequence--first glyph = 0 */ |
| 172 | USHORT lookupListIndex; /* Lookup to apply to that |
| 173 | * position--zero--based */ |
| 174 | }; |
| 175 | ASSERT_SIZE (LookupRecord, 4); |
| 176 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 177 | static inline bool apply_lookup (APPLY_ARG_DEF, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 178 | unsigned int count, /* Including the first glyph */ |
| 179 | unsigned int lookupCount, |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 180 | const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ |
| 181 | apply_lookup_func_t apply_func) |
| 182 | { |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 183 | unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); |
| 184 | if (HB_UNLIKELY (buffer->in_pos + count > end)) |
| 185 | return false; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 186 | |
Behdad Esfahbod | 7cff75b | 2009-05-18 04:09:05 -0400 | [diff] [blame] | 187 | /* TODO We don't support lookupRecord arrays that are not increasing: |
| 188 | * Should be easy for in_place ones at least. */ |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 189 | for (unsigned int i = 0; i < count; i++) |
| 190 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 191 | while (_hb_ot_layout_skip_mark (context->face, IN_CURINFO (), lookup_flag, NULL)) |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 192 | { |
Behdad Esfahbod | e73a0c2 | 2009-05-18 04:15:25 -0400 | [diff] [blame] | 193 | if (HB_UNLIKELY (buffer->in_pos == end)) |
| 194 | return true; |
| 195 | /* No lookup applied for this index */ |
| 196 | _hb_buffer_next_glyph (buffer); |
| 197 | } |
| 198 | |
Behdad Esfahbod | 47958de | 2009-05-18 04:17:47 -0400 | [diff] [blame] | 199 | if (lookupCount && i == lookupRecord->sequenceIndex) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 200 | { |
| 201 | unsigned int old_pos = buffer->in_pos; |
| 202 | |
| 203 | /* Apply a lookup */ |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 204 | bool done = apply_func (APPLY_ARG, lookupRecord->lookupListIndex); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 205 | |
Behdad Esfahbod | 47958de | 2009-05-18 04:17:47 -0400 | [diff] [blame] | 206 | lookupRecord++; |
| 207 | lookupCount--; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 208 | i += buffer->in_pos - old_pos; |
Behdad Esfahbod | 2e8fb6c | 2009-05-18 04:37:37 -0400 | [diff] [blame] | 209 | if (HB_UNLIKELY (buffer->in_pos == end)) |
| 210 | return true; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 211 | |
| 212 | if (!done) |
| 213 | goto not_applied; |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | not_applied: |
| 218 | /* No lookup applied for this index */ |
| 219 | _hb_buffer_next_glyph (buffer); |
| 220 | i++; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | return true; |
| 225 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 226 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 227 | |
| 228 | /* Contextual lookups */ |
| 229 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 230 | struct ContextLookupContext |
| 231 | { |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 232 | ContextFuncs funcs; |
| 233 | char *match_data; |
| 234 | }; |
| 235 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 236 | static inline bool context_lookup (APPLY_ARG_DEF, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 237 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 238 | const USHORT input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 239 | unsigned int lookupCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 240 | const LookupRecord lookupRecord[], |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 241 | ContextLookupContext &lookup_context) |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 242 | { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 243 | return match_input (APPLY_ARG, |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 244 | inputCount, input, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 245 | lookup_context.funcs.match, lookup_context.match_data, |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 246 | &context_length) && |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 247 | apply_lookup (APPLY_ARG, |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 248 | inputCount, |
| 249 | lookupCount, lookupRecord, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 250 | lookup_context.funcs.apply); |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 253 | struct Rule |
| 254 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 255 | friend struct RuleSet; |
| 256 | |
| 257 | private: |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 258 | inline bool apply (APPLY_ARG_DEF, ContextLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 259 | { |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 260 | const LookupRecord *lookupRecord = &CONST_CAST (LookupRecord, input, sizeof (input[0]) * (inputCount ? inputCount - 1 : 0)); |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 261 | return context_lookup (APPLY_ARG, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 262 | inputCount, input, |
| 263 | lookupCount, lookupRecord, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 264 | lookup_context); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 265 | } |
| 266 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 267 | public: |
| 268 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 269 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 270 | if (!SANITIZE_SELF ()) return false; |
| 271 | return SANITIZE_MEM (input, |
| 272 | sizeof (input[0]) * inputCount + |
| 273 | sizeof (lookupRecordX[0]) * lookupCount); |
| 274 | } |
| 275 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 276 | private: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 277 | USHORT inputCount; /* Total number of glyphs in input |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 278 | * glyph sequence--includes the first |
| 279 | * glyph */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 280 | USHORT lookupCount; /* Number of LookupRecords */ |
| 281 | USHORT input[]; /* Array of match inputs--start with |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 282 | * second glyph */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 283 | LookupRecord lookupRecordX[]; /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 284 | * design order */ |
| 285 | }; |
| 286 | ASSERT_SIZE (Rule, 4); |
| 287 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 288 | struct RuleSet |
| 289 | { |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 290 | inline bool apply (APPLY_ARG_DEF, ContextLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 291 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 292 | unsigned int num_rules = rule.len; |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 293 | for (unsigned int i = 0; i < num_rules; i++) |
| 294 | { |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 295 | if ((this+rule[i]).apply (APPLY_ARG, lookup_context)) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 296 | return true; |
| 297 | } |
| 298 | |
| 299 | return false; |
| 300 | } |
| 301 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 302 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 303 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 304 | return SANITIZE_THIS (rule); |
| 305 | } |
| 306 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 307 | private: |
| 308 | OffsetArrayOf<Rule> |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 309 | rule; /* Array of Rule tables |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 310 | * ordered by preference */ |
| 311 | }; |
| 312 | |
| 313 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 314 | struct ContextFormat1 |
| 315 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 316 | friend struct Context; |
| 317 | |
| 318 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 319 | inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const |
| 320 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 321 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 322 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 323 | return false; |
| 324 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 325 | const RuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 326 | struct ContextLookupContext lookup_context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 327 | {match_glyph, apply_func}, |
| 328 | NULL |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 329 | }; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 330 | return rule_set.apply (APPLY_ARG, lookup_context); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 333 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 334 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 335 | return SANITIZE_THIS2 (coverage, ruleSet); |
| 336 | } |
| 337 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 338 | private: |
| 339 | USHORT format; /* Format identifier--format = 1 */ |
| 340 | OffsetTo<Coverage> |
| 341 | coverage; /* Offset to Coverage table--from |
| 342 | * beginning of table */ |
| 343 | OffsetArrayOf<RuleSet> |
| 344 | ruleSet; /* Array of RuleSet tables |
| 345 | * ordered by Coverage Index */ |
| 346 | }; |
| 347 | ASSERT_SIZE (ContextFormat1, 6); |
| 348 | |
| 349 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 350 | struct ContextFormat2 |
| 351 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 352 | friend struct Context; |
| 353 | |
| 354 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 355 | inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const |
| 356 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 357 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 358 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 359 | return false; |
| 360 | |
| 361 | const ClassDef &class_def = this+classDef; |
| 362 | index = class_def (IN_CURGLYPH ()); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 363 | const RuleSet &rule_set = this+ruleSet[index]; |
| 364 | /* LONGTERMTODO: Old code fetches glyph classes at most once and caches |
| 365 | * them across subrule lookups. Not sure it's worth it. |
| 366 | */ |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 367 | struct ContextLookupContext lookup_context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 368 | {match_class, apply_func}, |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 369 | DECONST_CHARP(&class_def) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 370 | }; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 371 | return rule_set.apply (APPLY_ARG, lookup_context); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 372 | } |
| 373 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 374 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 375 | SANITIZE_DEBUG (); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 376 | return SANITIZE_THIS3 (coverage, classDef, ruleSet); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 377 | } |
| 378 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 379 | private: |
| 380 | USHORT format; /* Format identifier--format = 2 */ |
| 381 | OffsetTo<Coverage> |
| 382 | coverage; /* Offset to Coverage table--from |
| 383 | * beginning of table */ |
| 384 | OffsetTo<ClassDef> |
| 385 | classDef; /* Offset to glyph ClassDef table--from |
| 386 | * beginning of table */ |
| 387 | OffsetArrayOf<RuleSet> |
| 388 | ruleSet; /* Array of RuleSet tables |
| 389 | * ordered by class */ |
| 390 | }; |
| 391 | ASSERT_SIZE (ContextFormat2, 8); |
| 392 | |
| 393 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 394 | struct ContextFormat3 |
| 395 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 396 | friend struct Context; |
| 397 | |
| 398 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 399 | inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const |
| 400 | { |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 401 | unsigned int index = (this+coverage[0]) (IN_CURGLYPH ()); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 402 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 403 | return false; |
| 404 | |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 405 | const LookupRecord *lookupRecord = &CONST_CAST(LookupRecord, coverage, sizeof (coverage[0]) * glyphCount); |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 406 | struct ContextLookupContext lookup_context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 407 | {match_coverage, apply_func}, |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 408 | DECONST_CHARP(this) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 409 | }; |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 410 | return context_lookup (APPLY_ARG, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 411 | glyphCount, (const USHORT *) (coverage + 1), |
| 412 | lookupCount, lookupRecord, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 413 | lookup_context); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 414 | } |
| 415 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 416 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 417 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 418 | if (!SANITIZE_SELF ()) return false; |
| 419 | unsigned int count = glyphCount; |
| 420 | for (unsigned int i = 0; i < count; i++) |
| 421 | if (!SANITIZE_THIS (coverage[i])) return false; |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 422 | LookupRecord *lookupRecord = &CAST(LookupRecord, coverage, sizeof (coverage[0]) * glyphCount); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 423 | return SANITIZE_MEM (lookupRecord, sizeof (lookupRecord[0]) * lookupCount); |
| 424 | } |
| 425 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 426 | private: |
| 427 | USHORT format; /* Format identifier--format = 3 */ |
| 428 | USHORT glyphCount; /* Number of glyphs in the input glyph |
| 429 | * sequence */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 430 | USHORT lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 431 | OffsetTo<Coverage> |
| 432 | coverage[]; /* Array of offsets to Coverage |
| 433 | * table in glyph sequence order */ |
| 434 | LookupRecord lookupRecordX[]; /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 435 | * design order */ |
| 436 | }; |
| 437 | ASSERT_SIZE (ContextFormat3, 6); |
| 438 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 439 | struct Context |
| 440 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 441 | protected: |
Behdad Esfahbod | 20b035d | 2009-08-10 19:00:36 -0400 | [diff] [blame] | 442 | inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 443 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 444 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 445 | case 1: return u.format1->apply (APPLY_ARG, apply_func); |
| 446 | case 2: return u.format2->apply (APPLY_ARG, apply_func); |
| 447 | case 3: return u.format3->apply (APPLY_ARG, apply_func); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 448 | default:return false; |
| 449 | } |
| 450 | } |
| 451 | |
Behdad Esfahbod | 20b035d | 2009-08-10 19:00:36 -0400 | [diff] [blame] | 452 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 453 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 454 | if (!SANITIZE (u.format)) return false; |
| 455 | switch (u.format) { |
| 456 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 457 | case 2: return u.format2->sanitize (SANITIZE_ARG); |
| 458 | case 3: return u.format3->sanitize (SANITIZE_ARG); |
| 459 | default:return true; |
| 460 | } |
| 461 | } |
| 462 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 463 | private: |
| 464 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 465 | USHORT format; /* Format identifier */ |
| 466 | ContextFormat1 format1[]; |
| 467 | ContextFormat2 format2[]; |
| 468 | ContextFormat3 format3[]; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 469 | } u; |
| 470 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 471 | ASSERT_SIZE (Context, 2); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 472 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 473 | |
| 474 | /* Chaining Contextual lookups */ |
| 475 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 476 | struct ChainContextLookupContext |
| 477 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 478 | ContextFuncs funcs; |
| 479 | char *match_data[3]; |
| 480 | }; |
| 481 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 482 | static inline bool chain_context_lookup (APPLY_ARG_DEF, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 483 | unsigned int backtrackCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 484 | const USHORT backtrack[], |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 485 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 486 | const USHORT input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 487 | unsigned int lookaheadCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 488 | const USHORT lookahead[], |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 489 | unsigned int lookupCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 490 | const LookupRecord lookupRecord[], |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 491 | ChainContextLookupContext &lookup_context) |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 492 | { |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 493 | /* First guess */ |
| 494 | if (HB_UNLIKELY (buffer->out_pos < backtrackCount || |
Behdad Esfahbod | 122f21f | 2009-05-18 04:21:53 -0400 | [diff] [blame] | 495 | buffer->in_pos + inputCount + lookaheadCount > buffer->in_length || |
| 496 | inputCount + lookaheadCount > context_length)) |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 497 | return false; |
| 498 | |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 499 | unsigned int offset; |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 500 | return match_backtrack (APPLY_ARG, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 501 | backtrackCount, backtrack, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 502 | lookup_context.funcs.match, lookup_context.match_data[0]) && |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 503 | match_input (APPLY_ARG, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 504 | inputCount, input, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 505 | lookup_context.funcs.match, lookup_context.match_data[1], |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 506 | &offset) && |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 507 | match_lookahead (APPLY_ARG, |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 508 | lookaheadCount, lookahead, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 509 | lookup_context.funcs.match, lookup_context.match_data[2], |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame] | 510 | offset) && |
| 511 | (context_length = offset, true) && |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 512 | apply_lookup (APPLY_ARG, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 513 | inputCount, |
| 514 | lookupCount, lookupRecord, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 515 | lookup_context.funcs.apply); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 516 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 517 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 518 | struct ChainRule |
| 519 | { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 520 | friend struct ChainRuleSet; |
| 521 | |
| 522 | private: |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 523 | inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 524 | { |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 525 | const HeadlessArrayOf<USHORT> &input = CONST_NEXT (HeadlessArrayOf<USHORT>, backtrack); |
| 526 | const ArrayOf<USHORT> &lookahead = CONST_NEXT (ArrayOf<USHORT>, input); |
| 527 | const ArrayOf<LookupRecord> &lookup = CONST_NEXT (ArrayOf<LookupRecord>, lookahead); |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 528 | return chain_context_lookup (APPLY_ARG, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 529 | backtrack.len, backtrack.array, |
| 530 | input.len, input.array + 1, |
| 531 | lookahead.len, lookahead.array, |
| 532 | lookup.len, lookup.array, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 533 | lookup_context); |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 534 | return false; |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 535 | } |
| 536 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 537 | public: |
| 538 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 539 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 540 | if (!SANITIZE (backtrack)) return false; |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 541 | HeadlessArrayOf<USHORT> &input = NEXT (HeadlessArrayOf<USHORT>, backtrack); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 542 | if (!SANITIZE (input)) return false; |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 543 | ArrayOf<USHORT> &lookahead = NEXT (ArrayOf<USHORT>, input); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 544 | if (!SANITIZE (lookahead)) return false; |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 545 | ArrayOf<LookupRecord> &lookup = NEXT (ArrayOf<LookupRecord>, lookahead); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 546 | return SANITIZE (lookup); |
| 547 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 548 | |
| 549 | private: |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 550 | ArrayOf<USHORT> |
| 551 | backtrack; /* Array of backtracking values |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 552 | * (to be matched before the input |
| 553 | * sequence) */ |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 554 | HeadlessArrayOf<USHORT> |
| 555 | inputX; /* Array of input values (start with |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 556 | * second glyph) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 557 | ArrayOf<USHORT> |
| 558 | lookaheadX; /* Array of lookahead values's (to be |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 559 | * matched after the input sequence) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 560 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 561 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 562 | * design order) */ |
| 563 | }; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 564 | ASSERT_SIZE (ChainRule, 8); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 565 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 566 | struct ChainRuleSet |
| 567 | { |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 568 | inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &lookup_context) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 569 | { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 570 | unsigned int num_rules = rule.len; |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 571 | for (unsigned int i = 0; i < num_rules; i++) |
| 572 | { |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 573 | if ((this+rule[i]).apply (APPLY_ARG, lookup_context)) |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 574 | return true; |
| 575 | } |
| 576 | |
| 577 | return false; |
| 578 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 579 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 580 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 581 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 582 | return SANITIZE_THIS (rule); |
| 583 | } |
| 584 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 585 | private: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 586 | OffsetArrayOf<ChainRule> |
| 587 | rule; /* Array of ChainRule tables |
| 588 | * ordered by preference */ |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 589 | }; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 590 | ASSERT_SIZE (ChainRuleSet, 2); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 591 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 592 | struct ChainContextFormat1 |
| 593 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 594 | friend struct ChainContext; |
| 595 | |
| 596 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 597 | inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const |
| 598 | { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 599 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 600 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 601 | return false; |
| 602 | |
| 603 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 604 | struct ChainContextLookupContext lookup_context = { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 605 | {match_glyph, apply_func}, |
| 606 | {NULL, NULL, NULL} |
| 607 | }; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 608 | return rule_set.apply (APPLY_ARG, lookup_context); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 609 | } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 610 | |
| 611 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 612 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 613 | return SANITIZE_THIS2 (coverage, ruleSet); |
| 614 | } |
| 615 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 616 | private: |
| 617 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 618 | OffsetTo<Coverage> |
| 619 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 620 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 621 | OffsetArrayOf<ChainRuleSet> |
| 622 | ruleSet; /* Array of ChainRuleSet tables |
| 623 | * ordered by Coverage Index */ |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 624 | }; |
| 625 | ASSERT_SIZE (ChainContextFormat1, 6); |
| 626 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 627 | struct ChainContextFormat2 |
| 628 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 629 | friend struct ChainContext; |
| 630 | |
| 631 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 632 | inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const |
| 633 | { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 634 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 635 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 636 | return false; |
| 637 | |
| 638 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 639 | const ClassDef &input_class_def = this+inputClassDef; |
| 640 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 641 | |
| 642 | index = input_class_def (IN_CURGLYPH ()); |
| 643 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 644 | /* LONGTERMTODO: Old code fetches glyph classes at most once and caches |
| 645 | * them across subrule lookups. Not sure it's worth it. |
| 646 | */ |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 647 | struct ChainContextLookupContext lookup_context = { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 648 | {match_class, apply_func}, |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 649 | {DECONST_CHARP(&backtrack_class_def), |
| 650 | DECONST_CHARP(&input_class_def), |
| 651 | DECONST_CHARP(&lookahead_class_def)} |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 652 | }; |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 653 | return rule_set.apply (APPLY_ARG, lookup_context); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 654 | } |
| 655 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 656 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 657 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 658 | return SANITIZE_THIS2 (coverage, backtrackClassDef) && |
| 659 | SANITIZE_THIS2 (inputClassDef, lookaheadClassDef) && |
| 660 | SANITIZE_THIS (ruleSet); |
| 661 | } |
| 662 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 663 | private: |
| 664 | USHORT format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 665 | OffsetTo<Coverage> |
| 666 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 667 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 668 | OffsetTo<ClassDef> |
| 669 | backtrackClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 670 | * containing backtrack sequence |
| 671 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 672 | OffsetTo<ClassDef> |
| 673 | inputClassDef; /* Offset to glyph ClassDef |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 674 | * table containing input sequence |
| 675 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 676 | OffsetTo<ClassDef> |
| 677 | lookaheadClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 678 | * containing lookahead sequence |
| 679 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 680 | OffsetArrayOf<ChainRuleSet> |
| 681 | ruleSet; /* Array of ChainRuleSet tables |
| 682 | * ordered by class */ |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 683 | }; |
| 684 | ASSERT_SIZE (ChainContextFormat2, 12); |
| 685 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 686 | struct ChainContextFormat3 |
| 687 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 688 | friend struct ChainContext; |
| 689 | |
| 690 | private: |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 691 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 692 | inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const |
| 693 | { |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 694 | const OffsetArrayOf<Coverage> &input = CONST_NEXT (OffsetArrayOf<Coverage>, backtrack); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 695 | |
| 696 | unsigned int index = (this+input[0]) (IN_CURGLYPH ()); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 697 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 698 | return false; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 699 | |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 700 | const OffsetArrayOf<Coverage> &lookahead = CONST_NEXT (OffsetArrayOf<Coverage>, input); |
| 701 | const ArrayOf<LookupRecord> &lookup = CONST_NEXT (ArrayOf<LookupRecord>, lookahead); |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 702 | struct ChainContextLookupContext lookup_context = { |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 703 | {match_coverage, apply_func}, |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 704 | {DECONST_CHARP(this), DECONST_CHARP(this), DECONST_CHARP(this)} |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 705 | }; |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 706 | return chain_context_lookup (APPLY_ARG, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 707 | backtrack.len, (USHORT *) backtrack.array, |
| 708 | input.len, (USHORT *) input.array, |
| 709 | lookahead.len, (USHORT *) lookahead.array, |
| 710 | lookup.len, lookup.array, |
Behdad Esfahbod | 7cda6fa | 2009-07-29 18:37:57 -0400 | [diff] [blame] | 711 | lookup_context); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 712 | return false; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 715 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 716 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 717 | if (!SANITIZE_THIS (backtrack)) return false; |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 718 | OffsetArrayOf<Coverage> &input = NEXT (OffsetArrayOf<Coverage>, backtrack); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 719 | if (!SANITIZE_THIS (input)) return false; |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 720 | OffsetArrayOf<Coverage> &lookahead = NEXT (OffsetArrayOf<Coverage>, input); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 721 | if (!SANITIZE_THIS (lookahead)) return false; |
Behdad Esfahbod | 284899c | 2009-08-09 22:10:39 -0400 | [diff] [blame] | 722 | ArrayOf<LookupRecord> &lookup = NEXT (ArrayOf<LookupRecord>, lookahead); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 723 | return SANITIZE (lookup); |
| 724 | } |
| 725 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 726 | private: |
| 727 | USHORT format; /* Format identifier--format = 3 */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 728 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 729 | backtrack; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 730 | * in backtracking sequence, in glyph |
| 731 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 732 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 733 | inputX ; /* Array of coverage |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 734 | * tables in input sequence, in glyph |
| 735 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 736 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 737 | lookaheadX; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 738 | * in lookahead sequence, in glyph |
| 739 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 740 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 741 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 742 | * design order) */ |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 743 | }; |
| 744 | ASSERT_SIZE (ChainContextFormat3, 10); |
| 745 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 746 | struct ChainContext |
| 747 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 748 | protected: |
Behdad Esfahbod | 20b035d | 2009-08-10 19:00:36 -0400 | [diff] [blame] | 749 | inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 750 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 751 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 752 | case 1: return u.format1->apply (APPLY_ARG, apply_func); |
| 753 | case 2: return u.format2->apply (APPLY_ARG, apply_func); |
| 754 | case 3: return u.format3->apply (APPLY_ARG, apply_func); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 755 | default:return false; |
| 756 | } |
| 757 | } |
| 758 | |
Behdad Esfahbod | 20b035d | 2009-08-10 19:00:36 -0400 | [diff] [blame] | 759 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 760 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 761 | if (!SANITIZE (u.format)) return false; |
| 762 | switch (u.format) { |
| 763 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 764 | case 2: return u.format2->sanitize (SANITIZE_ARG); |
| 765 | case 3: return u.format3->sanitize (SANITIZE_ARG); |
| 766 | default:return true; |
| 767 | } |
| 768 | } |
| 769 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 770 | private: |
| 771 | union { |
| 772 | USHORT format; /* Format identifier */ |
| 773 | ChainContextFormat1 format1[]; |
| 774 | ChainContextFormat2 format2[]; |
| 775 | ChainContextFormat3 format3[]; |
| 776 | } u; |
| 777 | }; |
| 778 | ASSERT_SIZE (ChainContext, 2); |
| 779 | |
| 780 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 781 | struct ExtensionFormat1 |
| 782 | { |
| 783 | friend struct Extension; |
| 784 | |
Behdad Esfahbod | 1893948 | 2009-08-04 14:27:56 -0400 | [diff] [blame] | 785 | protected: |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 786 | inline unsigned int get_type (void) const { return extensionLookupType; } |
| 787 | inline unsigned int get_offset (void) const { return (extensionOffset[0] << 16) + extensionOffset[1]; } |
| 788 | inline const LookupSubTable& get_subtable (void) const |
| 789 | { |
| 790 | unsigned int offset = get_offset (); |
| 791 | if (HB_UNLIKELY (!offset)) return Null(LookupSubTable); |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 792 | return CONST_CAST (LookupSubTable, *this, offset); |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 793 | } |
| 794 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 795 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 796 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 797 | return SANITIZE_SELF (); |
| 798 | } |
| 799 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 800 | private: |
| 801 | USHORT format; /* Format identifier. Set to 1. */ |
| 802 | USHORT extensionLookupType; /* Lookup type of subtable referenced |
| 803 | * by ExtensionOffset (i.e. the |
| 804 | * extension subtable). */ |
| 805 | USHORT extensionOffset[2]; /* Offset to the extension subtable, |
| 806 | * of lookup type subtable. |
| 807 | * Defined as two shorts to avoid |
| 808 | * alignment requirements. */ |
| 809 | }; |
| 810 | ASSERT_SIZE (ExtensionFormat1, 8); |
| 811 | |
| 812 | struct Extension |
| 813 | { |
| 814 | inline unsigned int get_type (void) const |
| 815 | { |
| 816 | switch (u.format) { |
| 817 | case 1: return u.format1->get_type (); |
| 818 | default:return 0; |
| 819 | } |
| 820 | } |
| 821 | inline const LookupSubTable& get_subtable (void) const |
| 822 | { |
| 823 | switch (u.format) { |
| 824 | case 1: return u.format1->get_subtable (); |
| 825 | default:return Null(LookupSubTable); |
| 826 | } |
| 827 | } |
| 828 | |
Behdad Esfahbod | 20b035d | 2009-08-10 19:00:36 -0400 | [diff] [blame] | 829 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 830 | SANITIZE_DEBUG (); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 831 | if (!SANITIZE (u.format)) return false; |
| 832 | switch (u.format) { |
| 833 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 834 | default:return true; |
| 835 | } |
| 836 | } |
| 837 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 838 | private: |
| 839 | union { |
| 840 | USHORT format; /* Format identifier */ |
| 841 | ExtensionFormat1 format1[]; |
| 842 | } u; |
| 843 | }; |
| 844 | ASSERT_SIZE (Extension, 2); |
| 845 | |
| 846 | |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 847 | /* |
| 848 | * GSUB/GPOS Common |
| 849 | */ |
| 850 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 851 | struct GSUBGPOS |
| 852 | { |
Behdad Esfahbod | a328d66 | 2009-08-04 20:27:05 -0400 | [diff] [blame] | 853 | static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB; |
| 854 | static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS; |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 855 | |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 856 | STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GSUBGPOS, 1, 1); |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 857 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 858 | inline unsigned int get_script_count (void) const |
| 859 | { return (this+scriptList).len; } |
| 860 | inline const Tag& get_script_tag (unsigned int i) const |
| 861 | { return (this+scriptList).get_tag (i); } |
| 862 | inline bool get_script_tags (unsigned int *script_count /* IN/OUT */, |
| 863 | hb_tag_t *script_tags /* OUT */) const |
| 864 | { return (this+scriptList).get_tags (script_count, script_tags); } |
| 865 | inline const Script& get_script (unsigned int i) const |
| 866 | { return (this+scriptList)[i]; } |
| 867 | inline bool find_script_index (hb_tag_t tag, unsigned int *index) const |
| 868 | { return (this+scriptList).find_index (tag, index); } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 869 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 870 | inline unsigned int get_feature_count (void) const |
| 871 | { return (this+featureList).len; } |
| 872 | inline const Tag& get_feature_tag (unsigned int i) const |
| 873 | { return (this+featureList).get_tag (i); } |
| 874 | inline bool get_feature_tags (unsigned int *feature_count /* IN/OUT */, |
| 875 | hb_tag_t *feature_tags /* OUT */) const |
| 876 | { return (this+featureList).get_tags (feature_count, feature_tags); } |
| 877 | inline const Feature& get_feature (unsigned int i) const |
| 878 | { return (this+featureList)[i]; } |
| 879 | inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const |
| 880 | { return (this+featureList).find_index (tag, index); } |
| 881 | |
| 882 | inline unsigned int get_lookup_count (void) const |
| 883 | { return (this+lookupList).len; } |
| 884 | inline const Lookup& get_lookup (unsigned int i) const |
| 885 | { return (this+lookupList)[i]; } |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 886 | |
Behdad Esfahbod | 20b035d | 2009-08-10 19:00:36 -0400 | [diff] [blame] | 887 | inline bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | b28815c | 2009-08-04 22:35:36 -0400 | [diff] [blame] | 888 | SANITIZE_DEBUG (); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 889 | if (!SANITIZE (version)) return false; |
| 890 | if (version.major != 1) return true; |
| 891 | return SANITIZE_THIS3 (scriptList, featureList, lookupList); |
| 892 | } |
| 893 | |
Behdad Esfahbod | 212aba6 | 2009-05-24 00:50:27 -0400 | [diff] [blame] | 894 | protected: |
Behdad Esfahbod | 87fcdcb | 2009-05-24 01:03:24 -0400 | [diff] [blame] | 895 | FixedVersion version; /* Version of the GSUB/GPOS table--initially set |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 896 | * to 0x00010000 */ |
| 897 | OffsetTo<ScriptList> |
| 898 | scriptList; /* ScriptList table */ |
| 899 | OffsetTo<FeatureList> |
| 900 | featureList; /* FeatureList table */ |
| 901 | OffsetTo<LookupList> |
| 902 | lookupList; /* LookupList table */ |
| 903 | }; |
| 904 | ASSERT_SIZE (GSUBGPOS, 10); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 905 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 906 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 907 | #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */ |