blob: 14979e16e36b806ec562cf8963376d27495a3321 [file] [log] [blame]
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2007,2008,2009,2010 Red Hat, Inc.
3 * Copyright © 2010 Google, Inc.
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04004 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04005 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04006 *
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
12 *
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 *
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 *
25 * Red Hat Author(s): Behdad Esfahbod
Behdad Esfahbod98370e82010-10-27 17:39:01 -040026 * Google Author(s): Behdad Esfahbod
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -040027 */
28
Behdad Esfahbod5f5b24f2009-08-02 20:03:12 -040029#ifndef HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
30#define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -040031
Behdad Esfahbod22da7fd2010-05-12 18:23:21 -040032#include "hb-buffer-private.hh"
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +020033#include "hb-ot-layout-gdef-table.hh"
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -040034
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040035
Behdad Esfahbodc2709112010-10-27 23:18:51 -040036/* buffer var allocations */
Behdad Esfahbod18c42852011-07-25 00:36:58 -040037#define lig_id() var2.u8[2] /* unique ligature id */
38#define lig_comp() var2.u8[3] /* component number in the ligature (0 = base) */
Behdad Esfahbodc2709112010-10-27 23:18:51 -040039
Behdad Esfahbod18c42852011-07-25 00:36:58 -040040static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) {
41 uint8_t lig_id = buffer->next_serial ();
Behdad Esfahbodd8787492011-07-25 00:36:01 -040042 if (unlikely (!lig_id)) lig_id = buffer->next_serial (); /* in case of overflow */
43 return lig_id;
44}
45
46
Behdad Esfahbodc2709112010-10-27 23:18:51 -040047
Behdad Esfahbod0535b502009-08-28 17:14:33 -040048#ifndef HB_DEBUG_APPLY
Behdad Esfahbod11e3ec42010-11-03 15:11:04 -040049#define HB_DEBUG_APPLY (HB_DEBUG+0)
Behdad Esfahbod0535b502009-08-28 17:14:33 -040050#endif
51
Behdad Esfahbodbc200452010-04-29 01:40:26 -040052#define TRACE_APPLY() \
Behdad Esfahbodcc06c242011-07-25 20:25:44 -040053 hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", this, NULL, HB_FUNC);
Behdad Esfahbod74e313c2010-04-28 15:15:09 -040054
Behdad Esfahbod0535b502009-08-28 17:14:33 -040055
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040056
Behdad Esfahbod1376fb72010-04-29 02:19:21 -040057struct hb_apply_context_t
58{
Behdad Esfahbod705e2152010-05-05 01:40:25 -040059 unsigned int debug_depth;
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -040060 hb_font_t *font;
61 hb_face_t *face;
Behdad Esfahbod94a23aa2010-05-05 01:13:09 -040062 hb_buffer_t *buffer;
Behdad Esfahbod744970a2011-05-16 18:15:37 -040063 hb_direction_t direction;
Behdad Esfahbodf7acd8d2010-05-20 17:26:35 +010064 hb_mask_t lookup_mask;
Behdad Esfahbod969c9702010-05-05 01:23:44 -040065 unsigned int context_length;
Behdad Esfahbod1376fb72010-04-29 02:19:21 -040066 unsigned int nesting_level_left;
Behdad Esfahbod8c69e652010-10-27 22:07:49 -040067 unsigned int lookup_props;
Behdad Esfahbod98370e82010-10-27 17:39:01 -040068 unsigned int property; /* propety of first glyph */
69
70
71 inline void replace_glyph (hb_codepoint_t glyph_index) const
72 {
73 clear_property ();
74 buffer->replace_glyph (glyph_index);
75 }
76 inline void replace_glyphs_be16 (unsigned int num_in,
77 unsigned int num_out,
78 const uint16_t *glyph_data_be) const
79 {
80 clear_property ();
81 buffer->replace_glyphs_be16 (num_in, num_out, glyph_data_be);
82 }
83
84 inline void guess_glyph_class (unsigned int klass)
85 {
Behdad Esfahbod300cb412010-11-17 12:57:23 -050086 /* XXX if ! has gdef */
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040087 buffer->info[buffer->idx].props_cache() = klass;
Behdad Esfahbod98370e82010-10-27 17:39:01 -040088 }
89
90 private:
91 inline void clear_property (void) const
92 {
Behdad Esfahbod300cb412010-11-17 12:57:23 -050093 /* XXX if has gdef */
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040094 buffer->info[buffer->idx].props_cache() = 0;
Behdad Esfahbod98370e82010-10-27 17:39:01 -040095 }
Behdad Esfahbod1376fb72010-04-29 02:19:21 -040096};
97
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -040098
Behdad Esfahbod94a23aa2010-05-05 01:13:09 -040099
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400100typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400101typedef bool (*apply_lookup_func_t) (hb_apply_context_t *c, unsigned int lookup_index);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400102
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400103struct ContextFuncs
104{
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400105 match_func_t match;
106 apply_lookup_func_t apply;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400107};
108
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400109
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400110static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, const void *data HB_UNUSED)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400111{
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400112 return glyph_id == value;
113}
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400114
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400115static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, const void *data)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400116{
Behdad Esfahbod2b5a59c2009-08-04 11:38:50 -0400117 const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400118 return class_def.get_class (glyph_id) == value;
119}
120
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400121static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, const void *data)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400122{
Behdad Esfahbod6b54c5d2009-05-18 18:30:25 -0400123 const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400124 return (data+coverage) (glyph_id) != NOT_COVERED;
125}
126
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400127
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400128static inline bool match_input (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400129 unsigned int count, /* Including the first glyph (not matched) */
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400130 const USHORT input[], /* Array of input values--start with second glyph */
131 match_func_t match_func,
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400132 const void *match_data,
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400133 unsigned int *context_length_out)
134{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400135 unsigned int i, j;
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400136 unsigned int end = MIN (c->buffer->len, c->buffer->idx + c->context_length);
137 if (unlikely (c->buffer->idx + count > end))
Behdad Esfahbod7cff75b2009-05-18 04:09:05 -0400138 return false;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400139
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400140 for (i = 1, j = c->buffer->idx + 1; i < count; i++, j++)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400141 {
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400142 while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL))
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400143 {
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400144 if (unlikely (j + count - i == end))
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400145 return false;
146 j++;
147 }
148
Behdad Esfahbod7e7007a2010-05-14 22:02:37 -0400149 if (likely (!match_func (c->buffer->info[j].codepoint, input[i - 1], match_data)))
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400150 return false;
151 }
152
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400153 *context_length_out = j - c->buffer->idx;
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400154
155 return true;
156}
157
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400158static inline bool match_backtrack (hb_apply_context_t *c,
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400159 unsigned int count,
160 const USHORT backtrack[],
161 match_func_t match_func,
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400162 const void *match_data)
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400163{
Behdad Esfahbodcc1a8a92011-01-06 14:58:52 -0500164 if (unlikely (c->buffer->backtrack_len () < count))
Behdad Esfahbod7cff75b2009-05-18 04:09:05 -0400165 return false;
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400166
Behdad Esfahbodcc1a8a92011-01-06 14:58:52 -0500167 for (unsigned int i = 0, j = c->buffer->backtrack_len () - 1; i < count; i++, j--)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400168 {
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400169 while (_hb_ot_layout_skip_mark (c->face, &c->buffer->out_info[j], c->lookup_props, NULL))
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400170 {
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400171 if (unlikely (j + 1 == count - i))
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400172 return false;
173 j--;
174 }
175
Behdad Esfahbod9d5e26d2010-05-14 22:03:11 -0400176 if (likely (!match_func (c->buffer->out_info[j].codepoint, backtrack[i], match_data)))
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400177 return false;
178 }
179
180 return true;
181}
182
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400183static inline bool match_lookahead (hb_apply_context_t *c,
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400184 unsigned int count,
185 const USHORT lookahead[],
186 match_func_t match_func,
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400187 const void *match_data,
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400188 unsigned int offset)
189{
190 unsigned int i, j;
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400191 unsigned int end = MIN (c->buffer->len, c->buffer->idx + c->context_length);
192 if (unlikely (c->buffer->idx + offset + count > end))
Behdad Esfahbod7cff75b2009-05-18 04:09:05 -0400193 return false;
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400194
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400195 for (i = 0, j = c->buffer->idx + offset; i < count; i++, j++)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400196 {
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400197 while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL))
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400198 {
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400199 if (unlikely (j + count - i == end))
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400200 return false;
201 j++;
202 }
203
Behdad Esfahbod7e7007a2010-05-14 22:02:37 -0400204 if (likely (!match_func (c->buffer->info[j].codepoint, lookahead[i], match_data)))
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400205 return false;
206 }
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400207
208 return true;
209}
210
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400211
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400212
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400213struct LookupRecord
214{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400215 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400216 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400217 return c->check_struct (this);
Behdad Esfahbodcd3827e2009-08-04 02:09:34 -0400218 }
219
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400220 USHORT sequenceIndex; /* Index into current glyph
221 * sequence--first glyph = 0 */
222 USHORT lookupListIndex; /* Lookup to apply to that
223 * position--zero--based */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400224 public:
225 DEFINE_SIZE_STATIC (4);
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400226};
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400227
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400228
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400229
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400230static inline bool apply_lookup (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400231 unsigned int count, /* Including the first glyph */
232 unsigned int lookupCount,
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400233 const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
234 apply_lookup_func_t apply_func)
235{
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400236 unsigned int end = MIN (c->buffer->len, c->buffer->idx + c->context_length);
237 if (unlikely (count == 0 || c->buffer->idx + count > end))
Behdad Esfahbode73a0c22009-05-18 04:15:25 -0400238 return false;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400239
Behdad Esfahbod7cff75b2009-05-18 04:09:05 -0400240 /* TODO We don't support lookupRecord arrays that are not increasing:
241 * Should be easy for in_place ones at least. */
Behdad Esfahbod52e9a712009-09-21 13:58:56 -0400242
Behdad Esfahbod7eb87512010-12-13 14:13:35 -0500243 /* Note: If sublookup is reverse, it will underflow after the first loop
Behdad Esfahbod52e9a712009-09-21 13:58:56 -0400244 * and we jump out of it. Not entirely disastrous. So we don't check
245 * for reverse lookup here.
246 */
Behdad Esfahbodf9c0a2d2009-09-21 13:43:54 -0400247 for (unsigned int i = 0; i < count; /* NOP */)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400248 {
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400249 while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[c->buffer->idx], c->lookup_props, NULL))
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400250 {
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400251 if (unlikely (c->buffer->idx == end))
Behdad Esfahbode73a0c22009-05-18 04:15:25 -0400252 return true;
253 /* No lookup applied for this index */
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400254 c->buffer->next_glyph ();
Behdad Esfahbode73a0c22009-05-18 04:15:25 -0400255 }
256
Behdad Esfahbod47958de2009-05-18 04:17:47 -0400257 if (lookupCount && i == lookupRecord->sequenceIndex)
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400258 {
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400259 unsigned int old_pos = c->buffer->idx;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400260
261 /* Apply a lookup */
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400262 bool done = apply_func (c, lookupRecord->lookupListIndex);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400263
Behdad Esfahbod47958de2009-05-18 04:17:47 -0400264 lookupRecord++;
265 lookupCount--;
Behdad Esfahbodf9c0a2d2009-09-21 13:43:54 -0400266 /* Err, this is wrong if the lookup jumped over some glyphs */
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400267 i += c->buffer->idx - old_pos;
268 if (unlikely (c->buffer->idx == end))
Behdad Esfahbod2e8fb6c2009-05-18 04:37:37 -0400269 return true;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400270
271 if (!done)
272 goto not_applied;
273 }
274 else
275 {
276 not_applied:
277 /* No lookup applied for this index */
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400278 c->buffer->next_glyph ();
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400279 i++;
280 }
281 }
282
283 return true;
284}
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400285
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400286
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400287
288/* Contextual lookups */
289
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400290struct ContextLookupContext
291{
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400292 ContextFuncs funcs;
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400293 const void *match_data;
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400294};
295
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400296static inline bool context_lookup (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400297 unsigned int inputCount, /* Including the first glyph (not matched) */
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400298 const USHORT input[], /* Array of input values--start with second glyph */
Behdad Esfahbode072c242009-05-18 03:47:31 -0400299 unsigned int lookupCount,
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400300 const LookupRecord lookupRecord[],
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400301 ContextLookupContext &lookup_context)
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400302{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400303 hb_apply_context_t new_context = *c;
304 return match_input (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -0400305 inputCount, input,
306 lookup_context.funcs.match, lookup_context.match_data,
307 &new_context.context_length)
308 && apply_lookup (&new_context,
309 inputCount,
310 lookupCount, lookupRecord,
311 lookup_context.funcs.apply);
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400312}
313
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400314struct Rule
315{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400316 friend struct RuleSet;
317
318 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400319 inline bool apply (hb_apply_context_t *c, ContextLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400320 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400321 TRACE_APPLY ();
Behdad Esfahbode45d3f82010-05-06 19:33:31 -0400322 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0));
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400323 return context_lookup (c,
Behdad Esfahbod969afd72009-05-18 05:47:47 -0400324 inputCount, input,
Behdad Esfahbodfff9aa22010-05-05 00:32:21 -0400325 lookupCount, lookupRecord,
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400326 lookup_context);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400327 }
328
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400329 public:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400330 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400331 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400332 return inputCount.sanitize (c)
333 && lookupCount.sanitize (c)
334 && c->check_range (input,
Behdad Esfahbode45d3f82010-05-06 19:33:31 -0400335 input[0].static_size * inputCount
336 + lookupRecordX[0].static_size * lookupCount);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400337 }
338
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400339 private:
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400340 USHORT inputCount; /* Total number of glyphs in input
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400341 * glyph sequence--includes the first
342 * glyph */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400343 USHORT lookupCount; /* Number of LookupRecords */
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500344 USHORT input[VAR]; /* Array of match inputs--start with
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400345 * second glyph */
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500346 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400347 * design order */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400348 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400349 DEFINE_SIZE_ARRAY2 (4, input, lookupRecordX);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400350};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400351
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400352struct RuleSet
353{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400354 inline bool apply (hb_apply_context_t *c, ContextLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400355 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400356 TRACE_APPLY ();
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400357 unsigned int num_rules = rule.len;
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400358 for (unsigned int i = 0; i < num_rules; i++)
359 {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400360 if ((this+rule[i]).apply (c, lookup_context))
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400361 return true;
362 }
363
364 return false;
365 }
366
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400367 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400368 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400369 return rule.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400370 }
371
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400372 private:
373 OffsetArrayOf<Rule>
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400374 rule; /* Array of Rule tables
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400375 * ordered by preference */
Behdad Esfahboded074222010-05-10 18:08:46 -0400376 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400377 DEFINE_SIZE_ARRAY (2, rule);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400378};
379
380
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400381struct ContextFormat1
382{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400383 friend struct Context;
384
385 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400386 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400387 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400388 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400389 unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400390 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400391 return false;
392
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400393 const RuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400394 struct ContextLookupContext lookup_context = {
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400395 {match_glyph, apply_func},
396 NULL
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400397 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400398 return rule_set.apply (c, lookup_context);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400399 }
400
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400401 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400402 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400403 return coverage.sanitize (c, this)
404 && ruleSet.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400405 }
406
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400407 private:
408 USHORT format; /* Format identifier--format = 1 */
409 OffsetTo<Coverage>
410 coverage; /* Offset to Coverage table--from
411 * beginning of table */
412 OffsetArrayOf<RuleSet>
413 ruleSet; /* Array of RuleSet tables
414 * ordered by Coverage Index */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400415 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400416 DEFINE_SIZE_ARRAY (6, ruleSet);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400417};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400418
419
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400420struct ContextFormat2
421{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400422 friend struct Context;
423
424 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400425 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400426 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400427 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400428 unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400429 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400430 return false;
431
432 const ClassDef &class_def = this+classDef;
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400433 index = class_def (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400434 const RuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400435 struct ContextLookupContext lookup_context = {
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400436 {match_class, apply_func},
437 &class_def
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400438 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400439 return rule_set.apply (c, lookup_context);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400440 }
441
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400442 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400443 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400444 return coverage.sanitize (c, this)
445 && classDef.sanitize (c, this)
446 && ruleSet.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400447 }
448
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400449 private:
450 USHORT format; /* Format identifier--format = 2 */
451 OffsetTo<Coverage>
452 coverage; /* Offset to Coverage table--from
453 * beginning of table */
454 OffsetTo<ClassDef>
455 classDef; /* Offset to glyph ClassDef table--from
456 * beginning of table */
457 OffsetArrayOf<RuleSet>
458 ruleSet; /* Array of RuleSet tables
459 * ordered by class */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400460 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400461 DEFINE_SIZE_ARRAY (8, ruleSet);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400462};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400463
464
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400465struct ContextFormat3
466{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400467 friend struct Context;
468
469 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400470 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400471 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400472 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400473 unsigned int index = (this+coverage[0]) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400474 if (likely (index == NOT_COVERED))
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400475 return false;
476
Behdad Esfahbode45d3f82010-05-06 19:33:31 -0400477 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount);
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400478 struct ContextLookupContext lookup_context = {
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400479 {match_coverage, apply_func},
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400480 this
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400481 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400482 return context_lookup (c,
Behdad Esfahbod969afd72009-05-18 05:47:47 -0400483 glyphCount, (const USHORT *) (coverage + 1),
Behdad Esfahbodfff9aa22010-05-05 00:32:21 -0400484 lookupCount, lookupRecord,
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400485 lookup_context);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400486 }
487
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400488 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400489 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400490 if (!c->check_struct (this)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400491 unsigned int count = glyphCount;
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400492 if (!c->check_array (coverage, coverage[0].static_size, count)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400493 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400494 if (!coverage[i].sanitize (c, this)) return false;
Behdad Esfahbode45d3f82010-05-06 19:33:31 -0400495 LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * count);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400496 return c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400497 }
498
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400499 private:
500 USHORT format; /* Format identifier--format = 3 */
501 USHORT glyphCount; /* Number of glyphs in the input glyph
502 * sequence */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400503 USHORT lookupCount; /* Number of LookupRecords */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400504 OffsetTo<Coverage>
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500505 coverage[VAR]; /* Array of offsets to Coverage
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400506 * table in glyph sequence order */
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500507 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400508 * design order */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400509 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400510 DEFINE_SIZE_ARRAY2 (6, coverage, lookupRecordX);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400511};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400512
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400513struct Context
514{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400515 protected:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400516 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400517 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400518 TRACE_APPLY ();
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400519 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400520 case 1: return u.format1.apply (c, apply_func);
521 case 2: return u.format2.apply (c, apply_func);
522 case 3: return u.format3.apply (c, apply_func);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400523 default:return false;
524 }
525 }
526
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400527 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400528 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400529 if (!u.format.sanitize (c)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400530 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400531 case 1: return u.format1.sanitize (c);
532 case 2: return u.format2.sanitize (c);
533 case 3: return u.format3.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400534 default:return true;
535 }
536 }
537
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400538 private:
539 union {
Behdad Esfahbodf8dc67b2009-05-17 19:47:54 -0400540 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400541 ContextFormat1 format1;
542 ContextFormat2 format2;
543 ContextFormat3 format3;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400544 } u;
545};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400546
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400547
548/* Chaining Contextual lookups */
549
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400550struct ChainContextLookupContext
551{
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400552 ContextFuncs funcs;
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400553 const void *match_data[3];
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400554};
555
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400556static inline bool chain_context_lookup (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400557 unsigned int backtrackCount,
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400558 const USHORT backtrack[],
Behdad Esfahbode072c242009-05-18 03:47:31 -0400559 unsigned int inputCount, /* Including the first glyph (not matched) */
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400560 const USHORT input[], /* Array of input values--start with second glyph */
Behdad Esfahbode072c242009-05-18 03:47:31 -0400561 unsigned int lookaheadCount,
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400562 const USHORT lookahead[],
Behdad Esfahbode072c242009-05-18 03:47:31 -0400563 unsigned int lookupCount,
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400564 const LookupRecord lookupRecord[],
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400565 ChainContextLookupContext &lookup_context)
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400566{
Behdad Esfahbode072c242009-05-18 03:47:31 -0400567 /* First guess */
Behdad Esfahbodcc1a8a92011-01-06 14:58:52 -0500568 if (unlikely (c->buffer->backtrack_len () < backtrackCount ||
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400569 c->buffer->idx + inputCount + lookaheadCount > c->buffer->len ||
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400570 inputCount + lookaheadCount > c->context_length))
Behdad Esfahbode072c242009-05-18 03:47:31 -0400571 return false;
572
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400573 hb_apply_context_t new_context = *c;
574 return match_backtrack (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -0400575 backtrackCount, backtrack,
576 lookup_context.funcs.match, lookup_context.match_data[0])
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400577 && match_input (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -0400578 inputCount, input,
579 lookup_context.funcs.match, lookup_context.match_data[1],
580 &new_context.context_length)
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400581 && match_lookahead (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -0400582 lookaheadCount, lookahead,
583 lookup_context.funcs.match, lookup_context.match_data[2],
584 new_context.context_length)
585 && apply_lookup (&new_context,
586 inputCount,
587 lookupCount, lookupRecord,
588 lookup_context.funcs.apply);
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400589}
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400590
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400591struct ChainRule
592{
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400593 friend struct ChainRuleSet;
594
595 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400596 inline bool apply (hb_apply_context_t *c, ChainContextLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400597 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400598 TRACE_APPLY ();
Behdad Esfahbode961c862010-04-21 15:56:11 -0400599 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
600 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
601 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400602 return chain_context_lookup (c,
Behdad Esfahbodb9615182010-05-10 18:20:54 -0400603 backtrack.len, backtrack.array,
604 input.len, input.array,
605 lookahead.len, lookahead.array,
606 lookup.len, lookup.array,
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400607 lookup_context);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400608 }
609
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400610 public:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400611 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400612 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400613 if (!backtrack.sanitize (c)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400614 HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400615 if (!input.sanitize (c)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400616 ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400617 if (!lookahead.sanitize (c)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400618 ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400619 return lookup.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400620 }
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400621
622 private:
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400623 ArrayOf<USHORT>
624 backtrack; /* Array of backtracking values
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400625 * (to be matched before the input
626 * sequence) */
Behdad Esfahbode8cbaaf2009-05-18 02:03:58 -0400627 HeadlessArrayOf<USHORT>
628 inputX; /* Array of input values (start with
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400629 * second glyph) */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400630 ArrayOf<USHORT>
631 lookaheadX; /* Array of lookahead values's (to be
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400632 * matched after the input sequence) */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400633 ArrayOf<LookupRecord>
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400634 lookupX; /* Array of LookupRecords--in
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400635 * design order) */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400636 public:
Behdad Esfahbodbea34c72010-05-10 17:28:16 -0400637 DEFINE_SIZE_MIN (8);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400638};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400639
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400640struct ChainRuleSet
641{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400642 inline bool apply (hb_apply_context_t *c, ChainContextLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400643 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400644 TRACE_APPLY ();
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400645 unsigned int num_rules = rule.len;
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400646 for (unsigned int i = 0; i < num_rules; i++)
647 {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400648 if ((this+rule[i]).apply (c, lookup_context))
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400649 return true;
650 }
651
652 return false;
653 }
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400654
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400655 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400656 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400657 return rule.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400658 }
659
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400660 private:
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400661 OffsetArrayOf<ChainRule>
662 rule; /* Array of ChainRule tables
663 * ordered by preference */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400664 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400665 DEFINE_SIZE_ARRAY (2, rule);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400666};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400667
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400668struct ChainContextFormat1
669{
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400670 friend struct ChainContext;
671
672 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400673 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400674 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400675 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400676 unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400677 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400678 return false;
679
680 const ChainRuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400681 struct ChainContextLookupContext lookup_context = {
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400682 {match_glyph, apply_func},
683 {NULL, NULL, NULL}
684 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400685 return rule_set.apply (c, lookup_context);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400686 }
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400687
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400688 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400689 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400690 return coverage.sanitize (c, this)
691 && ruleSet.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400692 }
693
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400694 private:
695 USHORT format; /* Format identifier--format = 1 */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400696 OffsetTo<Coverage>
697 coverage; /* Offset to Coverage table--from
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400698 * beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400699 OffsetArrayOf<ChainRuleSet>
700 ruleSet; /* Array of ChainRuleSet tables
701 * ordered by Coverage Index */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400702 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400703 DEFINE_SIZE_ARRAY (6, ruleSet);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400704};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400705
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400706struct ChainContextFormat2
707{
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400708 friend struct ChainContext;
709
710 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400711 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400712 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400713 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400714 unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400715 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400716 return false;
717
718 const ClassDef &backtrack_class_def = this+backtrackClassDef;
719 const ClassDef &input_class_def = this+inputClassDef;
720 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
721
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400722 index = input_class_def (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400723 const ChainRuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400724 struct ChainContextLookupContext lookup_context = {
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400725 {match_class, apply_func},
726 {&backtrack_class_def,
727 &input_class_def,
728 &lookahead_class_def}
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400729 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400730 return rule_set.apply (c, lookup_context);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400731 }
732
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400733 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400734 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400735 return coverage.sanitize (c, this)
736 && backtrackClassDef.sanitize (c, this)
737 && inputClassDef.sanitize (c, this)
738 && lookaheadClassDef.sanitize (c, this)
739 && ruleSet.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400740 }
741
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400742 private:
743 USHORT format; /* Format identifier--format = 2 */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400744 OffsetTo<Coverage>
745 coverage; /* Offset to Coverage table--from
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400746 * beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400747 OffsetTo<ClassDef>
748 backtrackClassDef; /* Offset to glyph ClassDef table
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400749 * containing backtrack sequence
750 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400751 OffsetTo<ClassDef>
752 inputClassDef; /* Offset to glyph ClassDef
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400753 * table containing input sequence
754 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400755 OffsetTo<ClassDef>
756 lookaheadClassDef; /* Offset to glyph ClassDef table
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400757 * containing lookahead sequence
758 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400759 OffsetArrayOf<ChainRuleSet>
760 ruleSet; /* Array of ChainRuleSet tables
761 * ordered by class */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400762 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400763 DEFINE_SIZE_ARRAY (12, ruleSet);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400764};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400765
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400766struct ChainContextFormat3
767{
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400768 friend struct ChainContext;
769
770 private:
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400771
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400772 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400773 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400774 TRACE_APPLY ();
Behdad Esfahbode961c862010-04-21 15:56:11 -0400775 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400776
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400777 unsigned int index = (this+input[0]) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400778 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400779 return false;
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400780
Behdad Esfahbode961c862010-04-21 15:56:11 -0400781 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
782 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400783 struct ChainContextLookupContext lookup_context = {
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400784 {match_coverage, apply_func},
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400785 {this, this, this}
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400786 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400787 return chain_context_lookup (c,
Behdad Esfahbodb9615182010-05-10 18:20:54 -0400788 backtrack.len, (const USHORT *) backtrack.array,
789 input.len, (const USHORT *) input.array + 1,
790 lookahead.len, (const USHORT *) lookahead.array,
791 lookup.len, lookup.array,
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400792 lookup_context);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400793 }
794
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400795 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400796 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400797 if (!backtrack.sanitize (c, this)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400798 OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400799 if (!input.sanitize (c, this)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400800 OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400801 if (!lookahead.sanitize (c, this)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400802 ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400803 return lookup.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400804 }
805
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400806 private:
807 USHORT format; /* Format identifier--format = 3 */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400808 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -0400809 backtrack; /* Array of coverage tables
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400810 * in backtracking sequence, in glyph
811 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400812 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -0400813 inputX ; /* Array of coverage
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400814 * tables in input sequence, in glyph
815 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400816 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -0400817 lookaheadX; /* Array of coverage tables
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400818 * in lookahead sequence, in glyph
819 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400820 ArrayOf<LookupRecord>
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400821 lookupX; /* Array of LookupRecords--in
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400822 * design order) */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400823 public:
Behdad Esfahbodbea34c72010-05-10 17:28:16 -0400824 DEFINE_SIZE_MIN (10);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400825};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400826
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400827struct ChainContext
828{
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400829 protected:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400830 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400831 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400832 TRACE_APPLY ();
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400833 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400834 case 1: return u.format1.apply (c, apply_func);
835 case 2: return u.format2.apply (c, apply_func);
836 case 3: return u.format3.apply (c, apply_func);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400837 default:return false;
838 }
839 }
840
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400841 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400842 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400843 if (!u.format.sanitize (c)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400844 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400845 case 1: return u.format1.sanitize (c);
846 case 2: return u.format2.sanitize (c);
847 case 3: return u.format3.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400848 default:return true;
849 }
850 }
851
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400852 private:
853 union {
854 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400855 ChainContextFormat1 format1;
856 ChainContextFormat2 format2;
857 ChainContextFormat3 format3;
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400858 } u;
859};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400860
861
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400862struct ExtensionFormat1
863{
864 friend struct Extension;
865
Behdad Esfahbod18939482009-08-04 14:27:56 -0400866 protected:
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400867 inline unsigned int get_type (void) const { return extensionLookupType; }
Behdad Esfahbod3b2c2df2010-04-22 16:51:42 -0400868 inline unsigned int get_offset (void) const { return extensionOffset; }
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400869
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400870 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400871 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400872 return c->check_struct (this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400873 }
874
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400875 private:
876 USHORT format; /* Format identifier. Set to 1. */
877 USHORT extensionLookupType; /* Lookup type of subtable referenced
878 * by ExtensionOffset (i.e. the
879 * extension subtable). */
Behdad Esfahbod81f2af42010-04-22 00:58:49 -0400880 ULONG extensionOffset; /* Offset to the extension subtable,
881 * of lookup type subtable. */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400882 public:
883 DEFINE_SIZE_STATIC (8);
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400884};
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400885
886struct Extension
887{
888 inline unsigned int get_type (void) const
889 {
890 switch (u.format) {
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400891 case 1: return u.format1.get_type ();
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400892 default:return 0;
893 }
894 }
Behdad Esfahbod3b2c2df2010-04-22 16:51:42 -0400895 inline unsigned int get_offset (void) const
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400896 {
897 switch (u.format) {
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400898 case 1: return u.format1.get_offset ();
Behdad Esfahbod3b2c2df2010-04-22 16:51:42 -0400899 default:return 0;
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400900 }
901 }
902
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400903 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400904 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400905 if (!u.format.sanitize (c)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400906 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400907 case 1: return u.format1.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400908 default:return true;
909 }
910 }
911
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400912 private:
913 union {
914 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400915 ExtensionFormat1 format1;
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400916 } u;
917};
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400918
919
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400920/*
921 * GSUB/GPOS Common
922 */
923
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400924struct GSUBGPOS
925{
Behdad Esfahboda328d662009-08-04 20:27:05 -0400926 static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB;
927 static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS;
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400928
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400929 inline unsigned int get_script_count (void) const
930 { return (this+scriptList).len; }
931 inline const Tag& get_script_tag (unsigned int i) const
932 { return (this+scriptList).get_tag (i); }
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500933 inline unsigned int get_script_tags (unsigned int start_offset,
934 unsigned int *script_count /* IN/OUT */,
935 hb_tag_t *script_tags /* OUT */) const
936 { return (this+scriptList).get_tags (start_offset, script_count, script_tags); }
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400937 inline const Script& get_script (unsigned int i) const
938 { return (this+scriptList)[i]; }
939 inline bool find_script_index (hb_tag_t tag, unsigned int *index) const
940 { return (this+scriptList).find_index (tag, index); }
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400941
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400942 inline unsigned int get_feature_count (void) const
943 { return (this+featureList).len; }
944 inline const Tag& get_feature_tag (unsigned int i) const
945 { return (this+featureList).get_tag (i); }
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500946 inline unsigned int get_feature_tags (unsigned int start_offset,
947 unsigned int *feature_count /* IN/OUT */,
948 hb_tag_t *feature_tags /* OUT */) const
949 { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); }
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400950 inline const Feature& get_feature (unsigned int i) const
951 { return (this+featureList)[i]; }
952 inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const
953 { return (this+featureList).find_index (tag, index); }
954
955 inline unsigned int get_lookup_count (void) const
956 { return (this+lookupList).len; }
957 inline const Lookup& get_lookup (unsigned int i) const
958 { return (this+lookupList)[i]; }
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400959
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400960 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400961 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400962 return version.sanitize (c) && likely (version.major == 1)
963 && scriptList.sanitize (c, this)
964 && featureList.sanitize (c, this)
965 && lookupList.sanitize (c, this);
Behdad Esfahbodcd3827e2009-08-04 02:09:34 -0400966 }
967
Behdad Esfahbod212aba62009-05-24 00:50:27 -0400968 protected:
Behdad Esfahbod87fcdcb2009-05-24 01:03:24 -0400969 FixedVersion version; /* Version of the GSUB/GPOS table--initially set
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400970 * to 0x00010000 */
971 OffsetTo<ScriptList>
972 scriptList; /* ScriptList table */
973 OffsetTo<FeatureList>
974 featureList; /* FeatureList table */
975 OffsetTo<LookupList>
976 lookupList; /* LookupList table */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400977 public:
978 DEFINE_SIZE_STATIC (10);
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400979};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400980
Behdad Esfahbod6f20f722009-05-17 20:28:01 -0400981
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400982
Behdad Esfahbod5f5b24f2009-08-02 20:03:12 -0400983#endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */