blob: 5912924a11ae244e9877ccf7e21847e11e19a751 [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 Esfahbod4d3aeb82012-01-16 16:43:26 -0500135 unsigned int i;
136 unsigned int j = c->buffer->idx;
137 unsigned int end = MIN (c->buffer->len, j + c->context_length);
138 if (unlikely (j + count > end))
Behdad Esfahbod7cff75b2009-05-18 04:09:05 -0400139 return false;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400140
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500141 for (i = 1; i < count; i++)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400142 {
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500143 do
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400144 {
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400145 j++;
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500146 if (unlikely (j >= end))
147 return false;
148 } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL));
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400149
Behdad Esfahbod7e7007a2010-05-14 22:02:37 -0400150 if (likely (!match_func (c->buffer->info[j].codepoint, input[i - 1], match_data)))
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400151 return false;
152 }
153
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500154 *context_length_out = j - c->buffer->idx + 1;
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400155
156 return true;
157}
158
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400159static inline bool match_backtrack (hb_apply_context_t *c,
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400160 unsigned int count,
161 const USHORT backtrack[],
162 match_func_t match_func,
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400163 const void *match_data)
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400164{
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500165 unsigned int j = c->buffer->backtrack_len ();
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400166
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500167 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400168 {
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500169 do
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400170 {
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500171 if (unlikely (!j))
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400172 return false;
173 j--;
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500174 } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->out_info[j], c->lookup_props, NULL));
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400175
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{
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500190 unsigned int i;
191 unsigned int j = c->buffer->idx + offset - 1;
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400192 unsigned int end = MIN (c->buffer->len, c->buffer->idx + c->context_length);
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400193
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500194 for (i = 0; i < count; i++)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400195 {
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500196 do
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400197 {
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400198 j++;
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500199 if (unlikely (j >= end))
200 return false;
201 } while (_hb_ot_layout_skip_mark (c->face, &c->buffer->info[j], c->lookup_props, NULL));
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400202
Behdad Esfahbod7e7007a2010-05-14 22:02:37 -0400203 if (likely (!match_func (c->buffer->info[j].codepoint, lookahead[i], match_data)))
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400204 return false;
205 }
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400206
207 return true;
208}
209
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400210
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400211
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400212struct LookupRecord
213{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400214 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400215 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400216 return c->check_struct (this);
Behdad Esfahbodcd3827e2009-08-04 02:09:34 -0400217 }
218
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400219 USHORT sequenceIndex; /* Index into current glyph
220 * sequence--first glyph = 0 */
221 USHORT lookupListIndex; /* Lookup to apply to that
222 * position--zero--based */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400223 public:
224 DEFINE_SIZE_STATIC (4);
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400225};
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400226
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400227
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400228
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400229static inline bool apply_lookup (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400230 unsigned int count, /* Including the first glyph */
231 unsigned int lookupCount,
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400232 const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
233 apply_lookup_func_t apply_func)
234{
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400235 unsigned int end = MIN (c->buffer->len, c->buffer->idx + c->context_length);
236 if (unlikely (count == 0 || c->buffer->idx + count > end))
Behdad Esfahbode73a0c22009-05-18 04:15:25 -0400237 return false;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400238
Behdad Esfahbod7cff75b2009-05-18 04:09:05 -0400239 /* TODO We don't support lookupRecord arrays that are not increasing:
240 * Should be easy for in_place ones at least. */
Behdad Esfahbod52e9a712009-09-21 13:58:56 -0400241
Behdad Esfahbod7eb87512010-12-13 14:13:35 -0500242 /* Note: If sublookup is reverse, it will underflow after the first loop
Behdad Esfahbod52e9a712009-09-21 13:58:56 -0400243 * and we jump out of it. Not entirely disastrous. So we don't check
244 * for reverse lookup here.
245 */
Behdad Esfahbodf9c0a2d2009-09-21 13:43:54 -0400246 for (unsigned int i = 0; i < count; /* NOP */)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400247 {
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400248 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 -0400249 {
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400250 if (unlikely (c->buffer->idx == end))
Behdad Esfahbode73a0c22009-05-18 04:15:25 -0400251 return true;
252 /* No lookup applied for this index */
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400253 c->buffer->next_glyph ();
Behdad Esfahbode73a0c22009-05-18 04:15:25 -0400254 }
255
Behdad Esfahbod47958de2009-05-18 04:17:47 -0400256 if (lookupCount && i == lookupRecord->sequenceIndex)
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400257 {
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400258 unsigned int old_pos = c->buffer->idx;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400259
260 /* Apply a lookup */
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400261 bool done = apply_func (c, lookupRecord->lookupListIndex);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400262
Behdad Esfahbod47958de2009-05-18 04:17:47 -0400263 lookupRecord++;
264 lookupCount--;
Behdad Esfahbodf9c0a2d2009-09-21 13:43:54 -0400265 /* Err, this is wrong if the lookup jumped over some glyphs */
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400266 i += c->buffer->idx - old_pos;
267 if (unlikely (c->buffer->idx == end))
Behdad Esfahbod2e8fb6c2009-05-18 04:37:37 -0400268 return true;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400269
270 if (!done)
271 goto not_applied;
272 }
273 else
274 {
275 not_applied:
276 /* No lookup applied for this index */
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400277 c->buffer->next_glyph ();
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400278 i++;
279 }
280 }
281
282 return true;
283}
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400284
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400285
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400286
287/* Contextual lookups */
288
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400289struct ContextLookupContext
290{
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400291 ContextFuncs funcs;
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400292 const void *match_data;
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400293};
294
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400295static inline bool context_lookup (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400296 unsigned int inputCount, /* Including the first glyph (not matched) */
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400297 const USHORT input[], /* Array of input values--start with second glyph */
Behdad Esfahbode072c242009-05-18 03:47:31 -0400298 unsigned int lookupCount,
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400299 const LookupRecord lookupRecord[],
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400300 ContextLookupContext &lookup_context)
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400301{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400302 hb_apply_context_t new_context = *c;
303 return match_input (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -0400304 inputCount, input,
305 lookup_context.funcs.match, lookup_context.match_data,
306 &new_context.context_length)
307 && apply_lookup (&new_context,
308 inputCount,
309 lookupCount, lookupRecord,
310 lookup_context.funcs.apply);
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400311}
312
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400313struct Rule
314{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400315 friend struct RuleSet;
316
317 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400318 inline bool apply (hb_apply_context_t *c, ContextLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400319 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400320 TRACE_APPLY ();
Behdad Esfahbode45d3f82010-05-06 19:33:31 -0400321 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0));
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400322 return context_lookup (c,
Behdad Esfahbod969afd72009-05-18 05:47:47 -0400323 inputCount, input,
Behdad Esfahbodfff9aa22010-05-05 00:32:21 -0400324 lookupCount, lookupRecord,
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400325 lookup_context);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400326 }
327
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400328 public:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400329 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400330 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400331 return inputCount.sanitize (c)
332 && lookupCount.sanitize (c)
333 && c->check_range (input,
Behdad Esfahbode45d3f82010-05-06 19:33:31 -0400334 input[0].static_size * inputCount
335 + lookupRecordX[0].static_size * lookupCount);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400336 }
337
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400338 private:
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400339 USHORT inputCount; /* Total number of glyphs in input
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400340 * glyph sequence--includes the first
341 * glyph */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400342 USHORT lookupCount; /* Number of LookupRecords */
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500343 USHORT input[VAR]; /* Array of match inputs--start with
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400344 * second glyph */
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500345 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400346 * design order */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400347 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400348 DEFINE_SIZE_ARRAY2 (4, input, lookupRecordX);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400349};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400350
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400351struct RuleSet
352{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400353 inline bool apply (hb_apply_context_t *c, ContextLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400354 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400355 TRACE_APPLY ();
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400356 unsigned int num_rules = rule.len;
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400357 for (unsigned int i = 0; i < num_rules; i++)
358 {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400359 if ((this+rule[i]).apply (c, lookup_context))
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400360 return true;
361 }
362
363 return false;
364 }
365
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400366 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400367 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400368 return rule.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400369 }
370
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400371 private:
372 OffsetArrayOf<Rule>
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400373 rule; /* Array of Rule tables
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400374 * ordered by preference */
Behdad Esfahboded074222010-05-10 18:08:46 -0400375 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400376 DEFINE_SIZE_ARRAY (2, rule);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400377};
378
379
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400380struct ContextFormat1
381{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400382 friend struct Context;
383
384 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400385 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400386 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400387 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400388 unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400389 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400390 return false;
391
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400392 const RuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400393 struct ContextLookupContext lookup_context = {
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400394 {match_glyph, apply_func},
395 NULL
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400396 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400397 return rule_set.apply (c, lookup_context);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400398 }
399
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400400 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400401 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400402 return coverage.sanitize (c, this)
403 && ruleSet.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400404 }
405
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400406 private:
407 USHORT format; /* Format identifier--format = 1 */
408 OffsetTo<Coverage>
409 coverage; /* Offset to Coverage table--from
410 * beginning of table */
411 OffsetArrayOf<RuleSet>
412 ruleSet; /* Array of RuleSet tables
413 * ordered by Coverage Index */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400414 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400415 DEFINE_SIZE_ARRAY (6, ruleSet);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400416};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400417
418
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400419struct ContextFormat2
420{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400421 friend struct Context;
422
423 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400424 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400425 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400426 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400427 unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400428 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400429 return false;
430
431 const ClassDef &class_def = this+classDef;
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400432 index = class_def (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400433 const RuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400434 struct ContextLookupContext lookup_context = {
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400435 {match_class, apply_func},
436 &class_def
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400437 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400438 return rule_set.apply (c, lookup_context);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400439 }
440
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400441 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400442 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400443 return coverage.sanitize (c, this)
444 && classDef.sanitize (c, this)
445 && ruleSet.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400446 }
447
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400448 private:
449 USHORT format; /* Format identifier--format = 2 */
450 OffsetTo<Coverage>
451 coverage; /* Offset to Coverage table--from
452 * beginning of table */
453 OffsetTo<ClassDef>
454 classDef; /* Offset to glyph ClassDef table--from
455 * beginning of table */
456 OffsetArrayOf<RuleSet>
457 ruleSet; /* Array of RuleSet tables
458 * ordered by class */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400459 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400460 DEFINE_SIZE_ARRAY (8, ruleSet);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400461};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400462
463
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400464struct ContextFormat3
465{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400466 friend struct Context;
467
468 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400469 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400470 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400471 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400472 unsigned int index = (this+coverage[0]) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400473 if (likely (index == NOT_COVERED))
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400474 return false;
475
Behdad Esfahbode45d3f82010-05-06 19:33:31 -0400476 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount);
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400477 struct ContextLookupContext lookup_context = {
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400478 {match_coverage, apply_func},
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400479 this
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400480 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400481 return context_lookup (c,
Behdad Esfahbod969afd72009-05-18 05:47:47 -0400482 glyphCount, (const USHORT *) (coverage + 1),
Behdad Esfahbodfff9aa22010-05-05 00:32:21 -0400483 lookupCount, lookupRecord,
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400484 lookup_context);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400485 }
486
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400487 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400488 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400489 if (!c->check_struct (this)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400490 unsigned int count = glyphCount;
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400491 if (!c->check_array (coverage, coverage[0].static_size, count)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400492 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400493 if (!coverage[i].sanitize (c, this)) return false;
Behdad Esfahbode45d3f82010-05-06 19:33:31 -0400494 LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * count);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400495 return c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400496 }
497
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400498 private:
499 USHORT format; /* Format identifier--format = 3 */
500 USHORT glyphCount; /* Number of glyphs in the input glyph
501 * sequence */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400502 USHORT lookupCount; /* Number of LookupRecords */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400503 OffsetTo<Coverage>
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500504 coverage[VAR]; /* Array of offsets to Coverage
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400505 * table in glyph sequence order */
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500506 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400507 * design order */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400508 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400509 DEFINE_SIZE_ARRAY2 (6, coverage, lookupRecordX);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400510};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400511
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400512struct Context
513{
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400514 protected:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400515 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400516 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400517 TRACE_APPLY ();
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400518 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400519 case 1: return u.format1.apply (c, apply_func);
520 case 2: return u.format2.apply (c, apply_func);
521 case 3: return u.format3.apply (c, apply_func);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400522 default:return false;
523 }
524 }
525
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400526 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400527 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400528 if (!u.format.sanitize (c)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400529 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400530 case 1: return u.format1.sanitize (c);
531 case 2: return u.format2.sanitize (c);
532 case 3: return u.format3.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400533 default:return true;
534 }
535 }
536
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400537 private:
538 union {
Behdad Esfahbodf8dc67b2009-05-17 19:47:54 -0400539 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400540 ContextFormat1 format1;
541 ContextFormat2 format2;
542 ContextFormat3 format3;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400543 } u;
544};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400545
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400546
547/* Chaining Contextual lookups */
548
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400549struct ChainContextLookupContext
550{
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400551 ContextFuncs funcs;
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400552 const void *match_data[3];
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400553};
554
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400555static inline bool chain_context_lookup (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400556 unsigned int backtrackCount,
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400557 const USHORT backtrack[],
Behdad Esfahbode072c242009-05-18 03:47:31 -0400558 unsigned int inputCount, /* Including the first glyph (not matched) */
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400559 const USHORT input[], /* Array of input values--start with second glyph */
Behdad Esfahbode072c242009-05-18 03:47:31 -0400560 unsigned int lookaheadCount,
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400561 const USHORT lookahead[],
Behdad Esfahbode072c242009-05-18 03:47:31 -0400562 unsigned int lookupCount,
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400563 const LookupRecord lookupRecord[],
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400564 ChainContextLookupContext &lookup_context)
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400565{
Behdad Esfahbode072c242009-05-18 03:47:31 -0400566 /* First guess */
Behdad Esfahbodcc1a8a92011-01-06 14:58:52 -0500567 if (unlikely (c->buffer->backtrack_len () < backtrackCount ||
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400568 c->buffer->idx + inputCount + lookaheadCount > c->buffer->len ||
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400569 inputCount + lookaheadCount > c->context_length))
Behdad Esfahbode072c242009-05-18 03:47:31 -0400570 return false;
571
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400572 hb_apply_context_t new_context = *c;
573 return match_backtrack (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -0400574 backtrackCount, backtrack,
575 lookup_context.funcs.match, lookup_context.match_data[0])
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400576 && match_input (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -0400577 inputCount, input,
578 lookup_context.funcs.match, lookup_context.match_data[1],
579 &new_context.context_length)
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400580 && match_lookahead (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -0400581 lookaheadCount, lookahead,
582 lookup_context.funcs.match, lookup_context.match_data[2],
583 new_context.context_length)
584 && apply_lookup (&new_context,
585 inputCount,
586 lookupCount, lookupRecord,
587 lookup_context.funcs.apply);
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400588}
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400589
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400590struct ChainRule
591{
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400592 friend struct ChainRuleSet;
593
594 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400595 inline bool apply (hb_apply_context_t *c, ChainContextLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400596 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400597 TRACE_APPLY ();
Behdad Esfahbode961c862010-04-21 15:56:11 -0400598 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
599 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
600 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400601 return chain_context_lookup (c,
Behdad Esfahbodb9615182010-05-10 18:20:54 -0400602 backtrack.len, backtrack.array,
603 input.len, input.array,
604 lookahead.len, lookahead.array,
605 lookup.len, lookup.array,
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400606 lookup_context);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400607 }
608
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400609 public:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400610 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400611 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400612 if (!backtrack.sanitize (c)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400613 HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400614 if (!input.sanitize (c)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400615 ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400616 if (!lookahead.sanitize (c)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400617 ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400618 return lookup.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400619 }
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400620
621 private:
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400622 ArrayOf<USHORT>
623 backtrack; /* Array of backtracking values
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400624 * (to be matched before the input
625 * sequence) */
Behdad Esfahbode8cbaaf2009-05-18 02:03:58 -0400626 HeadlessArrayOf<USHORT>
627 inputX; /* Array of input values (start with
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400628 * second glyph) */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400629 ArrayOf<USHORT>
630 lookaheadX; /* Array of lookahead values's (to be
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400631 * matched after the input sequence) */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400632 ArrayOf<LookupRecord>
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400633 lookupX; /* Array of LookupRecords--in
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400634 * design order) */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400635 public:
Behdad Esfahbodbea34c72010-05-10 17:28:16 -0400636 DEFINE_SIZE_MIN (8);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400637};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400638
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400639struct ChainRuleSet
640{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400641 inline bool apply (hb_apply_context_t *c, ChainContextLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400642 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400643 TRACE_APPLY ();
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400644 unsigned int num_rules = rule.len;
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400645 for (unsigned int i = 0; i < num_rules; i++)
646 {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400647 if ((this+rule[i]).apply (c, lookup_context))
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400648 return true;
649 }
650
651 return false;
652 }
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400653
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400654 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400655 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400656 return rule.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400657 }
658
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400659 private:
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400660 OffsetArrayOf<ChainRule>
661 rule; /* Array of ChainRule tables
662 * ordered by preference */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400663 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400664 DEFINE_SIZE_ARRAY (2, rule);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400665};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400666
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400667struct ChainContextFormat1
668{
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400669 friend struct ChainContext;
670
671 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400672 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400673 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400674 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400675 unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400676 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400677 return false;
678
679 const ChainRuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400680 struct ChainContextLookupContext lookup_context = {
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400681 {match_glyph, apply_func},
682 {NULL, NULL, NULL}
683 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400684 return rule_set.apply (c, lookup_context);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400685 }
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400686
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400687 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400688 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400689 return coverage.sanitize (c, this)
690 && ruleSet.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400691 }
692
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400693 private:
694 USHORT format; /* Format identifier--format = 1 */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400695 OffsetTo<Coverage>
696 coverage; /* Offset to Coverage table--from
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400697 * beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400698 OffsetArrayOf<ChainRuleSet>
699 ruleSet; /* Array of ChainRuleSet tables
700 * ordered by Coverage Index */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400701 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400702 DEFINE_SIZE_ARRAY (6, ruleSet);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400703};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400704
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400705struct ChainContextFormat2
706{
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400707 friend struct ChainContext;
708
709 private:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400710 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400711 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400712 TRACE_APPLY ();
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400713 unsigned int index = (this+coverage) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400714 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400715 return false;
716
717 const ClassDef &backtrack_class_def = this+backtrackClassDef;
718 const ClassDef &input_class_def = this+inputClassDef;
719 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
720
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400721 index = input_class_def (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400722 const ChainRuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400723 struct ChainContextLookupContext lookup_context = {
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400724 {match_class, apply_func},
725 {&backtrack_class_def,
726 &input_class_def,
727 &lookahead_class_def}
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400728 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400729 return rule_set.apply (c, lookup_context);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400730 }
731
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400732 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400733 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400734 return coverage.sanitize (c, this)
735 && backtrackClassDef.sanitize (c, this)
736 && inputClassDef.sanitize (c, this)
737 && lookaheadClassDef.sanitize (c, this)
738 && ruleSet.sanitize (c, this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400739 }
740
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400741 private:
742 USHORT format; /* Format identifier--format = 2 */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400743 OffsetTo<Coverage>
744 coverage; /* Offset to Coverage table--from
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400745 * beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400746 OffsetTo<ClassDef>
747 backtrackClassDef; /* Offset to glyph ClassDef table
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400748 * containing backtrack sequence
749 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400750 OffsetTo<ClassDef>
751 inputClassDef; /* Offset to glyph ClassDef
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400752 * table containing input sequence
753 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400754 OffsetTo<ClassDef>
755 lookaheadClassDef; /* Offset to glyph ClassDef table
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400756 * containing lookahead sequence
757 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400758 OffsetArrayOf<ChainRuleSet>
759 ruleSet; /* Array of ChainRuleSet tables
760 * ordered by class */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400761 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400762 DEFINE_SIZE_ARRAY (12, ruleSet);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400763};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400764
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400765struct ChainContextFormat3
766{
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400767 friend struct ChainContext;
768
769 private:
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400770
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400771 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400772 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400773 TRACE_APPLY ();
Behdad Esfahbode961c862010-04-21 15:56:11 -0400774 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400775
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400776 unsigned int index = (this+input[0]) (c->buffer->info[c->buffer->idx].codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400777 if (likely (index == NOT_COVERED))
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -0400778 return false;
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400779
Behdad Esfahbode961c862010-04-21 15:56:11 -0400780 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
781 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400782 struct ChainContextLookupContext lookup_context = {
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400783 {match_coverage, apply_func},
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400784 {this, this, this}
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400785 };
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400786 return chain_context_lookup (c,
Behdad Esfahbodb9615182010-05-10 18:20:54 -0400787 backtrack.len, (const USHORT *) backtrack.array,
788 input.len, (const USHORT *) input.array + 1,
789 lookahead.len, (const USHORT *) lookahead.array,
790 lookup.len, lookup.array,
Behdad Esfahbod7cda6fa2009-07-29 18:37:57 -0400791 lookup_context);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400792 }
793
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400794 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400795 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400796 if (!backtrack.sanitize (c, this)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400797 OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400798 if (!input.sanitize (c, this)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400799 OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400800 if (!lookahead.sanitize (c, this)) return false;
Behdad Esfahbode961c862010-04-21 15:56:11 -0400801 ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400802 return lookup.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400803 }
804
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400805 private:
806 USHORT format; /* Format identifier--format = 3 */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400807 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -0400808 backtrack; /* Array of coverage tables
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400809 * in backtracking sequence, in glyph
810 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400811 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -0400812 inputX ; /* Array of coverage
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400813 * tables in input sequence, in glyph
814 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400815 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -0400816 lookaheadX; /* Array of coverage tables
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400817 * in lookahead sequence, in glyph
818 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400819 ArrayOf<LookupRecord>
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -0400820 lookupX; /* Array of LookupRecords--in
Behdad Esfahboddcb6b602009-05-18 01:49:57 -0400821 * design order) */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400822 public:
Behdad Esfahbodbea34c72010-05-10 17:28:16 -0400823 DEFINE_SIZE_MIN (10);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400824};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400825
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400826struct ChainContext
827{
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400828 protected:
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400829 inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400830 {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400831 TRACE_APPLY ();
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400832 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400833 case 1: return u.format1.apply (c, apply_func);
834 case 2: return u.format2.apply (c, apply_func);
835 case 3: return u.format3.apply (c, apply_func);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400836 default:return false;
837 }
838 }
839
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400840 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400841 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400842 if (!u.format.sanitize (c)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400843 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400844 case 1: return u.format1.sanitize (c);
845 case 2: return u.format2.sanitize (c);
846 case 3: return u.format3.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400847 default:return true;
848 }
849 }
850
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400851 private:
852 union {
853 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400854 ChainContextFormat1 format1;
855 ChainContextFormat2 format2;
856 ChainContextFormat3 format3;
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400857 } u;
858};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -0400859
860
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400861struct ExtensionFormat1
862{
863 friend struct Extension;
864
Behdad Esfahbod18939482009-08-04 14:27:56 -0400865 protected:
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400866 inline unsigned int get_type (void) const { return extensionLookupType; }
Behdad Esfahbod3b2c2df2010-04-22 16:51:42 -0400867 inline unsigned int get_offset (void) const { return extensionOffset; }
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400868
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400869 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400870 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400871 return c->check_struct (this);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400872 }
873
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400874 private:
875 USHORT format; /* Format identifier. Set to 1. */
876 USHORT extensionLookupType; /* Lookup type of subtable referenced
877 * by ExtensionOffset (i.e. the
878 * extension subtable). */
Behdad Esfahbod81f2af42010-04-22 00:58:49 -0400879 ULONG extensionOffset; /* Offset to the extension subtable,
880 * of lookup type subtable. */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400881 public:
882 DEFINE_SIZE_STATIC (8);
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400883};
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400884
885struct Extension
886{
887 inline unsigned int get_type (void) const
888 {
889 switch (u.format) {
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400890 case 1: return u.format1.get_type ();
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400891 default:return 0;
892 }
893 }
Behdad Esfahbod3b2c2df2010-04-22 16:51:42 -0400894 inline unsigned int get_offset (void) const
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400895 {
896 switch (u.format) {
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400897 case 1: return u.format1.get_offset ();
Behdad Esfahbod3b2c2df2010-04-22 16:51:42 -0400898 default:return 0;
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400899 }
900 }
901
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400902 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400903 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400904 if (!u.format.sanitize (c)) return false;
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400905 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400906 case 1: return u.format1.sanitize (c);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -0400907 default:return true;
908 }
909 }
910
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400911 private:
912 union {
913 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400914 ExtensionFormat1 format1;
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400915 } u;
916};
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -0400917
918
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400919/*
920 * GSUB/GPOS Common
921 */
922
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400923struct GSUBGPOS
924{
Behdad Esfahboda328d662009-08-04 20:27:05 -0400925 static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB;
926 static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS;
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400927
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400928 inline unsigned int get_script_count (void) const
929 { return (this+scriptList).len; }
930 inline const Tag& get_script_tag (unsigned int i) const
931 { return (this+scriptList).get_tag (i); }
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500932 inline unsigned int get_script_tags (unsigned int start_offset,
933 unsigned int *script_count /* IN/OUT */,
934 hb_tag_t *script_tags /* OUT */) const
935 { return (this+scriptList).get_tags (start_offset, script_count, script_tags); }
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400936 inline const Script& get_script (unsigned int i) const
937 { return (this+scriptList)[i]; }
938 inline bool find_script_index (hb_tag_t tag, unsigned int *index) const
939 { return (this+scriptList).find_index (tag, index); }
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400940
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400941 inline unsigned int get_feature_count (void) const
942 { return (this+featureList).len; }
943 inline const Tag& get_feature_tag (unsigned int i) const
944 { return (this+featureList).get_tag (i); }
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500945 inline unsigned int get_feature_tags (unsigned int start_offset,
946 unsigned int *feature_count /* IN/OUT */,
947 hb_tag_t *feature_tags /* OUT */) const
948 { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); }
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400949 inline const Feature& get_feature (unsigned int i) const
950 { return (this+featureList)[i]; }
951 inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const
952 { return (this+featureList).find_index (tag, index); }
953
954 inline unsigned int get_lookup_count (void) const
955 { return (this+lookupList).len; }
956 inline const Lookup& get_lookup (unsigned int i) const
957 { return (this+lookupList)[i]; }
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400958
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400959 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400960 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400961 return version.sanitize (c) && likely (version.major == 1)
962 && scriptList.sanitize (c, this)
963 && featureList.sanitize (c, this)
964 && lookupList.sanitize (c, this);
Behdad Esfahbodcd3827e2009-08-04 02:09:34 -0400965 }
966
Behdad Esfahbod212aba62009-05-24 00:50:27 -0400967 protected:
Behdad Esfahbod87fcdcb2009-05-24 01:03:24 -0400968 FixedVersion version; /* Version of the GSUB/GPOS table--initially set
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400969 * to 0x00010000 */
970 OffsetTo<ScriptList>
971 scriptList; /* ScriptList table */
972 OffsetTo<FeatureList>
973 featureList; /* FeatureList table */
974 OffsetTo<LookupList>
975 lookupList; /* LookupList table */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400976 public:
977 DEFINE_SIZE_STATIC (10);
Behdad Esfahbodf45107f2009-05-17 20:13:02 -0400978};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400979
Behdad Esfahbod6f20f722009-05-17 20:28:01 -0400980
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400981
Behdad Esfahbod5f5b24f2009-08-02 20:03:12 -0400982#endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */