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