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