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 | |
| 27 | #ifndef HB_OT_LAYOUT_GSUBGPOS_PRIVATE_H |
| 28 | #define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_H |
| 29 | |
| 30 | #include "hb-ot-layout-gdef-private.h" |
| 31 | #include "harfbuzz-buffer-private.h" /* XXX */ |
| 32 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 33 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 34 | #define LOOKUP_ARGS_DEF \ |
| 35 | hb_ot_layout_t *layout, \ |
| 36 | hb_buffer_t *buffer, \ |
| 37 | unsigned int context_length HB_GNUC_UNUSED, \ |
| 38 | unsigned int nesting_level_left HB_GNUC_UNUSED, \ |
Behdad Esfahbod | ecf17e8 | 2009-05-17 09:34:41 -0400 | [diff] [blame] | 39 | unsigned int lookup_flag, \ |
| 40 | unsigned int property HB_GNUC_UNUSED /* propety of first glyph */ |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 41 | #define LOOKUP_ARGS \ |
| 42 | layout, \ |
| 43 | buffer, \ |
| 44 | context_length, \ |
| 45 | nesting_level_left, \ |
Behdad Esfahbod | ecf17e8 | 2009-05-17 09:34:41 -0400 | [diff] [blame] | 46 | lookup_flag, \ |
| 47 | property |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 48 | |
| 49 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 50 | typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data); |
| 51 | typedef bool (*apply_lookup_func_t) (LOOKUP_ARGS_DEF, unsigned int lookup_index); |
| 52 | |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 53 | struct ContextFuncs { |
| 54 | match_func_t match; |
| 55 | apply_lookup_func_t apply; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 56 | }; |
| 57 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 58 | |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 59 | static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data) { |
| 60 | return glyph_id == value; |
| 61 | } |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 62 | |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 63 | static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, char *data) { |
| 64 | const ClassDef &class_def = * (const ClassDef *) data; |
| 65 | return class_def.get_class (glyph_id) == value; |
| 66 | } |
| 67 | |
| 68 | static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, char *data) { |
| 69 | const OffsetTo<Coverage> &coverage = * (const OffsetTo<Coverage> *) &value; |
| 70 | return (data+coverage) (glyph_id) != NOT_COVERED; |
| 71 | } |
| 72 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 73 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 74 | static inline bool match_input (LOOKUP_ARGS_DEF, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 75 | unsigned int count, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 76 | const USHORT input[], /* Array of input values--start with second glyph */ |
| 77 | match_func_t match_func, |
| 78 | char *match_data, |
| 79 | unsigned int *context_length_out) |
| 80 | { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 81 | unsigned int i, j; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 82 | |
| 83 | /* XXX context_length should also be checked when skipping glyphs, right? |
| 84 | * What does context_length really mean, anyway? */ |
| 85 | |
| 86 | for (i = 1, j = buffer->in_pos + 1; i < count; i++, j++) { |
| 87 | while (!_hb_ot_layout_check_glyph_property (layout, IN_ITEM (j), lookup_flag, &property)) { |
| 88 | if (HB_UNLIKELY (j + count - i == buffer->in_length)) |
| 89 | return false; |
| 90 | j++; |
| 91 | } |
| 92 | |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame^] | 93 | 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] | 94 | return false; |
| 95 | } |
| 96 | |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame^] | 97 | *context_length_out = j - buffer->in_pos; |
| 98 | |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | static inline bool match_backtrack (LOOKUP_ARGS_DEF, |
| 103 | unsigned int count, |
| 104 | const USHORT backtrack[], |
| 105 | match_func_t match_func, |
| 106 | char *match_data) |
| 107 | { |
| 108 | unsigned int i, j; |
| 109 | |
| 110 | for (i = 0, j = buffer->out_pos - 1; i < count; i++, j--) { |
| 111 | while (!_hb_ot_layout_check_glyph_property (layout, OUT_ITEM (j), lookup_flag, &property)) { |
| 112 | if (HB_UNLIKELY (j + 1 == count - i)) |
| 113 | return false; |
| 114 | j--; |
| 115 | } |
| 116 | |
| 117 | if (HB_LIKELY (!match_func (OUT_GLYPH(j), backtrack[i], match_data))) |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | return true; |
| 122 | } |
| 123 | |
| 124 | static inline bool match_lookahead (LOOKUP_ARGS_DEF, |
| 125 | unsigned int count, |
| 126 | const USHORT lookahead[], |
| 127 | match_func_t match_func, |
| 128 | char *match_data, |
| 129 | unsigned int offset) |
| 130 | { |
| 131 | unsigned int i, j; |
| 132 | |
| 133 | for (i = 0, j = buffer->in_pos + offset; i < count; i++, j++) { |
| 134 | while (!_hb_ot_layout_check_glyph_property (layout, OUT_ITEM (j), lookup_flag, &property)) { |
| 135 | if (HB_UNLIKELY (j + count - i == buffer->in_length)) |
| 136 | return false; |
| 137 | j++; |
| 138 | } |
| 139 | |
| 140 | if (HB_LIKELY (!match_func (IN_GLYPH(j), lookahead[i], match_data))) |
| 141 | return false; |
| 142 | } |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 143 | |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | struct LookupRecord { |
| 149 | |
| 150 | USHORT sequenceIndex; /* Index into current glyph |
| 151 | * sequence--first glyph = 0 */ |
| 152 | USHORT lookupListIndex; /* Lookup to apply to that |
| 153 | * position--zero--based */ |
| 154 | }; |
| 155 | ASSERT_SIZE (LookupRecord, 4); |
| 156 | |
| 157 | static inline bool apply_lookup (LOOKUP_ARGS_DEF, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 158 | unsigned int count, /* Including the first glyph */ |
| 159 | unsigned int lookupCount, |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 160 | const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ |
| 161 | apply_lookup_func_t apply_func) |
| 162 | { |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 163 | unsigned int record_count = lookupCount; |
| 164 | const LookupRecord *record = lookupRecord; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 165 | |
| 166 | /* XXX We have to jump non-matching glyphs when applying too, right? */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 167 | /* XXX We don't support lookupRecord arrays that are not increasing: |
| 168 | * Should be easy for in_place ones at least. */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 169 | for (unsigned int i = 0; i < count;) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 170 | { |
Behdad Esfahbod | 19fc24f | 2009-05-17 09:45:32 -0400 | [diff] [blame] | 171 | if (record_count && i == record->sequenceIndex) |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 172 | { |
| 173 | unsigned int old_pos = buffer->in_pos; |
| 174 | |
| 175 | /* Apply a lookup */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 176 | bool done = apply_func (LOOKUP_ARGS, record->lookupListIndex); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 177 | |
| 178 | record++; |
| 179 | record_count--; |
| 180 | i += buffer->in_pos - old_pos; |
| 181 | |
| 182 | if (!done) |
| 183 | goto not_applied; |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | not_applied: |
| 188 | /* No lookup applied for this index */ |
| 189 | _hb_buffer_next_glyph (buffer); |
| 190 | i++; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return true; |
| 195 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 196 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 197 | |
| 198 | /* Contextual lookups */ |
| 199 | |
| 200 | struct ContextLookupContext { |
| 201 | ContextFuncs funcs; |
| 202 | char *match_data; |
| 203 | }; |
| 204 | |
| 205 | static inline bool context_lookup (LOOKUP_ARGS_DEF, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 206 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 207 | const USHORT input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 208 | unsigned int lookupCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 209 | const LookupRecord lookupRecord[], |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 210 | ContextLookupContext &context) |
| 211 | { |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 212 | /* First guess */ |
| 213 | if (HB_UNLIKELY (buffer->in_pos + inputCount > buffer->in_length || |
| 214 | context_length < inputCount)) |
| 215 | return false; |
| 216 | |
Behdad Esfahbod | f14c2b7 | 2009-05-18 02:36:18 -0400 | [diff] [blame] | 217 | return match_input (LOOKUP_ARGS, |
| 218 | inputCount, input, |
| 219 | context.funcs.match, context.match_data, |
| 220 | &context_length) && |
| 221 | apply_lookup (LOOKUP_ARGS, |
| 222 | inputCount, |
| 223 | lookupCount, lookupRecord, |
| 224 | context.funcs.apply); |
| 225 | } |
| 226 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 227 | struct Rule { |
| 228 | |
| 229 | friend struct RuleSet; |
| 230 | |
| 231 | private: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 232 | inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const { |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 233 | const LookupRecord *lookupRecord = (const LookupRecord *) |
| 234 | ((const char *) input + |
| 235 | sizeof (input[0]) * (inputCount ? inputCount - 1 : 0)); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 236 | return context_lookup (LOOKUP_ARGS, |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 237 | inputCount, |
| 238 | input, |
| 239 | lookupCount, |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 240 | lookupRecord, |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 241 | context); |
| 242 | } |
| 243 | |
| 244 | private: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 245 | USHORT inputCount; /* Total number of glyphs in input |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 246 | * glyph sequence--includes the first |
| 247 | * glyph */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 248 | USHORT lookupCount; /* Number of LookupRecords */ |
| 249 | USHORT input[]; /* Array of match inputs--start with |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 250 | * second glyph */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 251 | LookupRecord lookupRecordX[]; /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 252 | * design order */ |
| 253 | }; |
| 254 | ASSERT_SIZE (Rule, 4); |
| 255 | |
| 256 | struct RuleSet { |
| 257 | |
| 258 | inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const { |
| 259 | |
| 260 | unsigned int num_rules = rule.len; |
| 261 | for (unsigned int i = 0; i < num_rules; i++) { |
| 262 | if ((this+rule[i]).apply (LOOKUP_ARGS, context)) |
| 263 | return true; |
| 264 | } |
| 265 | |
| 266 | return false; |
| 267 | } |
| 268 | |
| 269 | private: |
| 270 | OffsetArrayOf<Rule> |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 271 | rule; /* Array of Rule tables |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 272 | * ordered by preference */ |
| 273 | }; |
| 274 | |
| 275 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 276 | struct ContextFormat1 { |
| 277 | |
| 278 | friend struct Context; |
| 279 | |
| 280 | private: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 281 | inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
| 282 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 283 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 284 | if (G_LIKELY (index == NOT_COVERED)) |
| 285 | return false; |
| 286 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 287 | const RuleSet &rule_set = this+ruleSet[index]; |
| 288 | struct ContextLookupContext context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 289 | {match_glyph, apply_func}, |
| 290 | NULL |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 291 | }; |
| 292 | return rule_set.apply (LOOKUP_ARGS, context); |
| 293 | } |
| 294 | |
| 295 | private: |
| 296 | USHORT format; /* Format identifier--format = 1 */ |
| 297 | OffsetTo<Coverage> |
| 298 | coverage; /* Offset to Coverage table--from |
| 299 | * beginning of table */ |
| 300 | OffsetArrayOf<RuleSet> |
| 301 | ruleSet; /* Array of RuleSet tables |
| 302 | * ordered by Coverage Index */ |
| 303 | }; |
| 304 | ASSERT_SIZE (ContextFormat1, 6); |
| 305 | |
| 306 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 307 | struct ContextFormat2 { |
| 308 | |
| 309 | friend struct Context; |
| 310 | |
| 311 | private: |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 312 | inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
| 313 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 314 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 315 | if (G_LIKELY (index == NOT_COVERED)) |
| 316 | return false; |
| 317 | |
| 318 | const ClassDef &class_def = this+classDef; |
| 319 | index = class_def (IN_CURGLYPH ()); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 320 | const RuleSet &rule_set = this+ruleSet[index]; |
| 321 | /* LONGTERMTODO: Old code fetches glyph classes at most once and caches |
| 322 | * them across subrule lookups. Not sure it's worth it. |
| 323 | */ |
| 324 | struct ContextLookupContext context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 325 | {match_class, apply_func}, |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 326 | (char *) &class_def |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 327 | }; |
| 328 | return rule_set.apply (LOOKUP_ARGS, context); |
| 329 | } |
| 330 | |
| 331 | private: |
| 332 | USHORT format; /* Format identifier--format = 2 */ |
| 333 | OffsetTo<Coverage> |
| 334 | coverage; /* Offset to Coverage table--from |
| 335 | * beginning of table */ |
| 336 | OffsetTo<ClassDef> |
| 337 | classDef; /* Offset to glyph ClassDef table--from |
| 338 | * beginning of table */ |
| 339 | OffsetArrayOf<RuleSet> |
| 340 | ruleSet; /* Array of RuleSet tables |
| 341 | * ordered by class */ |
| 342 | }; |
| 343 | ASSERT_SIZE (ContextFormat2, 8); |
| 344 | |
| 345 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 346 | struct ContextFormat3 { |
| 347 | |
| 348 | friend struct Context; |
| 349 | |
| 350 | private: |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 351 | inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 352 | |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 353 | unsigned int index = (this+coverage[0]) (IN_CURGLYPH ()); |
| 354 | if (G_LIKELY (index == NOT_COVERED)) |
| 355 | return false; |
| 356 | |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 357 | const LookupRecord *lookupRecord = (const LookupRecord *) |
| 358 | ((const char *) coverage + |
| 359 | sizeof (coverage[0]) * glyphCount); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 360 | struct ContextLookupContext context = { |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 361 | {match_coverage, apply_func}, |
| 362 | (char *) this |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 363 | }; |
| 364 | return context_lookup (LOOKUP_ARGS, |
| 365 | glyphCount, |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 366 | (const USHORT *) (coverage + 1), |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 367 | lookupCount, |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 368 | lookupRecord, |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 369 | context); |
| 370 | } |
| 371 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 372 | private: |
| 373 | USHORT format; /* Format identifier--format = 3 */ |
| 374 | USHORT glyphCount; /* Number of glyphs in the input glyph |
| 375 | * sequence */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 376 | USHORT lookupCount; /* Number of LookupRecords */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 377 | OffsetTo<Coverage> |
| 378 | coverage[]; /* Array of offsets to Coverage |
| 379 | * table in glyph sequence order */ |
| 380 | LookupRecord lookupRecordX[]; /* Array of LookupRecords--in |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 381 | * design order */ |
| 382 | }; |
| 383 | ASSERT_SIZE (ContextFormat3, 6); |
| 384 | |
| 385 | struct Context { |
| 386 | |
| 387 | protected: |
| 388 | bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
| 389 | switch (u.format) { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 390 | case 1: return u.format1->apply (LOOKUP_ARGS, apply_func); |
| 391 | case 2: return u.format2->apply (LOOKUP_ARGS, apply_func); |
| 392 | case 3: return u.format3->apply (LOOKUP_ARGS, apply_func); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 393 | default:return false; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | private: |
| 398 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 399 | USHORT format; /* Format identifier */ |
| 400 | ContextFormat1 format1[]; |
| 401 | ContextFormat2 format2[]; |
| 402 | ContextFormat3 format3[]; |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 403 | } u; |
| 404 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 405 | ASSERT_SIZE (Context, 2); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 406 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 407 | |
| 408 | /* Chaining Contextual lookups */ |
| 409 | |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 410 | struct ChainContextLookupContext { |
| 411 | ContextFuncs funcs; |
| 412 | char *match_data[3]; |
| 413 | }; |
| 414 | |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 415 | static inline bool chain_context_lookup (LOOKUP_ARGS_DEF, |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 416 | unsigned int backtrackCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 417 | const USHORT backtrack[], |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 418 | unsigned int inputCount, /* Including the first glyph (not matched) */ |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 419 | const USHORT input[], /* Array of input values--start with second glyph */ |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 420 | unsigned int lookaheadCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 421 | const USHORT lookahead[], |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 422 | unsigned int lookupCount, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 423 | const LookupRecord lookupRecord[], |
| 424 | ChainContextLookupContext &context) |
| 425 | { |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 426 | /* First guess */ |
| 427 | if (HB_UNLIKELY (buffer->out_pos < backtrackCount || |
| 428 | buffer->in_pos + inputCount + lookaheadCount > buffer->in_length)) |
| 429 | return false; |
| 430 | |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame^] | 431 | unsigned int offset; |
Behdad Esfahbod | e072c24 | 2009-05-18 03:47:31 -0400 | [diff] [blame] | 432 | return match_backtrack (LOOKUP_ARGS, |
| 433 | backtrackCount, backtrack, |
| 434 | context.funcs.match, context.match_data[0]) && |
| 435 | match_input (LOOKUP_ARGS, |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 436 | inputCount, input, |
| 437 | context.funcs.match, context.match_data[1], |
Behdad Esfahbod | d0ba055 | 2009-05-18 03:56:39 -0400 | [diff] [blame^] | 438 | &offset) && |
| 439 | (context_length -= offset, true) && |
| 440 | match_lookahead (LOOKUP_ARGS, |
| 441 | lookaheadCount, lookahead, |
| 442 | context.funcs.match, context.match_data[2], |
| 443 | offset) && |
| 444 | (context_length = offset, true) && |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 445 | apply_lookup (LOOKUP_ARGS, |
| 446 | inputCount, |
| 447 | lookupCount, lookupRecord, |
| 448 | context.funcs.apply); |
| 449 | } |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 450 | |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 451 | struct ChainRule { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 452 | |
| 453 | friend struct ChainRuleSet; |
| 454 | |
| 455 | private: |
| 456 | inline bool apply (LOOKUP_ARGS_DEF, ChainContextLookupContext &context) const { |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 457 | const HeadlessArrayOf<USHORT> &input = * (const HeadlessArrayOf<USHORT> *) |
| 458 | ((const char *) &backtrack + backtrack.get_size ()); |
| 459 | const ArrayOf<USHORT> &lookahead = * (const ArrayOf<USHORT> *) |
| 460 | ((const char *) &input + input.get_size ()); |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 461 | const ArrayOf<LookupRecord> &lookup = * (const ArrayOf<LookupRecord> *) |
| 462 | ((const char *) &lookahead + lookahead.get_size ()); |
| 463 | return chain_context_lookup (LOOKUP_ARGS, |
| 464 | backtrack.len, |
| 465 | backtrack.array, |
| 466 | input.len, |
| 467 | input.array + 1, |
| 468 | lookahead.len, |
| 469 | lookahead.array, |
| 470 | lookup.len, |
| 471 | lookup.array, |
| 472 | context); |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 473 | return false; |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 474 | } |
| 475 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 476 | |
| 477 | private: |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 478 | ArrayOf<USHORT> |
| 479 | backtrack; /* Array of backtracking values |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 480 | * (to be matched before the input |
| 481 | * sequence) */ |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 482 | HeadlessArrayOf<USHORT> |
| 483 | inputX; /* Array of input values (start with |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 484 | * second glyph) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 485 | ArrayOf<USHORT> |
| 486 | lookaheadX; /* Array of lookahead values's (to be |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 487 | * matched after the input sequence) */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 488 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 489 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 490 | * design order) */ |
| 491 | }; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 492 | ASSERT_SIZE (ChainRule, 8); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 493 | |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 494 | struct ChainRuleSet { |
| 495 | |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 496 | inline bool apply (LOOKUP_ARGS_DEF, ChainContextLookupContext &context) const { |
| 497 | |
| 498 | unsigned int num_rules = rule.len; |
| 499 | for (unsigned int i = 0; i < num_rules; i++) { |
| 500 | if ((this+rule[i]).apply (LOOKUP_ARGS, context)) |
| 501 | return true; |
| 502 | } |
| 503 | |
| 504 | return false; |
| 505 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 506 | |
| 507 | private: |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 508 | OffsetArrayOf<ChainRule> |
| 509 | rule; /* Array of ChainRule tables |
| 510 | * ordered by preference */ |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 511 | }; |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 512 | ASSERT_SIZE (ChainRuleSet, 2); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 513 | |
| 514 | struct ChainContextFormat1 { |
| 515 | |
| 516 | friend struct ChainContext; |
| 517 | |
| 518 | private: |
| 519 | inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 520 | |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 521 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
| 522 | if (G_LIKELY (index == NOT_COVERED)) |
| 523 | return false; |
| 524 | |
| 525 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
| 526 | struct ChainContextLookupContext context = { |
| 527 | {match_glyph, apply_func}, |
| 528 | {NULL, NULL, NULL} |
| 529 | }; |
| 530 | return rule_set.apply (LOOKUP_ARGS, context); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 531 | } |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 532 | private: |
| 533 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 48f16ed | 2009-05-17 22:11:30 -0400 | [diff] [blame] | 534 | OffsetTo<Coverage> |
| 535 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 536 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 537 | OffsetArrayOf<ChainRuleSet> |
| 538 | ruleSet; /* Array of ChainRuleSet tables |
| 539 | * ordered by Coverage Index */ |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 540 | }; |
| 541 | ASSERT_SIZE (ChainContextFormat1, 6); |
| 542 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 543 | struct ChainContextFormat2 { |
| 544 | |
| 545 | friend struct ChainContext; |
| 546 | |
| 547 | private: |
| 548 | inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
| 549 | |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 550 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
| 551 | if (G_LIKELY (index == NOT_COVERED)) |
| 552 | return false; |
| 553 | |
| 554 | const ClassDef &backtrack_class_def = this+backtrackClassDef; |
| 555 | const ClassDef &input_class_def = this+inputClassDef; |
| 556 | const ClassDef &lookahead_class_def = this+lookaheadClassDef; |
| 557 | |
| 558 | index = input_class_def (IN_CURGLYPH ()); |
| 559 | const ChainRuleSet &rule_set = this+ruleSet[index]; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 560 | /* LONGTERMTODO: Old code fetches glyph classes at most once and caches |
| 561 | * them across subrule lookups. Not sure it's worth it. |
| 562 | */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 563 | struct ChainContextLookupContext context = { |
| 564 | {match_class, apply_func}, |
| 565 | {(char *) &backtrack_class_def, |
| 566 | (char *) &input_class_def, |
| 567 | (char *) &lookahead_class_def} |
| 568 | }; |
| 569 | return rule_set.apply (LOOKUP_ARGS, context); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | private: |
| 573 | USHORT format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 574 | OffsetTo<Coverage> |
| 575 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 576 | * beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 577 | OffsetTo<ClassDef> |
| 578 | backtrackClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 579 | * containing backtrack sequence |
| 580 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 581 | OffsetTo<ClassDef> |
| 582 | inputClassDef; /* Offset to glyph ClassDef |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 583 | * table containing input sequence |
| 584 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 585 | OffsetTo<ClassDef> |
| 586 | lookaheadClassDef; /* Offset to glyph ClassDef table |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 587 | * containing lookahead sequence |
| 588 | * data--from beginning of table */ |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 589 | OffsetArrayOf<ChainRuleSet> |
| 590 | ruleSet; /* Array of ChainRuleSet tables |
| 591 | * ordered by class */ |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 592 | }; |
| 593 | ASSERT_SIZE (ChainContextFormat2, 12); |
| 594 | |
| 595 | struct ChainContextFormat3 { |
| 596 | |
| 597 | friend struct ChainContext; |
| 598 | |
| 599 | private: |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 600 | |
| 601 | inline bool apply_coverage (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 602 | } |
| 603 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 604 | inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
| 605 | |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 606 | const OffsetArrayOf<Coverage> &input = * (const OffsetArrayOf<Coverage> *) |
| 607 | ((const char *) &backtrack + backtrack.get_size ()); |
| 608 | |
| 609 | unsigned int index = (this+input[0]) (IN_CURGLYPH ()); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 610 | if (G_LIKELY (index == NOT_COVERED)) |
| 611 | return false; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 612 | |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 613 | const OffsetArrayOf<Coverage> &lookahead = * (const OffsetArrayOf<Coverage> *) |
| 614 | ((const char *) &input + input.get_size ()); |
| 615 | const ArrayOf<LookupRecord> &lookup = * (const ArrayOf<LookupRecord> *) |
| 616 | ((const char *) &lookahead + lookahead.get_size ()); |
| 617 | struct ChainContextLookupContext context = { |
| 618 | {match_coverage, apply_func}, |
| 619 | {(char *) this, (char *) this, (char *) this} |
| 620 | }; |
| 621 | return chain_context_lookup (LOOKUP_ARGS, |
| 622 | backtrack.len, |
| 623 | (USHORT *) backtrack.array, |
| 624 | input.len, |
| 625 | (USHORT *) input.array, |
| 626 | lookahead.len, |
| 627 | (USHORT *) lookahead.array, |
| 628 | lookup.len, |
| 629 | lookup.array, |
| 630 | context); |
| 631 | return false; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | private: |
| 635 | USHORT format; /* Format identifier--format = 3 */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 636 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 637 | backtrack; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 638 | * in backtracking sequence, in glyph |
| 639 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 640 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 641 | inputX ; /* Array of coverage |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 642 | * tables in input sequence, in glyph |
| 643 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 644 | OffsetArrayOf<Coverage> |
Behdad Esfahbod | 13ed440 | 2009-05-18 02:14:37 -0400 | [diff] [blame] | 645 | lookaheadX; /* Array of coverage tables |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 646 | * in lookahead sequence, in glyph |
| 647 | * sequence order */ |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 648 | ArrayOf<LookupRecord> |
Behdad Esfahbod | 02e1e5c | 2009-05-18 02:47:57 -0400 | [diff] [blame] | 649 | lookupX; /* Array of LookupRecords--in |
Behdad Esfahbod | dcb6b60 | 2009-05-18 01:49:57 -0400 | [diff] [blame] | 650 | * design order) */ |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 651 | }; |
| 652 | ASSERT_SIZE (ChainContextFormat3, 10); |
| 653 | |
| 654 | struct ChainContext { |
| 655 | |
| 656 | protected: |
| 657 | bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { |
| 658 | switch (u.format) { |
| 659 | case 1: return u.format1->apply (LOOKUP_ARGS, apply_func); |
| 660 | case 2: return u.format2->apply (LOOKUP_ARGS, apply_func); |
| 661 | case 3: return u.format3->apply (LOOKUP_ARGS, apply_func); |
| 662 | default:return false; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | private: |
| 667 | union { |
| 668 | USHORT format; /* Format identifier */ |
| 669 | ChainContextFormat1 format1[]; |
| 670 | ChainContextFormat2 format2[]; |
| 671 | ChainContextFormat3 format3[]; |
| 672 | } u; |
| 673 | }; |
| 674 | ASSERT_SIZE (ChainContext, 2); |
| 675 | |
| 676 | |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 677 | /* |
| 678 | * GSUB/GPOS Common |
| 679 | */ |
| 680 | |
| 681 | struct GSUBGPOS { |
| 682 | static const hb_tag_t GSUBTag = HB_TAG ('G','S','U','B'); |
| 683 | static const hb_tag_t GPOSTag = HB_TAG ('G','P','O','S'); |
| 684 | |
| 685 | STATIC_DEFINE_GET_FOR_DATA (GSUBGPOS); |
| 686 | /* XXX check version here? */ |
| 687 | |
| 688 | DEFINE_TAG_LIST_INTERFACE (Script, script ); /* get_script_count (), get_script (i), get_script_tag (i) */ |
| 689 | DEFINE_TAG_LIST_INTERFACE (Feature, feature); /* get_feature_count(), get_feature(i), get_feature_tag(i) */ |
| 690 | DEFINE_LIST_INTERFACE (Lookup, lookup ); /* get_lookup_count (), get_lookup (i) */ |
| 691 | |
| 692 | // LONGTERMTODO bsearch |
| 693 | DEFINE_TAG_FIND_INTERFACE (Script, script ); /* find_script_index (), get_script_by_tag (tag) */ |
| 694 | DEFINE_TAG_FIND_INTERFACE (Feature, feature); /* find_feature_index(), get_feature_by_tag(tag) */ |
| 695 | |
| 696 | private: |
| 697 | Fixed_Version version; /* Version of the GSUB/GPOS table--initially set |
| 698 | * to 0x00010000 */ |
| 699 | OffsetTo<ScriptList> |
| 700 | scriptList; /* ScriptList table */ |
| 701 | OffsetTo<FeatureList> |
| 702 | featureList; /* FeatureList table */ |
| 703 | OffsetTo<LookupList> |
| 704 | lookupList; /* LookupList table */ |
| 705 | }; |
| 706 | ASSERT_SIZE (GSUBGPOS, 10); |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 707 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 708 | |
Behdad Esfahbod | 66bf7ce | 2009-05-17 08:28:42 -0400 | [diff] [blame] | 709 | #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_H */ |