blob: 99c4c8385ebc79adf8671e55ecf5167f338820a7 [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.
Behdad Esfahbod5b93e8d2012-04-23 22:26:13 -04003 * Copyright © 2010,2012 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 Esfahbod1336ecd2012-08-01 21:46:36 -040034#include "hb-set-private.hh"
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040035
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -040036
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -040037namespace OT {
38
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040039
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040040#ifndef HB_DEBUG_CLOSURE
41#define HB_DEBUG_CLOSURE (HB_DEBUG+0)
42#endif
43
Behdad Esfahbodbe218c62012-11-23 15:32:14 -050044#define TRACE_CLOSURE(this) \
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -050045 hb_auto_trace_t<HB_DEBUG_CLOSURE, hb_void_t> trace \
Behdad Esfahbod2c53bd32012-11-23 17:29:05 -050046 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
Behdad Esfahbod902cc8a2012-11-23 15:06:59 -050047 "");
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040048
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040049struct hb_closure_context_t
50{
Behdad Esfahboda1733db2012-11-23 16:40:04 -050051 inline const char *get_name (void) { return "CLOSURE"; }
52 static const unsigned int max_debug_depth = HB_DEBUG_CLOSURE;
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -050053 typedef hb_void_t return_t;
Behdad Esfahbod44fc2372012-11-21 23:33:13 -050054 typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index);
Behdad Esfahbod50b8dc72015-02-17 18:14:17 +030055 template <typename T, typename F>
56 inline bool may_dispatch (const T *obj, const F *format) { return true; }
Behdad Esfahbod44fc2372012-11-21 23:33:13 -050057 template <typename T>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -050058 inline return_t dispatch (const T &obj) { obj.closure (this); return HB_VOID; }
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -050059 static return_t default_return_value (void) { return HB_VOID; }
Behdad Esfahbod7b912c12013-01-04 01:25:27 -060060 bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
Behdad Esfahbod44fc2372012-11-21 23:33:13 -050061 return_t recurse (unsigned int lookup_index)
62 {
Behdad Esfahbod9b346772012-11-23 17:55:40 -050063 if (unlikely (nesting_level_left == 0 || !recurse_func))
Behdad Esfahbod2005fa52012-11-22 14:38:10 -050064 return default_return_value ();
Behdad Esfahbod44fc2372012-11-21 23:33:13 -050065
66 nesting_level_left--;
67 recurse_func (this, lookup_index);
68 nesting_level_left++;
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -050069 return HB_VOID;
Behdad Esfahbod44fc2372012-11-21 23:33:13 -050070 }
71
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040072 hb_face_t *face;
Behdad Esfahbod6a9be5b2012-04-23 22:23:17 -040073 hb_set_t *glyphs;
Behdad Esfahbod44fc2372012-11-21 23:33:13 -050074 recurse_func_t recurse_func;
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040075 unsigned int nesting_level_left;
76 unsigned int debug_depth;
77
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040078 hb_closure_context_t (hb_face_t *face_,
Behdad Esfahbod6a9be5b2012-04-23 22:23:17 -040079 hb_set_t *glyphs_,
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040080 unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) :
Behdad Esfahbode72b3602012-07-19 14:35:23 -040081 face (face_),
82 glyphs (glyphs_),
Behdad Esfahbod9b346772012-11-23 17:55:40 -050083 recurse_func (NULL),
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040084 nesting_level_left (nesting_level_left_),
85 debug_depth (0) {}
Behdad Esfahbod9b346772012-11-23 17:55:40 -050086
87 void set_recurse_func (recurse_func_t func) { recurse_func = func; }
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040088};
89
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -040090
91
Behdad Esfahbod472f2292012-08-07 22:25:24 -040092#ifndef HB_DEBUG_WOULD_APPLY
93#define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0)
94#endif
95
Behdad Esfahbodbe218c62012-11-23 15:32:14 -050096#define TRACE_WOULD_APPLY(this) \
Behdad Esfahbod902cc8a2012-11-23 15:06:59 -050097 hb_auto_trace_t<HB_DEBUG_WOULD_APPLY, bool> trace \
Behdad Esfahbod2c53bd32012-11-23 17:29:05 -050098 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
Behdad Esfahbod902cc8a2012-11-23 15:06:59 -050099 "%d glyphs", c->len);
Behdad Esfahbode72b3602012-07-19 14:35:23 -0400100
101struct hb_would_apply_context_t
102{
Behdad Esfahboda1733db2012-11-23 16:40:04 -0500103 inline const char *get_name (void) { return "WOULD_APPLY"; }
104 static const unsigned int max_debug_depth = HB_DEBUG_WOULD_APPLY;
Behdad Esfahbod1d67ef92012-11-22 16:47:53 -0500105 typedef bool return_t;
Behdad Esfahbod50b8dc72015-02-17 18:14:17 +0300106 template <typename T, typename F>
107 inline bool may_dispatch (const T *obj, const F *format) { return true; }
Behdad Esfahbod1d67ef92012-11-22 16:47:53 -0500108 template <typename T>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -0500109 inline return_t dispatch (const T &obj) { return obj.would_apply (this); }
Behdad Esfahbod1d67ef92012-11-22 16:47:53 -0500110 static return_t default_return_value (void) { return false; }
Behdad Esfahbod7b912c12013-01-04 01:25:27 -0600111 bool stop_sublookup_iteration (return_t r) const { return r; }
Behdad Esfahbod1d67ef92012-11-22 16:47:53 -0500112
Behdad Esfahbode72b3602012-07-19 14:35:23 -0400113 hb_face_t *face;
Behdad Esfahbod472f2292012-08-07 22:25:24 -0400114 const hb_codepoint_t *glyphs;
Behdad Esfahbode72b3602012-07-19 14:35:23 -0400115 unsigned int len;
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -0400116 bool zero_context;
Behdad Esfahbode72b3602012-07-19 14:35:23 -0400117 unsigned int debug_depth;
118
119 hb_would_apply_context_t (hb_face_t *face_,
Behdad Esfahbod472f2292012-08-07 22:25:24 -0400120 const hb_codepoint_t *glyphs_,
121 unsigned int len_,
Behdad Esfahbod2bd9fe32012-09-04 15:15:19 -0400122 bool zero_context_) :
Behdad Esfahbode72b3602012-07-19 14:35:23 -0400123 face (face_),
Behdad Esfahbod472f2292012-08-07 22:25:24 -0400124 glyphs (glyphs_),
125 len (len_),
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -0400126 zero_context (zero_context_),
Behdad Esfahboda1733db2012-11-23 16:40:04 -0500127 debug_depth (0) {}
Behdad Esfahbode72b3602012-07-19 14:35:23 -0400128};
129
130
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -0800131
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -0800132#ifndef HB_DEBUG_COLLECT_GLYPHS
133#define HB_DEBUG_COLLECT_GLYPHS (HB_DEBUG+0)
134#endif
135
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500136#define TRACE_COLLECT_GLYPHS(this) \
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -0500137 hb_auto_trace_t<HB_DEBUG_COLLECT_GLYPHS, hb_void_t> trace \
Behdad Esfahbod2c53bd32012-11-23 17:29:05 -0500138 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
Behdad Esfahbod902cc8a2012-11-23 15:06:59 -0500139 "");
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -0800140
141struct hb_collect_glyphs_context_t
142{
Behdad Esfahboda1733db2012-11-23 16:40:04 -0500143 inline const char *get_name (void) { return "COLLECT_GLYPHS"; }
144 static const unsigned int max_debug_depth = HB_DEBUG_COLLECT_GLYPHS;
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -0500145 typedef hb_void_t return_t;
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500146 typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index);
Behdad Esfahbod50b8dc72015-02-17 18:14:17 +0300147 template <typename T, typename F>
148 inline bool may_dispatch (const T *obj, const F *format) { return true; }
Behdad Esfahbod1d67ef92012-11-22 16:47:53 -0500149 template <typename T>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -0500150 inline return_t dispatch (const T &obj) { obj.collect_glyphs (this); return HB_VOID; }
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -0500151 static return_t default_return_value (void) { return HB_VOID; }
Behdad Esfahbod7b912c12013-01-04 01:25:27 -0600152 bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
Behdad Esfahbod1d67ef92012-11-22 16:47:53 -0500153 return_t recurse (unsigned int lookup_index)
154 {
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500155 if (unlikely (nesting_level_left == 0 || !recurse_func))
156 return default_return_value ();
157
Behdad Esfahbod1bcfa062012-12-04 16:58:09 -0500158 /* Note that GPOS sets recurse_func to NULL already, so it doesn't get
159 * past the previous check. For GSUB, we only want to collect the output
Behdad Esfahbod76ea5632013-05-04 16:01:20 -0400160 * glyphs in the recursion. If output is not requested, we can go home now.
161 *
162 * Note further, that the above is not exactly correct. A recursed lookup
163 * is allowed to match input that is not matched in the context, but that's
164 * not how most fonts are built. It's possible to relax that and recurse
165 * with all sets here if it proves to be an issue.
166 */
Behdad Esfahbod4a350d02012-12-04 17:13:09 -0500167
168 if (output == hb_set_get_empty ())
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -0500169 return HB_VOID;
Behdad Esfahbod4a350d02012-12-04 17:13:09 -0500170
Behdad Esfahbodfde3e4a2014-10-29 11:23:08 -0700171 /* Return if new lookup was recursed to before. */
172 if (recursed_lookups.has (lookup_index))
173 return HB_VOID;
174
Behdad Esfahbod4a350d02012-12-04 17:13:09 -0500175 hb_set_t *old_before = before;
176 hb_set_t *old_input = input;
177 hb_set_t *old_after = after;
178 before = input = after = hb_set_get_empty ();
Behdad Esfahbod1bcfa062012-12-04 16:58:09 -0500179
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500180 nesting_level_left--;
Behdad Esfahbod4a350d02012-12-04 17:13:09 -0500181 recurse_func (this, lookup_index);
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500182 nesting_level_left++;
Behdad Esfahbod4a350d02012-12-04 17:13:09 -0500183
184 before = old_before;
185 input = old_input;
186 after = old_after;
187
Behdad Esfahbodfde3e4a2014-10-29 11:23:08 -0700188 recursed_lookups.add (lookup_index);
189
Behdad Esfahbod130bb3f2012-12-05 16:49:47 -0500190 return HB_VOID;
Behdad Esfahbod1d67ef92012-11-22 16:47:53 -0500191 }
192
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -0800193 hb_face_t *face;
Behdad Esfahbod83035932012-12-04 17:08:41 -0500194 hb_set_t *before;
195 hb_set_t *input;
196 hb_set_t *after;
197 hb_set_t *output;
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500198 recurse_func_t recurse_func;
Behdad Esfahbodfde3e4a2014-10-29 11:23:08 -0700199 hb_set_t recursed_lookups;
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500200 unsigned int nesting_level_left;
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -0800201 unsigned int debug_depth;
202
203 hb_collect_glyphs_context_t (hb_face_t *face_,
204 hb_set_t *glyphs_before, /* OUT. May be NULL */
205 hb_set_t *glyphs_input, /* OUT. May be NULL */
206 hb_set_t *glyphs_after, /* OUT. May be NULL */
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500207 hb_set_t *glyphs_output, /* OUT. May be NULL */
208 unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) :
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -0800209 face (face_),
Behdad Esfahbod83035932012-12-04 17:08:41 -0500210 before (glyphs_before ? glyphs_before : hb_set_get_empty ()),
211 input (glyphs_input ? glyphs_input : hb_set_get_empty ()),
212 after (glyphs_after ? glyphs_after : hb_set_get_empty ()),
213 output (glyphs_output ? glyphs_output : hb_set_get_empty ()),
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500214 recurse_func (NULL),
Behdad Esfahbodfde3e4a2014-10-29 11:23:08 -0700215 recursed_lookups (),
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500216 nesting_level_left (nesting_level_left_),
Behdad Esfahbodfde3e4a2014-10-29 11:23:08 -0700217 debug_depth (0)
218 {
219 recursed_lookups.init ();
220 }
221 ~hb_collect_glyphs_context_t (void)
222 {
223 recursed_lookups.fini ();
224 }
Behdad Esfahbod26514d52012-11-23 18:13:48 -0500225
226 void set_recurse_func (recurse_func_t func) { recurse_func = func; }
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -0800227};
228
229
230
Behdad Esfahbod295ef1d2014-12-12 20:43:18 -0800231#ifndef HB_DEBUG_GET_COVERAGE
232#define HB_DEBUG_GET_COVERAGE (HB_DEBUG+0)
233#endif
234
Behdad Esfahbod8e36ccf2015-02-17 19:15:34 +0300235template <typename set_t>
236struct hb_add_coverage_context_t
Behdad Esfahbod2005fa52012-11-22 14:38:10 -0500237{
Behdad Esfahboda1733db2012-11-23 16:40:04 -0500238 inline const char *get_name (void) { return "GET_COVERAGE"; }
Behdad Esfahbod295ef1d2014-12-12 20:43:18 -0800239 static const unsigned int max_debug_depth = HB_DEBUG_GET_COVERAGE;
Behdad Esfahbod2005fa52012-11-22 14:38:10 -0500240 typedef const Coverage &return_t;
Behdad Esfahbod50b8dc72015-02-17 18:14:17 +0300241 template <typename T, typename F>
242 inline bool may_dispatch (const T *obj, const F *format) { return true; }
Behdad Esfahbod2005fa52012-11-22 14:38:10 -0500243 template <typename T>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -0500244 inline return_t dispatch (const T &obj) { return obj.get_coverage (); }
Behdad Esfahboda1733db2012-11-23 16:40:04 -0500245 static return_t default_return_value (void) { return Null(Coverage); }
Behdad Esfahbod8e36ccf2015-02-17 19:15:34 +0300246 bool stop_sublookup_iteration (return_t r) const
247 {
248 r.add_coverage (set);
249 return false;
250 }
Behdad Esfahbod1d67ef92012-11-22 16:47:53 -0500251
Behdad Esfahbod8e36ccf2015-02-17 19:15:34 +0300252 hb_add_coverage_context_t (set_t *set_) :
253 set (set_),
Behdad Esfahboda1733db2012-11-23 16:40:04 -0500254 debug_depth (0) {}
255
Behdad Esfahbod8e36ccf2015-02-17 19:15:34 +0300256 set_t *set;
Behdad Esfahboda1733db2012-11-23 16:40:04 -0500257 unsigned int debug_depth;
Behdad Esfahbod2005fa52012-11-22 14:38:10 -0500258};
259
260
261
Behdad Esfahbod0535b502009-08-28 17:14:33 -0400262#ifndef HB_DEBUG_APPLY
Behdad Esfahbod11e3ec42010-11-03 15:11:04 -0400263#define HB_DEBUG_APPLY (HB_DEBUG+0)
Behdad Esfahbod0535b502009-08-28 17:14:33 -0400264#endif
265
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500266#define TRACE_APPLY(this) \
Behdad Esfahbod902cc8a2012-11-23 15:06:59 -0500267 hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace \
Behdad Esfahbod2c53bd32012-11-23 17:29:05 -0500268 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
Behdad Esfahbod902cc8a2012-11-23 15:06:59 -0500269 "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
Behdad Esfahbod0535b502009-08-28 17:14:33 -0400270
Behdad Esfahbod1376fb72010-04-29 02:19:21 -0400271struct hb_apply_context_t
272{
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500273 struct matcher_t
274 {
275 inline matcher_t (void) :
276 lookup_props (0),
Behdad Esfahbodcfc507c2013-02-14 10:40:12 -0500277 ignore_zwnj (false),
278 ignore_zwj (false),
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500279 mask (-1),
280#define arg1(arg) (arg) /* Remove the macro to see why it's needed! */
281 syllable arg1(0),
282#undef arg1
283 match_func (NULL),
284 match_data (NULL) {};
285
286 typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data);
287
288 inline void set_ignore_zwnj (bool ignore_zwnj_) { ignore_zwnj = ignore_zwnj_; }
Behdad Esfahbod0b454792013-02-14 10:46:52 -0500289 inline void set_ignore_zwj (bool ignore_zwj_) { ignore_zwj = ignore_zwj_; }
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500290 inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; }
291 inline void set_mask (hb_mask_t mask_) { mask = mask_; }
292 inline void set_syllable (uint8_t syllable_) { syllable = syllable_; }
293 inline void set_match_func (match_func_t match_func_,
294 const void *match_data_)
295 { match_func = match_func_; match_data = match_data_; }
296
Behdad Esfahbod2b2a6e82013-02-21 15:07:03 -0500297 enum may_match_t {
298 MATCH_NO,
299 MATCH_YES,
300 MATCH_MAYBE
301 };
302
303 inline may_match_t may_match (const hb_glyph_info_t &info,
304 const USHORT *glyph_data) const
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500305 {
Behdad Esfahbod2b2a6e82013-02-21 15:07:03 -0500306 if (!(info.mask & mask) ||
307 (syllable && syllable != info.syllable ()))
308 return MATCH_NO;
309
310 if (match_func)
311 return match_func (info.codepoint, *glyph_data, match_data) ? MATCH_YES : MATCH_NO;
312
313 return MATCH_MAYBE;
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500314 }
315
316 enum may_skip_t {
317 SKIP_NO,
318 SKIP_YES,
319 SKIP_MAYBE
320 };
321
322 inline may_skip_t
323 may_skip (const hb_apply_context_t *c,
324 const hb_glyph_info_t &info) const
325 {
Behdad Esfahbodb98c5db2014-07-16 13:44:01 -0400326 if (!c->check_glyph_property (&info, lookup_props))
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500327 return SKIP_YES;
328
Behdad Esfahbod0b454792013-02-14 10:46:52 -0500329 if (unlikely (_hb_glyph_info_is_default_ignorable (&info) &&
330 (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info)) &&
Behdad Esfahbod4ba796b2015-07-22 17:41:31 +0100331 (ignore_zwj || !_hb_glyph_info_is_zwj (&info))))
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500332 return SKIP_MAYBE;
333
334 return SKIP_NO;
335 }
336
337 protected:
338 unsigned int lookup_props;
339 bool ignore_zwnj;
Behdad Esfahbod0b454792013-02-14 10:46:52 -0500340 bool ignore_zwj;
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500341 hb_mask_t mask;
342 uint8_t syllable;
343 match_func_t match_func;
344 const void *match_data;
345 };
346
Behdad Esfahbod69626692015-01-29 13:08:41 +0100347 struct skipping_iterator_t
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500348 {
Behdad Esfahbod514564f2015-01-29 13:48:48 +0100349 inline void init (hb_apply_context_t *c_, bool context_match = false)
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500350 {
Behdad Esfahbod514564f2015-01-29 13:48:48 +0100351 c = c_;
352 match_glyph_data = NULL,
353 matcher.set_match_func (NULL, NULL);
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500354 matcher.set_lookup_props (c->lookup_props);
Behdad Esfahboda8cf7b42013-03-19 05:53:26 -0400355 /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */
356 matcher.set_ignore_zwnj (context_match || c->table_index == 1);
357 /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */
358 matcher.set_ignore_zwj (context_match || c->table_index == 1 || c->auto_zwj);
Behdad Esfahbod514564f2015-01-29 13:48:48 +0100359 matcher.set_mask (context_match ? -1 : c->lookup_mask);
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500360 }
Behdad Esfahbod514564f2015-01-29 13:48:48 +0100361 inline void set_lookup_props (unsigned int lookup_props)
362 {
363 matcher.set_lookup_props (lookup_props);
364 }
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500365 inline void set_match_func (matcher_t::match_func_t match_func,
366 const void *match_data,
367 const USHORT glyph_data[])
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -0500368 {
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500369 matcher.set_match_func (match_func, match_data);
370 match_glyph_data = glyph_data;
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -0500371 }
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500372
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100373 inline void reset (unsigned int start_index_,
374 unsigned int num_items_)
375 {
376 idx = start_index_;
377 num_items = num_items_;
378 end = c->buffer->len;
379 matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0);
380 }
381
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500382 inline void reject (void) { num_items++; match_glyph_data--; }
Behdad Esfahbod69626692015-01-29 13:08:41 +0100383
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -0500384 inline bool next (void)
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500385 {
Behdad Esfahbod506ffeb2012-01-18 16:07:53 -0500386 assert (num_items > 0);
Behdad Esfahbod37d13ac2015-01-29 11:38:01 +0100387 while (idx + num_items < end)
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500388 {
Behdad Esfahboda4a48fe2012-01-17 18:08:41 -0500389 idx++;
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500390 const hb_glyph_info_t &info = c->buffer->info[idx];
391
Behdad Esfahbodff93ac82013-02-21 14:51:40 -0500392 matcher_t::may_skip_t skip = matcher.may_skip (c, info);
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500393 if (unlikely (skip == matcher_t::SKIP_YES))
394 continue;
395
Behdad Esfahbod2b2a6e82013-02-21 15:07:03 -0500396 matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data);
Behdad Esfahbod722e8b82013-02-21 15:37:51 -0500397 if (match == matcher_t::MATCH_YES ||
398 (match == matcher_t::MATCH_MAYBE &&
399 skip == matcher_t::SKIP_NO))
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500400 {
401 num_items--;
402 match_glyph_data++;
403 return true;
404 }
405
406 if (skip == matcher_t::SKIP_NO)
Behdad Esfahbod722e8b82013-02-21 15:37:51 -0500407 return false;
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500408 }
409 return false;
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500410 }
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -0500411 inline bool prev (void)
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500412 {
Behdad Esfahbod506ffeb2012-01-18 16:07:53 -0500413 assert (num_items > 0);
Behdad Esfahbod37d13ac2015-01-29 11:38:01 +0100414 while (idx >= num_items)
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500415 {
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500416 idx--;
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500417 const hb_glyph_info_t &info = c->buffer->out_info[idx];
418
Behdad Esfahbodff93ac82013-02-21 14:51:40 -0500419 matcher_t::may_skip_t skip = matcher.may_skip (c, info);
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500420 if (unlikely (skip == matcher_t::SKIP_YES))
421 continue;
422
Behdad Esfahbod2b2a6e82013-02-21 15:07:03 -0500423 matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data);
Behdad Esfahbod722e8b82013-02-21 15:37:51 -0500424 if (match == matcher_t::MATCH_YES ||
425 (match == matcher_t::MATCH_MAYBE &&
426 skip == matcher_t::SKIP_NO))
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500427 {
428 num_items--;
429 match_glyph_data++;
430 return true;
431 }
432
433 if (skip == matcher_t::SKIP_NO)
Behdad Esfahbod722e8b82013-02-21 15:37:51 -0500434 return false;
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500435 }
436 return false;
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500437 }
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500438
439 unsigned int idx;
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400440 protected:
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500441 hb_apply_context_t *c;
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500442 matcher_t matcher;
443 const USHORT *match_glyph_data;
444
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500445 unsigned int num_items;
Behdad Esfahbod69626692015-01-29 13:08:41 +0100446 unsigned int end;
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500447 };
448
Behdad Esfahbod2cecc382015-01-29 13:32:05 +0100449
450 inline const char *get_name (void) { return "APPLY"; }
451 static const unsigned int max_debug_depth = HB_DEBUG_APPLY;
452 typedef bool return_t;
453 typedef return_t (*recurse_func_t) (hb_apply_context_t *c, unsigned int lookup_index);
Behdad Esfahbod50b8dc72015-02-17 18:14:17 +0300454 template <typename T, typename F>
455 inline bool may_dispatch (const T *obj, const F *format) { return true; }
Behdad Esfahbod2cecc382015-01-29 13:32:05 +0100456 template <typename T>
457 inline return_t dispatch (const T &obj) { return obj.apply (this); }
458 static return_t default_return_value (void) { return false; }
459 bool stop_sublookup_iteration (return_t r) const { return r; }
460 return_t recurse (unsigned int lookup_index)
461 {
462 if (unlikely (nesting_level_left == 0 || !recurse_func))
463 return default_return_value ();
464
465 nesting_level_left--;
466 bool ret = recurse_func (this, lookup_index);
467 nesting_level_left++;
468 return ret;
469 }
470
471 unsigned int table_index; /* GSUB/GPOS */
472 hb_font_t *font;
473 hb_face_t *face;
474 hb_buffer_t *buffer;
475 hb_direction_t direction;
476 hb_mask_t lookup_mask;
477 bool auto_zwj;
478 recurse_func_t recurse_func;
479 unsigned int nesting_level_left;
480 unsigned int lookup_props;
481 const GDEF &gdef;
482 bool has_glyph_classes;
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100483 skipping_iterator_t iter_input, iter_context;
Behdad Esfahbod2cecc382015-01-29 13:32:05 +0100484 unsigned int debug_depth;
485
486
487 hb_apply_context_t (unsigned int table_index_,
488 hb_font_t *font_,
489 hb_buffer_t *buffer_) :
490 table_index (table_index_),
491 font (font_), face (font->face), buffer (buffer_),
492 direction (buffer_->props.direction),
493 lookup_mask (1),
494 auto_zwj (true),
495 recurse_func (NULL),
496 nesting_level_left (MAX_NESTING_LEVEL),
497 lookup_props (0),
498 gdef (*hb_ot_layout_from_face (face)->gdef),
499 has_glyph_classes (gdef.has_glyph_classes ()),
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100500 iter_input (),
501 iter_context (),
Behdad Esfahbod2cecc382015-01-29 13:32:05 +0100502 debug_depth (0) {}
503
504 inline void set_lookup_mask (hb_mask_t mask) { lookup_mask = mask; }
505 inline void set_auto_zwj (bool auto_zwj_) { auto_zwj = auto_zwj_; }
506 inline void set_recurse_func (recurse_func_t func) { recurse_func = func; }
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100507 inline void set_lookup (const Lookup &l) { set_lookup_props (l.get_props ()); }
508 inline void set_lookup_props (unsigned int lookup_props_)
509 {
510 lookup_props = lookup_props_;
511 iter_input.init (this, false);
512 iter_context.init (this, true);
513 }
Behdad Esfahbod2cecc382015-01-29 13:32:05 +0100514
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400515 inline bool
516 match_properties_mark (hb_codepoint_t glyph,
517 unsigned int glyph_props,
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700518 unsigned int match_props) const
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400519 {
520 /* If using mark filtering sets, the high short of
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700521 * match_props has the set index.
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400522 */
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700523 if (match_props & LookupFlag::UseMarkFilteringSet)
524 return gdef.mark_set_covers (match_props >> 16, glyph);
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400525
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700526 /* The second byte of match_props has the meaning
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400527 * "ignore marks of attachment type different than
528 * the attachment type specified."
529 */
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700530 if (match_props & LookupFlag::MarkAttachmentType)
531 return (match_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType);
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400532
533 return true;
534 }
535
536 inline bool
Behdad Esfahbodb98c5db2014-07-16 13:44:01 -0400537 check_glyph_property (const hb_glyph_info_t *info,
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700538 unsigned int match_props) const
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400539 {
Behdad Esfahbodb98c5db2014-07-16 13:44:01 -0400540 hb_codepoint_t glyph = info->codepoint;
541 unsigned int glyph_props = _hb_glyph_info_get_glyph_props (info);
542
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400543 /* Not covered, if, for example, glyph class is ligature and
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700544 * match_props includes LookupFlags::IgnoreLigatures
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400545 */
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700546 if (glyph_props & match_props & LookupFlag::IgnoreFlags)
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400547 return false;
548
Behdad Esfahbod5a08ecf2012-11-16 13:34:29 -0800549 if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK))
Behdad Esfahbodb931e0b2015-04-08 14:39:00 -0700550 return match_properties_mark (glyph, glyph_props, match_props);
Behdad Esfahbod03f67bc2012-07-30 19:47:53 -0400551
552 return true;
553 }
554
Behdad Esfahboda0161742013-10-18 00:06:30 +0200555 inline void _set_glyph_props (hb_codepoint_t glyph_index,
Behdad Esfahbod71b4c992013-10-28 00:20:59 +0100556 unsigned int class_guess = 0,
Behdad Esfahbod832a6f92014-06-04 16:57:42 -0400557 bool ligature = false,
558 bool component = false) const
Behdad Esfahbod60da7632012-07-16 16:13:32 -0400559 {
Behdad Esfahbod09675a82013-10-18 01:05:58 +0200560 unsigned int add_in = _hb_glyph_info_get_glyph_props (&buffer->cur()) &
561 HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE;
562 add_in |= HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED;
563 if (ligature)
Behdad Esfahbod832a6f92014-06-04 16:57:42 -0400564 {
Behdad Esfahbod09675a82013-10-18 01:05:58 +0200565 add_in |= HB_OT_LAYOUT_GLYPH_PROPS_LIGATED;
Behdad Esfahbod832a6f92014-06-04 16:57:42 -0400566 /* In the only place that the MULTIPLIED bit is used, Uniscribe
567 * seems to only care about the "last" transformation between
568 * Ligature and Multiple substitions. Ie. if you ligate, expand,
569 * and ligate again, it forgives the multiplication and acts as
570 * if only ligation happened. As such, clear MULTIPLIED bit.
571 */
572 add_in &= ~HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED;
573 }
574 if (component)
575 add_in |= HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED;
Behdad Esfahbod2fca1422012-07-30 18:46:41 -0400576 if (likely (has_glyph_classes))
Behdad Esfahbod05ad6b52013-10-18 00:45:59 +0200577 _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | gdef.get_glyph_props (glyph_index));
Behdad Esfahbod05bd1b62012-07-30 19:30:01 -0400578 else if (class_guess)
Behdad Esfahbod09675a82013-10-18 01:05:58 +0200579 _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | class_guess);
Behdad Esfahbod60da7632012-07-16 16:13:32 -0400580 }
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500581
Behdad Esfahboda0161742013-10-18 00:06:30 +0200582 inline void replace_glyph (hb_codepoint_t glyph_index) const
Behdad Esfahbod3ec77d62012-06-08 21:44:06 -0400583 {
Behdad Esfahboda0161742013-10-18 00:06:30 +0200584 _set_glyph_props (glyph_index);
Behdad Esfahbod98370e82010-10-27 17:39:01 -0400585 buffer->replace_glyph (glyph_index);
586 }
Behdad Esfahboda0161742013-10-18 00:06:30 +0200587 inline void replace_glyph_inplace (hb_codepoint_t glyph_index) const
Behdad Esfahbod7fbbf862012-07-30 18:36:42 -0400588 {
Behdad Esfahboda0161742013-10-18 00:06:30 +0200589 _set_glyph_props (glyph_index);
Behdad Esfahbod7fbbf862012-07-30 18:36:42 -0400590 buffer->cur().codepoint = glyph_index;
591 }
Behdad Esfahboda0161742013-10-18 00:06:30 +0200592 inline void replace_glyph_with_ligature (hb_codepoint_t glyph_index,
593 unsigned int class_guess) const
594 {
Behdad Esfahbod09675a82013-10-18 01:05:58 +0200595 _set_glyph_props (glyph_index, class_guess, true);
Behdad Esfahboda0161742013-10-18 00:06:30 +0200596 buffer->replace_glyph (glyph_index);
597 }
Behdad Esfahbod832a6f92014-06-04 16:57:42 -0400598 inline void output_glyph_for_component (hb_codepoint_t glyph_index,
599 unsigned int class_guess) const
Behdad Esfahboda0161742013-10-18 00:06:30 +0200600 {
Behdad Esfahbod832a6f92014-06-04 16:57:42 -0400601 _set_glyph_props (glyph_index, class_guess, false, true);
Behdad Esfahboda0161742013-10-18 00:06:30 +0200602 buffer->output_glyph (glyph_index);
603 }
Behdad Esfahbod1376fb72010-04-29 02:19:21 -0400604};
605
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400606
Behdad Esfahbod94a23aa2010-05-05 01:13:09 -0400607
Behdad Esfahbod6a9be5b2012-04-23 22:23:17 -0400608typedef bool (*intersects_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data);
Behdad Esfahbodd0a52332012-11-23 18:54:59 -0500609typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data);
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400610typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400611
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400612struct ContextClosureFuncs
613{
614 intersects_func_t intersects;
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400615};
Behdad Esfahbodd0a52332012-11-23 18:54:59 -0500616struct ContextCollectGlyphsFuncs
617{
618 collect_glyphs_func_t collect;
619};
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400620struct ContextApplyFuncs
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400621{
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400622 match_func_t match;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400623};
624
Behdad Esfahbodd0a52332012-11-23 18:54:59 -0500625
Behdad Esfahbod6a9be5b2012-04-23 22:23:17 -0400626static inline bool intersects_glyph (hb_set_t *glyphs, const USHORT &value, const void *data HB_UNUSED)
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400627{
628 return glyphs->has (value);
629}
Behdad Esfahbod6a9be5b2012-04-23 22:23:17 -0400630static inline bool intersects_class (hb_set_t *glyphs, const USHORT &value, const void *data)
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400631{
632 const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
633 return class_def.intersects_class (glyphs, value);
634}
Behdad Esfahbod6a9be5b2012-04-23 22:23:17 -0400635static inline bool intersects_coverage (hb_set_t *glyphs, const USHORT &value, const void *data)
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400636{
637 const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
638 return (data+coverage).intersects (glyphs);
639}
640
641static inline bool intersects_array (hb_closure_context_t *c,
642 unsigned int count,
643 const USHORT values[],
644 intersects_func_t intersects_func,
645 const void *intersects_data)
646{
647 for (unsigned int i = 0; i < count; i++)
648 if (likely (!intersects_func (c->glyphs, values[i], intersects_data)))
649 return false;
650 return true;
651}
652
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400653
Behdad Esfahbodd0a52332012-11-23 18:54:59 -0500654static inline void collect_glyph (hb_set_t *glyphs, const USHORT &value, const void *data HB_UNUSED)
655{
656 glyphs->add (value);
657}
658static inline void collect_class (hb_set_t *glyphs, const USHORT &value, const void *data)
659{
660 const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
661 class_def.add_class (glyphs, value);
662}
663static inline void collect_coverage (hb_set_t *glyphs, const USHORT &value, const void *data)
664{
665 const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
666 (data+coverage).add_coverage (glyphs);
667}
Behdad Esfahbod0beb66e2012-12-05 18:46:04 -0500668static inline void collect_array (hb_collect_glyphs_context_t *c HB_UNUSED,
Behdad Esfahbodf1b12782012-11-24 01:55:34 -0500669 hb_set_t *glyphs,
Behdad Esfahbodd0a52332012-11-23 18:54:59 -0500670 unsigned int count,
671 const USHORT values[],
672 collect_glyphs_func_t collect_func,
673 const void *collect_data)
674{
675 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodf1b12782012-11-24 01:55:34 -0500676 collect_func (glyphs, values[i], collect_data);
Behdad Esfahbodd0a52332012-11-23 18:54:59 -0500677}
678
679
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400680static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, const void *data HB_UNUSED)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400681{
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400682 return glyph_id == value;
683}
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400684static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, const void *data)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400685{
Behdad Esfahbod2b5a59c2009-08-04 11:38:50 -0400686 const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400687 return class_def.get_class (glyph_id) == value;
688}
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400689static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, const void *data)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400690{
Behdad Esfahbod6b54c5d2009-05-18 18:30:25 -0400691 const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400692 return (data+coverage).get_coverage (glyph_id) != NOT_COVERED;
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -0400693}
694
Behdad Esfahbode72b3602012-07-19 14:35:23 -0400695static inline bool would_match_input (hb_would_apply_context_t *c,
696 unsigned int count, /* Including the first glyph (not matched) */
697 const USHORT input[], /* Array of input values--start with second glyph */
698 match_func_t match_func,
699 const void *match_data)
700{
701 if (count != c->len)
702 return false;
703
704 for (unsigned int i = 1; i < count; i++)
Behdad Esfahbod472f2292012-08-07 22:25:24 -0400705 if (likely (!match_func (c->glyphs[i], input[i - 1], match_data)))
Behdad Esfahbode72b3602012-07-19 14:35:23 -0400706 return false;
707
708 return true;
709}
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400710static inline bool match_input (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400711 unsigned int count, /* Including the first glyph (not matched) */
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400712 const USHORT input[], /* Array of input values--start with second glyph */
713 match_func_t match_func,
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400714 const void *match_data,
Behdad Esfahbod6cc136f2013-10-17 13:55:48 +0200715 unsigned int *end_offset,
716 unsigned int match_positions[MAX_CONTEXT_LENGTH],
Behdad Esfahbod191fa882012-08-28 22:58:55 -0400717 bool *p_is_mark_ligature = NULL,
718 unsigned int *p_total_component_count = NULL)
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400719{
Behdad Esfahbod73c18ae2012-11-23 15:34:11 -0500720 TRACE_APPLY (NULL);
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400721
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200722 if (unlikely (count > MAX_CONTEXT_LENGTH)) TRACE_RETURN (false);
723
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200724 hb_buffer_t *buffer = c->buffer;
725
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100726 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100727 skippy_iter.reset (buffer->idx, count - 1);
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500728 skippy_iter.set_match_func (match_func, match_data, input);
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400729
Behdad Esfahbod191fa882012-08-28 22:58:55 -0400730 /*
731 * This is perhaps the trickiest part of OpenType... Remarks:
732 *
733 * - If all components of the ligature were marks, we call this a mark ligature.
734 *
735 * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize
736 * it as a ligature glyph.
737 *
738 * - Ligatures cannot be formed across glyphs attached to different components
739 * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and
740 * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother.
741 * However, it would be wrong to ligate that SHADDA,FATHA sequence.o
742 * There is an exception to this: If a ligature tries ligating with marks that
743 * belong to it itself, go ahead, assuming that the font designer knows what
744 * they are doing (otherwise it can break Indic stuff when a matra wants to
745 * ligate with a conjunct...)
746 */
747
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200748 bool is_mark_ligature = _hb_glyph_info_is_mark (&buffer->cur());
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400749
750 unsigned int total_component_count = 0;
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200751 total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->cur());
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400752
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200753 unsigned int first_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
754 unsigned int first_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400755
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200756 match_positions[0] = buffer->idx;
Behdad Esfahbod370f03e2012-01-16 17:03:55 -0500757 for (unsigned int i = 1; i < count; i++)
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400758 {
Behdad Esfahbod407fc122013-02-13 11:13:06 -0500759 if (!skippy_iter.next ()) return TRACE_RETURN (false);
Behdad Esfahbod6cc136f2013-10-17 13:55:48 +0200760
761 match_positions[i] = skippy_iter.idx;
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400762
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200763 unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]);
764 unsigned int this_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]);
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400765
766 if (first_lig_id && first_lig_comp) {
767 /* If first component was attached to a previous ligature component,
768 * all subsequent components should be attached to the same ligature
769 * component, otherwise we shouldn't ligate them. */
770 if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp)
771 return TRACE_RETURN (false);
772 } else {
773 /* If first component was NOT attached to a previous ligature component,
774 * all subsequent components should also NOT be attached to any ligature
775 * component, unless they are attached to the first component itself! */
776 if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id))
777 return TRACE_RETURN (false);
778 }
779
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200780 is_mark_ligature = is_mark_ligature && _hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx]);
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200781 total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->info[skippy_iter.idx]);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400782 }
783
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200784 *end_offset = skippy_iter.idx - buffer->idx + 1;
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400785
Behdad Esfahbod191fa882012-08-28 22:58:55 -0400786 if (p_is_mark_ligature)
787 *p_is_mark_ligature = is_mark_ligature;
788
789 if (p_total_component_count)
790 *p_total_component_count = total_component_count;
791
Behdad Esfahbodbc513ad2012-10-29 19:03:55 -0700792 return TRACE_RETURN (true);
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400793}
Behdad Esfahboda177d022012-08-28 23:18:22 -0400794static inline void ligate_input (hb_apply_context_t *c,
Behdad Esfahbode714fe62013-10-17 13:49:51 +0200795 unsigned int count, /* Including the first glyph */
796 unsigned int match_positions[MAX_CONTEXT_LENGTH], /* Including the first glyph */
797 unsigned int match_length,
Behdad Esfahboda177d022012-08-28 23:18:22 -0400798 hb_codepoint_t lig_glyph,
Behdad Esfahboda177d022012-08-28 23:18:22 -0400799 bool is_mark_ligature,
800 unsigned int total_component_count)
801{
Behdad Esfahbode714fe62013-10-17 13:49:51 +0200802 TRACE_APPLY (NULL);
803
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200804 hb_buffer_t *buffer = c->buffer;
805
806 buffer->merge_clusters (buffer->idx, buffer->idx + match_length);
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500807
Behdad Esfahboda177d022012-08-28 23:18:22 -0400808 /*
809 * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
810 * the ligature to keep its old ligature id. This will allow it to attach to
811 * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH,
812 * and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a
813 * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature
814 * later, we don't want them to lose their ligature id/component, otherwise
815 * GPOS will fail to correctly position the mark ligature on top of the
816 * LAM,LAM,HEH ligature. See:
817 * https://bugzilla.gnome.org/show_bug.cgi?id=676343
818 *
819 * - If a ligature is formed of components that some of which are also ligatures
820 * themselves, and those ligature components had marks attached to *their*
821 * components, we have to attach the marks to the new ligature component
822 * positions! Now *that*'s tricky! And these marks may be following the
823 * last component of the whole sequence, so we should loop forward looking
824 * for them and update them.
825 *
826 * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a
827 * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature
828 * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature
829 * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to
830 * the new ligature with a component value of 2.
831 *
832 * This in fact happened to a font... See:
833 * https://bugzilla.gnome.org/show_bug.cgi?id=437633
834 */
835
Behdad Esfahbod5a08ecf2012-11-16 13:34:29 -0800836 unsigned int klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200837 unsigned int lig_id = is_mark_ligature ? 0 : _hb_allocate_lig_id (buffer);
838 unsigned int last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
839 unsigned int last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur());
Behdad Esfahboda177d022012-08-28 23:18:22 -0400840 unsigned int components_so_far = last_num_components;
841
842 if (!is_mark_ligature)
Behdad Esfahbod7e08f122013-05-27 14:48:34 -0400843 {
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200844 _hb_glyph_info_set_lig_props_for_ligature (&buffer->cur(), lig_id, total_component_count);
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200845 if (_hb_glyph_info_get_general_category (&buffer->cur()) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
Behdad Esfahbod3d436d32013-10-28 21:00:37 +0100846 {
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200847 _hb_glyph_info_set_general_category (&buffer->cur(), HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER);
Behdad Esfahbod3d436d32013-10-28 21:00:37 +0100848 _hb_glyph_info_set_modified_combining_class (&buffer->cur(), 0);
849 }
Behdad Esfahbod7e08f122013-05-27 14:48:34 -0400850 }
Behdad Esfahboda0161742013-10-18 00:06:30 +0200851 c->replace_glyph_with_ligature (lig_glyph, klass);
Behdad Esfahboda177d022012-08-28 23:18:22 -0400852
853 for (unsigned int i = 1; i < count; i++)
854 {
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200855 while (buffer->idx < match_positions[i])
Behdad Esfahboda177d022012-08-28 23:18:22 -0400856 {
857 if (!is_mark_ligature) {
858 unsigned int new_lig_comp = components_so_far - last_num_components +
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200859 MIN (MAX (_hb_glyph_info_get_lig_comp (&buffer->cur()), 1u), last_num_components);
860 _hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp);
Behdad Esfahboda177d022012-08-28 23:18:22 -0400861 }
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200862 buffer->next_glyph ();
Behdad Esfahboda177d022012-08-28 23:18:22 -0400863 }
864
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200865 last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
866 last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur());
Behdad Esfahboda177d022012-08-28 23:18:22 -0400867 components_so_far += last_num_components;
868
869 /* Skip the base glyph */
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200870 buffer->idx++;
Behdad Esfahboda177d022012-08-28 23:18:22 -0400871 }
872
873 if (!is_mark_ligature && last_lig_id) {
874 /* Re-adjust components for any marks following. */
Behdad Esfahbod3c3df9c2013-10-17 13:58:31 +0200875 for (unsigned int i = buffer->idx; i < buffer->len; i++) {
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200876 if (last_lig_id == _hb_glyph_info_get_lig_id (&buffer->info[i])) {
Behdad Esfahboda177d022012-08-28 23:18:22 -0400877 unsigned int new_lig_comp = components_so_far - last_num_components +
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200878 MIN (MAX (_hb_glyph_info_get_lig_comp (&buffer->info[i]), 1u), last_num_components);
879 _hb_glyph_info_set_lig_props_for_mark (&buffer->info[i], lig_id, new_lig_comp);
Behdad Esfahboda177d022012-08-28 23:18:22 -0400880 } else
881 break;
882 }
883 }
Behdad Esfahbod04d894e2014-03-25 12:11:32 -0700884 TRACE_RETURN (true);
Behdad Esfahboda177d022012-08-28 23:18:22 -0400885}
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400886
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400887static inline bool match_backtrack (hb_apply_context_t *c,
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400888 unsigned int count,
889 const USHORT backtrack[],
890 match_func_t match_func,
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400891 const void *match_data)
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400892{
Behdad Esfahbod73c18ae2012-11-23 15:34:11 -0500893 TRACE_APPLY (NULL);
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400894
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100895 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100896 skippy_iter.reset (c->buffer->backtrack_len (), count);
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500897 skippy_iter.set_match_func (match_func, match_data, backtrack);
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400898
Behdad Esfahbod4d3aeb82012-01-16 16:43:26 -0500899 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500900 if (!skippy_iter.prev ())
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400901 return TRACE_RETURN (false);
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400902
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400903 return TRACE_RETURN (true);
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400904}
905
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400906static inline bool match_lookahead (hb_apply_context_t *c,
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400907 unsigned int count,
908 const USHORT lookahead[],
909 match_func_t match_func,
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -0400910 const void *match_data,
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400911 unsigned int offset)
912{
Behdad Esfahbod73c18ae2012-11-23 15:34:11 -0500913 TRACE_APPLY (NULL);
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400914
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100915 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100916 skippy_iter.reset (c->buffer->idx + offset - 1, count);
Behdad Esfahbod607feb72013-02-14 07:43:13 -0500917 skippy_iter.set_match_func (match_func, match_data, lookahead);
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400918
Behdad Esfahbod370f03e2012-01-16 17:03:55 -0500919 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500920 if (!skippy_iter.next ())
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400921 return TRACE_RETURN (false);
Behdad Esfahbodd0ba0552009-05-18 03:56:39 -0400922
Behdad Esfahbod93814ca2012-08-28 22:24:51 -0400923 return TRACE_RETURN (true);
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400924}
925
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400926
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400927
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400928struct LookupRecord
929{
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300930 inline bool sanitize (hb_sanitize_context_t *c) const
931 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500932 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +0200933 return TRACE_RETURN (c->check_struct (this));
Behdad Esfahbodcd3827e2009-08-04 02:09:34 -0400934 }
935
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400936 USHORT sequenceIndex; /* Index into current glyph
937 * sequence--first glyph = 0 */
938 USHORT lookupListIndex; /* Lookup to apply to that
939 * position--zero--based */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400940 public:
941 DEFINE_SIZE_STATIC (4);
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400942};
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400943
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400944
Behdad Esfahbodd0a52332012-11-23 18:54:59 -0500945template <typename context_t>
946static inline void recurse_lookups (context_t *c,
947 unsigned int lookupCount,
948 const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */)
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400949{
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400950 for (unsigned int i = 0; i < lookupCount; i++)
Behdad Esfahbod86522e42013-07-22 19:07:53 -0400951 c->recurse (lookupRecord[i].lookupListIndex);
Behdad Esfahbod31081f72012-04-23 16:54:58 -0400952}
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400953
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400954static inline bool apply_lookup (hb_apply_context_t *c,
Behdad Esfahbode072c242009-05-18 03:47:31 -0400955 unsigned int count, /* Including the first glyph */
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200956 unsigned int match_positions[MAX_CONTEXT_LENGTH], /* Including the first glyph */
Behdad Esfahbode072c242009-05-18 03:47:31 -0400957 unsigned int lookupCount,
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200958 const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
959 unsigned int match_length)
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -0400960{
Behdad Esfahbod73c18ae2012-11-23 15:34:11 -0500961 TRACE_APPLY (NULL);
Behdad Esfahbod902cc8a2012-11-23 15:06:59 -0500962
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200963 hb_buffer_t *buffer = c->buffer;
964 unsigned int end;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -0400965
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200966 /* All positions are distance from beginning of *output* buffer.
967 * Adjust. */
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400968 {
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200969 unsigned int bl = buffer->backtrack_len ();
970 end = bl + match_length;
Behdad Esfahbod8751de52013-07-18 16:29:50 -0400971
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200972 int delta = bl - buffer->idx;
973 /* Convert positions to new indexing. */
974 for (unsigned int j = 0; j < count; j++)
975 match_positions[j] += delta;
Behdad Esfahbod8820bb22013-02-14 07:41:03 -0500976 }
Behdad Esfahbode73a0c22009-05-18 04:15:25 -0400977
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200978 for (unsigned int i = 0; i < lookupCount; i++)
979 {
980 unsigned int idx = lookupRecord[i].sequenceIndex;
981 if (idx >= count)
982 continue;
983
984 buffer->move_to (match_positions[idx]);
985
986 unsigned int orig_len = buffer->backtrack_len () + buffer->lookahead_len ();
987 if (!c->recurse (lookupRecord[i].lookupListIndex))
988 continue;
989
990 unsigned int new_len = buffer->backtrack_len () + buffer->lookahead_len ();
991 int delta = new_len - orig_len;
992
993 if (!delta)
994 continue;
995
996 /* Recursed lookup changed buffer len. Adjust. */
997
Behdad Esfahbodb6b304f2014-06-05 17:12:54 -0400998 /* end can't go back past the current match position.
999 * Note: this is only true because we do NOT allow MultipleSubst
1000 * with zero sequence len. */
Behdad Esfahbodda720422013-10-17 12:01:50 +02001001 end = MAX ((int) match_positions[idx] + 1, int (end) + delta);
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001002
1003 unsigned int next = idx + 1; /* next now is the position after the recursed lookup. */
1004
1005 if (delta > 0)
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001006 {
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001007 if (unlikely (delta + count > MAX_CONTEXT_LENGTH))
1008 break;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001009 }
1010 else
1011 {
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001012 /* NOTE: delta is negative. */
1013 delta = MAX (delta, (int) next - (int) count);
1014 next -= delta;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001015 }
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001016
1017 /* Shift! */
1018 memmove (match_positions + next + delta, match_positions + next,
1019 (count - next) * sizeof (match_positions[0]));
1020 next += delta;
1021 count += delta;
1022
1023 /* Fill in new entries. */
1024 for (unsigned int j = idx + 1; j < next; j++)
1025 match_positions[j] = match_positions[j - 1] + 1;
1026
1027 /* And fixup the rest. */
1028 for (; next < count; next++)
1029 match_positions[next] += delta;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001030 }
1031
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001032 buffer->move_to (end);
1033
Behdad Esfahbod26166892012-10-29 21:51:56 -07001034 return TRACE_RETURN (true);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001035}
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001036
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -04001037
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -04001038
1039/* Contextual lookups */
1040
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001041struct ContextClosureLookupContext
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001042{
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001043 ContextClosureFuncs funcs;
1044 const void *intersects_data;
1045};
1046
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001047struct ContextCollectGlyphsLookupContext
1048{
1049 ContextCollectGlyphsFuncs funcs;
1050 const void *collect_data;
1051};
1052
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001053struct ContextApplyLookupContext
1054{
1055 ContextApplyFuncs funcs;
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -04001056 const void *match_data;
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -04001057};
1058
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001059static inline void context_closure_lookup (hb_closure_context_t *c,
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001060 unsigned int inputCount, /* Including the first glyph (not matched) */
1061 const USHORT input[], /* Array of input values--start with second glyph */
1062 unsigned int lookupCount,
1063 const LookupRecord lookupRecord[],
1064 ContextClosureLookupContext &lookup_context)
1065{
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001066 if (intersects_array (c,
1067 inputCount ? inputCount - 1 : 0, input,
1068 lookup_context.funcs.intersects, lookup_context.intersects_data))
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001069 recurse_lookups (c,
1070 lookupCount, lookupRecord);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001071}
1072
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001073static inline void context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c,
1074 unsigned int inputCount, /* Including the first glyph (not matched) */
1075 const USHORT input[], /* Array of input values--start with second glyph */
1076 unsigned int lookupCount,
1077 const LookupRecord lookupRecord[],
1078 ContextCollectGlyphsLookupContext &lookup_context)
1079{
Behdad Esfahbod83035932012-12-04 17:08:41 -05001080 collect_array (c, c->input,
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001081 inputCount ? inputCount - 1 : 0, input,
1082 lookup_context.funcs.collect, lookup_context.collect_data);
1083 recurse_lookups (c,
1084 lookupCount, lookupRecord);
1085}
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001086
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001087static inline bool context_would_apply_lookup (hb_would_apply_context_t *c,
1088 unsigned int inputCount, /* Including the first glyph (not matched) */
1089 const USHORT input[], /* Array of input values--start with second glyph */
Behdad Esfahbod0beb66e2012-12-05 18:46:04 -05001090 unsigned int lookupCount HB_UNUSED,
1091 const LookupRecord lookupRecord[] HB_UNUSED,
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001092 ContextApplyLookupContext &lookup_context)
1093{
1094 return would_match_input (c,
1095 inputCount, input,
1096 lookup_context.funcs.match, lookup_context.match_data);
1097}
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001098static inline bool context_apply_lookup (hb_apply_context_t *c,
1099 unsigned int inputCount, /* Including the first glyph (not matched) */
1100 const USHORT input[], /* Array of input values--start with second glyph */
1101 unsigned int lookupCount,
1102 const LookupRecord lookupRecord[],
1103 ContextApplyLookupContext &lookup_context)
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -04001104{
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001105 unsigned int match_length = 0;
1106 unsigned int match_positions[MAX_CONTEXT_LENGTH];
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -04001107 return match_input (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -04001108 inputCount, input,
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001109 lookup_context.funcs.match, lookup_context.match_data,
1110 &match_length, match_positions)
Behdad Esfahbod5df809b2012-05-13 15:17:51 +02001111 && apply_lookup (c,
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001112 inputCount, match_positions,
1113 lookupCount, lookupRecord,
1114 match_length);
Behdad Esfahbodf14c2b72009-05-18 02:36:18 -04001115}
1116
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001117struct Rule
1118{
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001119 inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001120 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001121 TRACE_CLOSURE (this);
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001122 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001123 context_closure_lookup (c,
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001124 inputCount, inputZ,
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001125 lookupCount, lookupRecord,
1126 lookup_context);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001127 }
1128
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001129 inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const
1130 {
1131 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001132 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001133 context_collect_glyphs_lookup (c,
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001134 inputCount, inputZ,
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001135 lookupCount, lookupRecord,
1136 lookup_context);
1137 }
1138
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001139 inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
1140 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001141 TRACE_WOULD_APPLY (this);
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001142 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
1143 return TRACE_RETURN (context_would_apply_lookup (c, inputCount, inputZ, lookupCount, lookupRecord, lookup_context));
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001144 }
1145
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001146 inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001147 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001148 TRACE_APPLY (this);
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001149 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
1150 return TRACE_RETURN (context_apply_lookup (c, inputCount, inputZ, lookupCount, lookupRecord, lookup_context));
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001151 }
1152
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001153 public:
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001154 inline bool sanitize (hb_sanitize_context_t *c) const
1155 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001156 TRACE_SANITIZE (this);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -04001157 return inputCount.sanitize (c)
1158 && lookupCount.sanitize (c)
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001159 && c->check_range (inputZ,
1160 inputZ[0].static_size * inputCount
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001161 + lookupRecordX[0].static_size * lookupCount);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001162 }
1163
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001164 protected:
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001165 USHORT inputCount; /* Total number of glyphs in input
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001166 * glyph sequence--includes the first
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001167 * glyph */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001168 USHORT lookupCount; /* Number of LookupRecords */
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001169 USHORT inputZ[VAR]; /* Array of match inputs--start with
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001170 * second glyph */
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -05001171 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001172 * design order */
Behdad Esfahbod569da922010-05-10 16:38:32 -04001173 public:
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001174 DEFINE_SIZE_ARRAY2 (4, inputZ, lookupRecordX);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001175};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001176
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001177struct RuleSet
1178{
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001179 inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001180 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001181 TRACE_CLOSURE (this);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001182 unsigned int num_rules = rule.len;
1183 for (unsigned int i = 0; i < num_rules; i++)
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001184 (this+rule[i]).closure (c, lookup_context);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001185 }
1186
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001187 inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const
1188 {
1189 TRACE_COLLECT_GLYPHS (this);
1190 unsigned int num_rules = rule.len;
1191 for (unsigned int i = 0; i < num_rules; i++)
1192 (this+rule[i]).collect_glyphs (c, lookup_context);
1193 }
1194
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001195 inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
1196 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001197 TRACE_WOULD_APPLY (this);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001198 unsigned int num_rules = rule.len;
1199 for (unsigned int i = 0; i < num_rules; i++)
1200 {
1201 if ((this+rule[i]).would_apply (c, lookup_context))
1202 return TRACE_RETURN (true);
1203 }
1204 return TRACE_RETURN (false);
1205 }
1206
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001207 inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001208 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001209 TRACE_APPLY (this);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001210 unsigned int num_rules = rule.len;
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001211 for (unsigned int i = 0; i < num_rules; i++)
1212 {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -04001213 if ((this+rule[i]).apply (c, lookup_context))
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001214 return TRACE_RETURN (true);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001215 }
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001216 return TRACE_RETURN (false);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001217 }
1218
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001219 inline bool sanitize (hb_sanitize_context_t *c) const
1220 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001221 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001222 return TRACE_RETURN (rule.sanitize (c, this));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001223 }
1224
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001225 protected:
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001226 OffsetArrayOf<Rule>
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001227 rule; /* Array of Rule tables
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001228 * ordered by preference */
Behdad Esfahboded074222010-05-10 18:08:46 -04001229 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -04001230 DEFINE_SIZE_ARRAY (2, rule);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001231};
1232
1233
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001234struct ContextFormat1
1235{
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001236 inline void closure (hb_closure_context_t *c) const
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001237 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001238 TRACE_CLOSURE (this);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001239
1240 const Coverage &cov = (this+coverage);
1241
1242 struct ContextClosureLookupContext lookup_context = {
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001243 {intersects_glyph},
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001244 NULL
1245 };
1246
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001247 unsigned int count = ruleSet.len;
1248 for (unsigned int i = 0; i < count; i++)
1249 if (cov.intersects_coverage (c->glyphs, i)) {
1250 const RuleSet &rule_set = this+ruleSet[i];
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001251 rule_set.closure (c, lookup_context);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001252 }
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001253 }
1254
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001255 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1256 {
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001257 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001258 (this+coverage).add_coverage (c->input);
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001259
1260 struct ContextCollectGlyphsLookupContext lookup_context = {
1261 {collect_glyph},
1262 NULL
1263 };
1264
1265 unsigned int count = ruleSet.len;
1266 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001267 (this+ruleSet[i]).collect_glyphs (c, lookup_context);
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001268 }
1269
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001270 inline bool would_apply (hb_would_apply_context_t *c) const
1271 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001272 TRACE_WOULD_APPLY (this);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001273
Behdad Esfahbodb67881b2012-11-24 19:13:55 -05001274 const RuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])];
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001275 struct ContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001276 {match_glyph},
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001277 NULL
1278 };
1279 return TRACE_RETURN (rule_set.would_apply (c, lookup_context));
1280 }
1281
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001282 inline const Coverage &get_coverage (void) const
1283 {
1284 return this+coverage;
1285 }
1286
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001287 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001288 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001289 TRACE_APPLY (this);
Behdad Esfahbodb67881b2012-11-24 19:13:55 -05001290 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -04001291 if (likely (index == NOT_COVERED))
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001292 return TRACE_RETURN (false);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001293
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001294 const RuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001295 struct ContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001296 {match_glyph},
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001297 NULL
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001298 };
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001299 return TRACE_RETURN (rule_set.apply (c, lookup_context));
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001300 }
1301
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001302 inline bool sanitize (hb_sanitize_context_t *c) const
1303 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001304 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001305 return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001306 }
1307
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001308 protected:
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001309 USHORT format; /* Format identifier--format = 1 */
1310 OffsetTo<Coverage>
1311 coverage; /* Offset to Coverage table--from
1312 * beginning of table */
1313 OffsetArrayOf<RuleSet>
1314 ruleSet; /* Array of RuleSet tables
1315 * ordered by Coverage Index */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001316 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -04001317 DEFINE_SIZE_ARRAY (6, ruleSet);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001318};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001319
1320
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001321struct ContextFormat2
1322{
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001323 inline void closure (hb_closure_context_t *c) const
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001324 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001325 TRACE_CLOSURE (this);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001326 if (!(this+coverage).intersects (c->glyphs))
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001327 return;
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001328
1329 const ClassDef &class_def = this+classDef;
1330
1331 struct ContextClosureLookupContext lookup_context = {
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001332 {intersects_class},
Behdad Esfahbod11fba792013-01-02 23:36:37 -06001333 &class_def
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001334 };
1335
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001336 unsigned int count = ruleSet.len;
1337 for (unsigned int i = 0; i < count; i++)
1338 if (class_def.intersects_class (c->glyphs, i)) {
1339 const RuleSet &rule_set = this+ruleSet[i];
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001340 rule_set.closure (c, lookup_context);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001341 }
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001342 }
1343
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001344 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1345 {
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001346 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001347 (this+coverage).add_coverage (c->input);
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001348
Behdad Esfahbod11fba792013-01-02 23:36:37 -06001349 const ClassDef &class_def = this+classDef;
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001350 struct ContextCollectGlyphsLookupContext lookup_context = {
1351 {collect_class},
Behdad Esfahbod11fba792013-01-02 23:36:37 -06001352 &class_def
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001353 };
1354
1355 unsigned int count = ruleSet.len;
1356 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001357 (this+ruleSet[i]).collect_glyphs (c, lookup_context);
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001358 }
1359
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001360 inline bool would_apply (hb_would_apply_context_t *c) const
1361 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001362 TRACE_WOULD_APPLY (this);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001363
1364 const ClassDef &class_def = this+classDef;
Behdad Esfahbod2dc11412012-11-24 19:16:34 -05001365 unsigned int index = class_def.get_class (c->glyphs[0]);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001366 const RuleSet &rule_set = this+ruleSet[index];
1367 struct ContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001368 {match_class},
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001369 &class_def
1370 };
1371 return TRACE_RETURN (rule_set.would_apply (c, lookup_context));
1372 }
1373
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001374 inline const Coverage &get_coverage (void) const
1375 {
1376 return this+coverage;
1377 }
1378
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001379 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001380 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001381 TRACE_APPLY (this);
Behdad Esfahbodb67881b2012-11-24 19:13:55 -05001382 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001383 if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001384
1385 const ClassDef &class_def = this+classDef;
Behdad Esfahbod2dc11412012-11-24 19:16:34 -05001386 index = class_def.get_class (c->buffer->cur().codepoint);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001387 const RuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001388 struct ContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001389 {match_class},
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -04001390 &class_def
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001391 };
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001392 return TRACE_RETURN (rule_set.apply (c, lookup_context));
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001393 }
1394
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001395 inline bool sanitize (hb_sanitize_context_t *c) const
1396 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001397 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001398 return TRACE_RETURN (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001399 }
1400
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001401 protected:
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001402 USHORT format; /* Format identifier--format = 2 */
1403 OffsetTo<Coverage>
1404 coverage; /* Offset to Coverage table--from
1405 * beginning of table */
1406 OffsetTo<ClassDef>
1407 classDef; /* Offset to glyph ClassDef table--from
1408 * beginning of table */
1409 OffsetArrayOf<RuleSet>
1410 ruleSet; /* Array of RuleSet tables
1411 * ordered by class */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001412 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -04001413 DEFINE_SIZE_ARRAY (8, ruleSet);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001414};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001415
1416
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001417struct ContextFormat3
1418{
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001419 inline void closure (hb_closure_context_t *c) const
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001420 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001421 TRACE_CLOSURE (this);
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001422 if (!(this+coverageZ[0]).intersects (c->glyphs))
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001423 return;
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001424
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001425 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001426 struct ContextClosureLookupContext lookup_context = {
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001427 {intersects_coverage},
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001428 this
1429 };
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001430 context_closure_lookup (c,
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001431 glyphCount, (const USHORT *) (coverageZ + 1),
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001432 lookupCount, lookupRecord,
1433 lookup_context);
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001434 }
1435
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001436 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1437 {
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001438 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001439 (this+coverageZ[0]).add_coverage (c->input);
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001440
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001441 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001442 struct ContextCollectGlyphsLookupContext lookup_context = {
1443 {collect_coverage},
Behdad Esfahbode75943d2012-11-30 08:38:24 +02001444 this
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001445 };
1446
1447 context_collect_glyphs_lookup (c,
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001448 glyphCount, (const USHORT *) (coverageZ + 1),
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001449 lookupCount, lookupRecord,
1450 lookup_context);
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001451 }
1452
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001453 inline bool would_apply (hb_would_apply_context_t *c) const
1454 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001455 TRACE_WOULD_APPLY (this);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001456
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001457 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001458 struct ContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001459 {match_coverage},
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001460 this
1461 };
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001462 return TRACE_RETURN (context_would_apply_lookup (c, glyphCount, (const USHORT *) (coverageZ + 1), lookupCount, lookupRecord, lookup_context));
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001463 }
1464
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001465 inline const Coverage &get_coverage (void) const
1466 {
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001467 return this+coverageZ[0];
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001468 }
1469
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001470 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001471 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001472 TRACE_APPLY (this);
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001473 unsigned int index = (this+coverageZ[0]).get_coverage (c->buffer->cur().codepoint);
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001474 if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -04001475
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001476 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001477 struct ContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001478 {match_coverage},
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -04001479 this
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001480 };
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001481 return TRACE_RETURN (context_apply_lookup (c, glyphCount, (const USHORT *) (coverageZ + 1), lookupCount, lookupRecord, lookup_context));
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001482 }
1483
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001484 inline bool sanitize (hb_sanitize_context_t *c) const
1485 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001486 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001487 if (!c->check_struct (this)) return TRACE_RETURN (false);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001488 unsigned int count = glyphCount;
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001489 if (!count) return TRACE_RETURN (false); /* We want to access coverageZ[0] freely. */
1490 if (!c->check_array (coverageZ, coverageZ[0].static_size, count)) return TRACE_RETURN (false);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001491 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001492 if (!coverageZ[i].sanitize (c, this)) return TRACE_RETURN (false);
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001493 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * count);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001494 return TRACE_RETURN (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001495 }
1496
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001497 protected:
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001498 USHORT format; /* Format identifier--format = 3 */
1499 USHORT glyphCount; /* Number of glyphs in the input glyph
1500 * sequence */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001501 USHORT lookupCount; /* Number of LookupRecords */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001502 OffsetTo<Coverage>
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001503 coverageZ[VAR]; /* Array of offsets to Coverage
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001504 * table in glyph sequence order */
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -05001505 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001506 * design order */
Behdad Esfahbod569da922010-05-10 16:38:32 -04001507 public:
Behdad Esfahbod093c5202014-12-12 21:07:53 -08001508 DEFINE_SIZE_ARRAY2 (6, coverageZ, lookupRecordX);
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001509};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001510
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001511struct Context
1512{
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001513 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001514 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001515 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001516 TRACE_DISPATCH (this, u.format);
Behdad Esfahbod50b8dc72015-02-17 18:14:17 +03001517 if (unlikely (!c->may_dispatch (this, &u.format))) TRACE_RETURN (c->default_return_value ());
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001518 switch (u.format) {
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001519 case 1: return TRACE_RETURN (c->dispatch (u.format1));
1520 case 2: return TRACE_RETURN (c->dispatch (u.format2));
1521 case 3: return TRACE_RETURN (c->dispatch (u.format3));
Behdad Esfahbodf48ec0e2012-11-23 17:23:41 -05001522 default:return TRACE_RETURN (c->default_return_value ());
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001523 }
1524 }
1525
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001526 protected:
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001527 union {
Behdad Esfahbodf8dc67b2009-05-17 19:47:54 -04001528 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001529 ContextFormat1 format1;
1530 ContextFormat2 format2;
1531 ContextFormat3 format3;
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001532 } u;
1533};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04001534
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001535
1536/* Chaining Contextual lookups */
1537
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001538struct ChainContextClosureLookupContext
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001539{
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001540 ContextClosureFuncs funcs;
1541 const void *intersects_data[3];
1542};
1543
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001544struct ChainContextCollectGlyphsLookupContext
1545{
1546 ContextCollectGlyphsFuncs funcs;
1547 const void *collect_data[3];
1548};
1549
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001550struct ChainContextApplyLookupContext
1551{
1552 ContextApplyFuncs funcs;
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -04001553 const void *match_data[3];
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001554};
1555
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001556static inline void chain_context_closure_lookup (hb_closure_context_t *c,
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001557 unsigned int backtrackCount,
1558 const USHORT backtrack[],
1559 unsigned int inputCount, /* Including the first glyph (not matched) */
1560 const USHORT input[], /* Array of input values--start with second glyph */
1561 unsigned int lookaheadCount,
1562 const USHORT lookahead[],
1563 unsigned int lookupCount,
1564 const LookupRecord lookupRecord[],
1565 ChainContextClosureLookupContext &lookup_context)
1566{
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001567 if (intersects_array (c,
1568 backtrackCount, backtrack,
1569 lookup_context.funcs.intersects, lookup_context.intersects_data[0])
1570 && intersects_array (c,
1571 inputCount ? inputCount - 1 : 0, input,
1572 lookup_context.funcs.intersects, lookup_context.intersects_data[1])
Behdad Esfahbod74439d02013-07-22 19:02:29 -04001573 && intersects_array (c,
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001574 lookaheadCount, lookahead,
1575 lookup_context.funcs.intersects, lookup_context.intersects_data[2]))
Behdad Esfahbodd0a52332012-11-23 18:54:59 -05001576 recurse_lookups (c,
1577 lookupCount, lookupRecord);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001578}
1579
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001580static inline void chain_context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c,
1581 unsigned int backtrackCount,
1582 const USHORT backtrack[],
1583 unsigned int inputCount, /* Including the first glyph (not matched) */
1584 const USHORT input[], /* Array of input values--start with second glyph */
1585 unsigned int lookaheadCount,
1586 const USHORT lookahead[],
1587 unsigned int lookupCount,
1588 const LookupRecord lookupRecord[],
1589 ChainContextCollectGlyphsLookupContext &lookup_context)
1590{
Behdad Esfahbod83035932012-12-04 17:08:41 -05001591 collect_array (c, c->before,
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001592 backtrackCount, backtrack,
1593 lookup_context.funcs.collect, lookup_context.collect_data[0]);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001594 collect_array (c, c->input,
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001595 inputCount ? inputCount - 1 : 0, input,
1596 lookup_context.funcs.collect, lookup_context.collect_data[1]);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001597 collect_array (c, c->after,
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001598 lookaheadCount, lookahead,
1599 lookup_context.funcs.collect, lookup_context.collect_data[2]);
1600 recurse_lookups (c,
1601 lookupCount, lookupRecord);
1602}
1603
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001604static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c,
1605 unsigned int backtrackCount,
Behdad Esfahbod0beb66e2012-12-05 18:46:04 -05001606 const USHORT backtrack[] HB_UNUSED,
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001607 unsigned int inputCount, /* Including the first glyph (not matched) */
1608 const USHORT input[], /* Array of input values--start with second glyph */
1609 unsigned int lookaheadCount,
Behdad Esfahbod0beb66e2012-12-05 18:46:04 -05001610 const USHORT lookahead[] HB_UNUSED,
1611 unsigned int lookupCount HB_UNUSED,
1612 const LookupRecord lookupRecord[] HB_UNUSED,
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001613 ChainContextApplyLookupContext &lookup_context)
1614{
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -04001615 return (c->zero_context ? !backtrackCount && !lookaheadCount : true)
Behdad Esfahbod1f2bb172012-08-23 16:10:37 -04001616 && would_match_input (c,
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001617 inputCount, input,
1618 lookup_context.funcs.match, lookup_context.match_data[1]);
1619}
1620
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001621static inline bool chain_context_apply_lookup (hb_apply_context_t *c,
1622 unsigned int backtrackCount,
1623 const USHORT backtrack[],
1624 unsigned int inputCount, /* Including the first glyph (not matched) */
1625 const USHORT input[], /* Array of input values--start with second glyph */
1626 unsigned int lookaheadCount,
1627 const USHORT lookahead[],
1628 unsigned int lookupCount,
1629 const LookupRecord lookupRecord[],
1630 ChainContextApplyLookupContext &lookup_context)
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -04001631{
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001632 unsigned int match_length = 0;
1633 unsigned int match_positions[MAX_CONTEXT_LENGTH];
Behdad Esfahbodf19e0b02012-06-09 02:26:57 -04001634 return match_input (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -04001635 inputCount, input,
1636 lookup_context.funcs.match, lookup_context.match_data[1],
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001637 &match_length, match_positions)
Behdad Esfahbodf19e0b02012-06-09 02:26:57 -04001638 && match_backtrack (c,
1639 backtrackCount, backtrack,
1640 lookup_context.funcs.match, lookup_context.match_data[0])
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -04001641 && match_lookahead (c,
Behdad Esfahbod41697102010-05-05 01:37:58 -04001642 lookaheadCount, lookahead,
1643 lookup_context.funcs.match, lookup_context.match_data[2],
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001644 match_length)
Behdad Esfahbod5df809b2012-05-13 15:17:51 +02001645 && apply_lookup (c,
Behdad Esfahbod6b65a762013-10-14 18:51:39 +02001646 inputCount, match_positions,
1647 lookupCount, lookupRecord,
1648 match_length);
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -04001649}
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001650
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001651struct ChainRule
1652{
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001653 inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001654 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001655 TRACE_CLOSURE (this);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001656 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1657 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1658 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001659 chain_context_closure_lookup (c,
1660 backtrack.len, backtrack.array,
1661 input.len, input.array,
1662 lookahead.len, lookahead.array,
1663 lookup.len, lookup.array,
1664 lookup_context);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001665 }
1666
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001667 inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const
1668 {
1669 TRACE_COLLECT_GLYPHS (this);
1670 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1671 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1672 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
1673 chain_context_collect_glyphs_lookup (c,
1674 backtrack.len, backtrack.array,
1675 input.len, input.array,
1676 lookahead.len, lookahead.array,
1677 lookup.len, lookup.array,
1678 lookup_context);
1679 }
1680
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001681 inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
1682 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001683 TRACE_WOULD_APPLY (this);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001684 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1685 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1686 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
1687 return TRACE_RETURN (chain_context_would_apply_lookup (c,
1688 backtrack.len, backtrack.array,
1689 input.len, input.array,
1690 lookahead.len, lookahead.array, lookup.len,
1691 lookup.array, lookup_context));
1692 }
1693
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001694 inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001695 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001696 TRACE_APPLY (this);
Behdad Esfahbode961c862010-04-21 15:56:11 -04001697 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1698 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1699 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001700 return TRACE_RETURN (chain_context_apply_lookup (c,
1701 backtrack.len, backtrack.array,
1702 input.len, input.array,
1703 lookahead.len, lookahead.array, lookup.len,
1704 lookup.array, lookup_context));
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001705 }
1706
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001707 inline bool sanitize (hb_sanitize_context_t *c) const
1708 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001709 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001710 if (!backtrack.sanitize (c)) return TRACE_RETURN (false);
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001711 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001712 if (!input.sanitize (c)) return TRACE_RETURN (false);
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001713 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001714 if (!lookahead.sanitize (c)) return TRACE_RETURN (false);
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001715 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001716 return TRACE_RETURN (lookup.sanitize (c));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001717 }
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001718
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001719 protected:
Behdad Esfahboddcb6b602009-05-18 01:49:57 -04001720 ArrayOf<USHORT>
1721 backtrack; /* Array of backtracking values
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001722 * (to be matched before the input
1723 * sequence) */
Behdad Esfahbode8cbaaf2009-05-18 02:03:58 -04001724 HeadlessArrayOf<USHORT>
1725 inputX; /* Array of input values (start with
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001726 * second glyph) */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -04001727 ArrayOf<USHORT>
1728 lookaheadX; /* Array of lookahead values's (to be
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001729 * matched after the input sequence) */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -04001730 ArrayOf<LookupRecord>
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -04001731 lookupX; /* Array of LookupRecords--in
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001732 * design order) */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001733 public:
Behdad Esfahbodbea34c72010-05-10 17:28:16 -04001734 DEFINE_SIZE_MIN (8);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001735};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001736
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001737struct ChainRuleSet
1738{
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001739 inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001740 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001741 TRACE_CLOSURE (this);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001742 unsigned int num_rules = rule.len;
1743 for (unsigned int i = 0; i < num_rules; i++)
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001744 (this+rule[i]).closure (c, lookup_context);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001745 }
1746
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001747 inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const
1748 {
1749 TRACE_COLLECT_GLYPHS (this);
1750 unsigned int num_rules = rule.len;
1751 for (unsigned int i = 0; i < num_rules; i++)
1752 (this+rule[i]).collect_glyphs (c, lookup_context);
1753 }
1754
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001755 inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
1756 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001757 TRACE_WOULD_APPLY (this);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001758 unsigned int num_rules = rule.len;
1759 for (unsigned int i = 0; i < num_rules; i++)
1760 if ((this+rule[i]).would_apply (c, lookup_context))
1761 return TRACE_RETURN (true);
1762
1763 return TRACE_RETURN (false);
1764 }
1765
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001766 inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001767 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001768 TRACE_APPLY (this);
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001769 unsigned int num_rules = rule.len;
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001770 for (unsigned int i = 0; i < num_rules; i++)
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -04001771 if ((this+rule[i]).apply (c, lookup_context))
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001772 return TRACE_RETURN (true);
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001773
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001774 return TRACE_RETURN (false);
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001775 }
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001776
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001777 inline bool sanitize (hb_sanitize_context_t *c) const
1778 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001779 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001780 return TRACE_RETURN (rule.sanitize (c, this));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001781 }
1782
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001783 protected:
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001784 OffsetArrayOf<ChainRule>
1785 rule; /* Array of ChainRule tables
1786 * ordered by preference */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001787 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -04001788 DEFINE_SIZE_ARRAY (2, rule);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001789};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001790
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001791struct ChainContextFormat1
1792{
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001793 inline void closure (hb_closure_context_t *c) const
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001794 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001795 TRACE_CLOSURE (this);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001796 const Coverage &cov = (this+coverage);
1797
1798 struct ChainContextClosureLookupContext lookup_context = {
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001799 {intersects_glyph},
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001800 {NULL, NULL, NULL}
1801 };
1802
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001803 unsigned int count = ruleSet.len;
1804 for (unsigned int i = 0; i < count; i++)
1805 if (cov.intersects_coverage (c->glyphs, i)) {
1806 const ChainRuleSet &rule_set = this+ruleSet[i];
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001807 rule_set.closure (c, lookup_context);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001808 }
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001809 }
1810
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001811 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1812 {
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001813 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001814 (this+coverage).add_coverage (c->input);
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001815
1816 struct ChainContextCollectGlyphsLookupContext lookup_context = {
1817 {collect_glyph},
1818 {NULL, NULL, NULL}
1819 };
1820
1821 unsigned int count = ruleSet.len;
1822 for (unsigned int i = 0; i < count; i++)
1823 (this+ruleSet[i]).collect_glyphs (c, lookup_context);
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001824 }
1825
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001826 inline bool would_apply (hb_would_apply_context_t *c) const
1827 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001828 TRACE_WOULD_APPLY (this);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001829
Behdad Esfahbodb67881b2012-11-24 19:13:55 -05001830 const ChainRuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])];
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001831 struct ChainContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001832 {match_glyph},
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001833 {NULL, NULL, NULL}
1834 };
1835 return TRACE_RETURN (rule_set.would_apply (c, lookup_context));
1836 }
1837
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001838 inline const Coverage &get_coverage (void) const
1839 {
1840 return this+coverage;
1841 }
1842
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001843 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001844 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001845 TRACE_APPLY (this);
Behdad Esfahbodb67881b2012-11-24 19:13:55 -05001846 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001847 if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001848
1849 const ChainRuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001850 struct ChainContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001851 {match_glyph},
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001852 {NULL, NULL, NULL}
1853 };
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001854 return TRACE_RETURN (rule_set.apply (c, lookup_context));
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001855 }
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001856
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001857 inline bool sanitize (hb_sanitize_context_t *c) const
1858 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001859 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001860 return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001861 }
1862
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001863 protected:
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001864 USHORT format; /* Format identifier--format = 1 */
Behdad Esfahbod48f16ed2009-05-17 22:11:30 -04001865 OffsetTo<Coverage>
1866 coverage; /* Offset to Coverage table--from
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001867 * beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001868 OffsetArrayOf<ChainRuleSet>
1869 ruleSet; /* Array of ChainRuleSet tables
1870 * ordered by Coverage Index */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001871 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -04001872 DEFINE_SIZE_ARRAY (6, ruleSet);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001873};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001874
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001875struct ChainContextFormat2
1876{
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001877 inline void closure (hb_closure_context_t *c) const
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001878 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001879 TRACE_CLOSURE (this);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001880 if (!(this+coverage).intersects (c->glyphs))
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001881 return;
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001882
1883 const ClassDef &backtrack_class_def = this+backtrackClassDef;
1884 const ClassDef &input_class_def = this+inputClassDef;
1885 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
1886
1887 struct ChainContextClosureLookupContext lookup_context = {
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001888 {intersects_class},
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001889 {&backtrack_class_def,
1890 &input_class_def,
1891 &lookahead_class_def}
1892 };
1893
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001894 unsigned int count = ruleSet.len;
1895 for (unsigned int i = 0; i < count; i++)
1896 if (input_class_def.intersects_class (c->glyphs, i)) {
1897 const ChainRuleSet &rule_set = this+ruleSet[i];
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001898 rule_set.closure (c, lookup_context);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001899 }
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001900 }
1901
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001902 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1903 {
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001904 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001905 (this+coverage).add_coverage (c->input);
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001906
Behdad Esfahbod11fba792013-01-02 23:36:37 -06001907 const ClassDef &backtrack_class_def = this+backtrackClassDef;
1908 const ClassDef &input_class_def = this+inputClassDef;
1909 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
1910
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001911 struct ChainContextCollectGlyphsLookupContext lookup_context = {
1912 {collect_class},
Behdad Esfahbod11fba792013-01-02 23:36:37 -06001913 {&backtrack_class_def,
1914 &input_class_def,
1915 &lookahead_class_def}
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05001916 };
1917
1918 unsigned int count = ruleSet.len;
1919 for (unsigned int i = 0; i < count; i++)
1920 (this+ruleSet[i]).collect_glyphs (c, lookup_context);
Behdad Esfahbod26514d52012-11-23 18:13:48 -05001921 }
1922
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001923 inline bool would_apply (hb_would_apply_context_t *c) const
1924 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001925 TRACE_WOULD_APPLY (this);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001926
Behdad Esfahbod11fba792013-01-02 23:36:37 -06001927 const ClassDef &backtrack_class_def = this+backtrackClassDef;
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001928 const ClassDef &input_class_def = this+inputClassDef;
Behdad Esfahbod11fba792013-01-02 23:36:37 -06001929 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001930
Behdad Esfahbod2dc11412012-11-24 19:16:34 -05001931 unsigned int index = input_class_def.get_class (c->glyphs[0]);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001932 const ChainRuleSet &rule_set = this+ruleSet[index];
1933 struct ChainContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001934 {match_class},
Behdad Esfahbod11fba792013-01-02 23:36:37 -06001935 {&backtrack_class_def,
1936 &input_class_def,
1937 &lookahead_class_def}
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001938 };
1939 return TRACE_RETURN (rule_set.would_apply (c, lookup_context));
1940 }
1941
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05001942 inline const Coverage &get_coverage (void) const
1943 {
1944 return this+coverage;
1945 }
1946
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001947 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04001948 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001949 TRACE_APPLY (this);
Behdad Esfahbodb67881b2012-11-24 19:13:55 -05001950 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001951 if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001952
1953 const ClassDef &backtrack_class_def = this+backtrackClassDef;
1954 const ClassDef &input_class_def = this+inputClassDef;
1955 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
1956
Behdad Esfahbod2dc11412012-11-24 19:16:34 -05001957 index = input_class_def.get_class (c->buffer->cur().codepoint);
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001958 const ChainRuleSet &rule_set = this+ruleSet[index];
Behdad Esfahbod31081f72012-04-23 16:54:58 -04001959 struct ChainContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001960 {match_class},
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -04001961 {&backtrack_class_def,
1962 &input_class_def,
1963 &lookahead_class_def}
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001964 };
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001965 return TRACE_RETURN (rule_set.apply (c, lookup_context));
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001966 }
1967
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001968 inline bool sanitize (hb_sanitize_context_t *c) const
1969 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001970 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02001971 return TRACE_RETURN (coverage.sanitize (c, this) && backtrackClassDef.sanitize (c, this) &&
1972 inputClassDef.sanitize (c, this) && lookaheadClassDef.sanitize (c, this) &&
1973 ruleSet.sanitize (c, this));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04001974 }
1975
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001976 protected:
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001977 USHORT format; /* Format identifier--format = 2 */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001978 OffsetTo<Coverage>
1979 coverage; /* Offset to Coverage table--from
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001980 * beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001981 OffsetTo<ClassDef>
1982 backtrackClassDef; /* Offset to glyph ClassDef table
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001983 * containing backtrack sequence
1984 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001985 OffsetTo<ClassDef>
1986 inputClassDef; /* Offset to glyph ClassDef
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001987 * table containing input sequence
1988 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001989 OffsetTo<ClassDef>
1990 lookaheadClassDef; /* Offset to glyph ClassDef table
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001991 * containing lookahead sequence
1992 * data--from beginning of table */
Behdad Esfahbodaa3d7ad2009-05-17 23:17:56 -04001993 OffsetArrayOf<ChainRuleSet>
1994 ruleSet; /* Array of ChainRuleSet tables
1995 * ordered by class */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001996 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -04001997 DEFINE_SIZE_ARRAY (12, ruleSet);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001998};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04001999
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04002000struct ChainContextFormat3
2001{
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05002002 inline void closure (hb_closure_context_t *c) const
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04002003 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05002004 TRACE_CLOSURE (this);
Behdad Esfahbod5caece62012-04-23 23:03:12 -04002005 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2006
2007 if (!(this+input[0]).intersects (c->glyphs))
2008 return;
2009
2010 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2011 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
2012 struct ChainContextClosureLookupContext lookup_context = {
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05002013 {intersects_coverage},
Behdad Esfahbod5caece62012-04-23 23:03:12 -04002014 {this, this, this}
2015 };
2016 chain_context_closure_lookup (c,
2017 backtrack.len, (const USHORT *) backtrack.array,
2018 input.len, (const USHORT *) input.array + 1,
2019 lookahead.len, (const USHORT *) lookahead.array,
2020 lookup.len, lookup.array,
2021 lookup_context);
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04002022 }
2023
Behdad Esfahbod26514d52012-11-23 18:13:48 -05002024 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
2025 {
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05002026 TRACE_COLLECT_GLYPHS (this);
2027 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2028
Behdad Esfahbod83035932012-12-04 17:08:41 -05002029 (this+input[0]).add_coverage (c->input);
Behdad Esfahbodf1b12782012-11-24 01:55:34 -05002030
2031 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2032 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
2033 struct ChainContextCollectGlyphsLookupContext lookup_context = {
2034 {collect_coverage},
2035 {this, this, this}
2036 };
2037 chain_context_collect_glyphs_lookup (c,
2038 backtrack.len, (const USHORT *) backtrack.array,
2039 input.len, (const USHORT *) input.array + 1,
2040 lookahead.len, (const USHORT *) lookahead.array,
2041 lookup.len, lookup.array,
2042 lookup_context);
Behdad Esfahbod26514d52012-11-23 18:13:48 -05002043 }
2044
Behdad Esfahbode72b3602012-07-19 14:35:23 -04002045 inline bool would_apply (hb_would_apply_context_t *c) const
2046 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05002047 TRACE_WOULD_APPLY (this);
Behdad Esfahbode6f74792012-07-28 18:34:58 -04002048
Behdad Esfahbode72b3602012-07-19 14:35:23 -04002049 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
Behdad Esfahbode72b3602012-07-19 14:35:23 -04002050 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2051 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
2052 struct ChainContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05002053 {match_coverage},
Behdad Esfahbode72b3602012-07-19 14:35:23 -04002054 {this, this, this}
2055 };
2056 return TRACE_RETURN (chain_context_would_apply_lookup (c,
2057 backtrack.len, (const USHORT *) backtrack.array,
2058 input.len, (const USHORT *) input.array + 1,
2059 lookahead.len, (const USHORT *) lookahead.array,
2060 lookup.len, lookup.array, lookup_context));
2061 }
2062
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05002063 inline const Coverage &get_coverage (void) const
2064 {
2065 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2066 return this+input[0];
2067 }
2068
Behdad Esfahbodec35a722012-11-22 16:05:59 -05002069 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04002070 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05002071 TRACE_APPLY (this);
Behdad Esfahbode961c862010-04-21 15:56:11 -04002072 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -04002073
Behdad Esfahbodb67881b2012-11-24 19:13:55 -05002074 unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint);
Behdad Esfahbodacea1832012-05-11 02:33:11 +02002075 if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002076
Behdad Esfahbode961c862010-04-21 15:56:11 -04002077 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2078 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbod31081f72012-04-23 16:54:58 -04002079 struct ChainContextApplyLookupContext lookup_context = {
Behdad Esfahbodec35a722012-11-22 16:05:59 -05002080 {match_coverage},
Behdad Esfahbod40cbefe2010-05-10 17:47:22 -04002081 {this, this, this}
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -04002082 };
Behdad Esfahbodacea1832012-05-11 02:33:11 +02002083 return TRACE_RETURN (chain_context_apply_lookup (c,
2084 backtrack.len, (const USHORT *) backtrack.array,
2085 input.len, (const USHORT *) input.array + 1,
2086 lookahead.len, (const USHORT *) lookahead.array,
2087 lookup.len, lookup.array, lookup_context));
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002088 }
2089
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03002090 inline bool sanitize (hb_sanitize_context_t *c) const
2091 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05002092 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02002093 if (!backtrack.sanitize (c, this)) return TRACE_RETURN (false);
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03002094 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02002095 if (!input.sanitize (c, this)) return TRACE_RETURN (false);
Behdad Esfahbod9df0a522014-12-12 20:54:28 -08002096 if (!input.len) return TRACE_RETURN (false); /* To be consistent with Context. */
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03002097 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02002098 if (!lookahead.sanitize (c, this)) return TRACE_RETURN (false);
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03002099 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02002100 return TRACE_RETURN (lookup.sanitize (c));
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04002101 }
2102
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04002103 protected:
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002104 USHORT format; /* Format identifier--format = 3 */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -04002105 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -04002106 backtrack; /* Array of coverage tables
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002107 * in backtracking sequence, in glyph
2108 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -04002109 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -04002110 inputX ; /* Array of coverage
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002111 * tables in input sequence, in glyph
2112 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -04002113 OffsetArrayOf<Coverage>
Behdad Esfahbod13ed4402009-05-18 02:14:37 -04002114 lookaheadX; /* Array of coverage tables
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002115 * in lookahead sequence, in glyph
2116 * sequence order */
Behdad Esfahboddcb6b602009-05-18 01:49:57 -04002117 ArrayOf<LookupRecord>
Behdad Esfahbod02e1e5c2009-05-18 02:47:57 -04002118 lookupX; /* Array of LookupRecords--in
Behdad Esfahboddcb6b602009-05-18 01:49:57 -04002119 * design order) */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04002120 public:
Behdad Esfahbodbea34c72010-05-10 17:28:16 -04002121 DEFINE_SIZE_MIN (10);
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002122};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002123
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04002124struct ChainContext
2125{
Behdad Esfahbod44fc2372012-11-21 23:33:13 -05002126 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05002127 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04002128 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08002129 TRACE_DISPATCH (this, u.format);
Behdad Esfahbod50b8dc72015-02-17 18:14:17 +03002130 if (unlikely (!c->may_dispatch (this, &u.format))) TRACE_RETURN (c->default_return_value ());
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04002131 switch (u.format) {
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05002132 case 1: return TRACE_RETURN (c->dispatch (u.format1));
2133 case 2: return TRACE_RETURN (c->dispatch (u.format2));
2134 case 3: return TRACE_RETURN (c->dispatch (u.format3));
Behdad Esfahbodf48ec0e2012-11-23 17:23:41 -05002135 default:return TRACE_RETURN (c->default_return_value ());
Behdad Esfahbode72b3602012-07-19 14:35:23 -04002136 }
2137 }
2138
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04002139 protected:
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002140 union {
2141 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04002142 ChainContextFormat1 format1;
2143 ChainContextFormat2 format2;
2144 ChainContextFormat3 format3;
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002145 } u;
2146};
Behdad Esfahbodca5290f2009-05-17 20:48:27 -04002147
2148
Behdad Esfahbod095a1252015-02-19 10:29:41 +03002149template <typename T>
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002150struct ExtensionFormat1
2151{
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002152 inline unsigned int get_type (void) const { return extensionLookupType; }
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002153
Behdad Esfahbod095a1252015-02-19 10:29:41 +03002154 template <typename X>
2155 inline const X& get_subtable (void) const
2156 {
2157 unsigned int offset = extensionOffset;
2158 if (unlikely (!offset)) return Null(typename T::LookupSubTable);
2159 return StructAtOffset<typename T::LookupSubTable> (this, offset);
2160 }
2161
2162 template <typename context_t>
2163 inline typename context_t::return_t dispatch (context_t *c) const
2164 {
2165 TRACE_DISPATCH (this, format);
2166 if (unlikely (!c->may_dispatch (this, this))) TRACE_RETURN (c->default_return_value ());
2167 return get_subtable<typename T::LookupSubTable> ().dispatch (c, get_type ());
2168 }
2169
2170 /* This is called from may_dispatch() above with hb_sanitize_context_t. */
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03002171 inline bool sanitize (hb_sanitize_context_t *c) const
2172 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05002173 TRACE_SANITIZE (this);
Behdad Esfahbod095a1252015-02-19 10:29:41 +03002174 return TRACE_RETURN (c->check_struct (this) && extensionOffset != 0);
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04002175 }
2176
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04002177 protected:
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002178 USHORT format; /* Format identifier. Set to 1. */
2179 USHORT extensionLookupType; /* Lookup type of subtable referenced
2180 * by ExtensionOffset (i.e. the
2181 * extension subtable). */
Behdad Esfahbod81f2af42010-04-22 00:58:49 -04002182 ULONG extensionOffset; /* Offset to the extension subtable,
2183 * of lookup type subtable. */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04002184 public:
2185 DEFINE_SIZE_STATIC (8);
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002186};
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002187
Behdad Esfahbod653eeb22012-11-23 16:57:36 -05002188template <typename T>
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002189struct Extension
2190{
2191 inline unsigned int get_type (void) const
2192 {
2193 switch (u.format) {
Behdad Esfahboddacebca2010-05-10 19:45:41 -04002194 case 1: return u.format1.get_type ();
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002195 default:return 0;
2196 }
2197 }
Behdad Esfahbod7dddd4e2012-11-23 17:04:55 -05002198 template <typename X>
2199 inline const X& get_subtable (void) const
2200 {
Behdad Esfahbod095a1252015-02-19 10:29:41 +03002201 switch (u.format) {
2202 case 1: return u.format1.template get_subtable<typename T::LookupSubTable> ();
2203 default:return Null(typename T::LookupSubTable);
2204 }
Behdad Esfahbod7dddd4e2012-11-23 17:04:55 -05002205 }
2206
Behdad Esfahbod653eeb22012-11-23 16:57:36 -05002207 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05002208 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod653eeb22012-11-23 16:57:36 -05002209 {
Behdad Esfahbod095a1252015-02-19 10:29:41 +03002210 TRACE_DISPATCH (this, u.format);
2211 if (unlikely (!c->may_dispatch (this, &u.format))) TRACE_RETURN (c->default_return_value ());
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04002212 switch (u.format) {
Behdad Esfahbod095a1252015-02-19 10:29:41 +03002213 case 1: return TRACE_RETURN (u.format1.dispatch (c));
2214 default:return TRACE_RETURN (c->default_return_value ());
Behdad Esfahbod70de50c2009-08-04 00:58:28 -04002215 }
2216 }
2217
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04002218 protected:
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002219 union {
2220 USHORT format; /* Format identifier */
Behdad Esfahbod095a1252015-02-19 10:29:41 +03002221 ExtensionFormat1<T> format1;
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002222 } u;
2223};
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04002224
2225
Behdad Esfahbodf45107f2009-05-17 20:13:02 -04002226/*
2227 * GSUB/GPOS Common
2228 */
2229
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -04002230struct GSUBGPOS
2231{
Behdad Esfahboda328d662009-08-04 20:27:05 -04002232 static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB;
2233 static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS;
Behdad Esfahbodf45107f2009-05-17 20:13:02 -04002234
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -04002235 inline unsigned int get_script_count (void) const
2236 { return (this+scriptList).len; }
2237 inline const Tag& get_script_tag (unsigned int i) const
2238 { return (this+scriptList).get_tag (i); }
Behdad Esfahbode21899b2009-11-04 16:36:14 -05002239 inline unsigned int get_script_tags (unsigned int start_offset,
2240 unsigned int *script_count /* IN/OUT */,
2241 hb_tag_t *script_tags /* OUT */) const
2242 { return (this+scriptList).get_tags (start_offset, script_count, script_tags); }
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -04002243 inline const Script& get_script (unsigned int i) const
2244 { return (this+scriptList)[i]; }
2245 inline bool find_script_index (hb_tag_t tag, unsigned int *index) const
2246 { return (this+scriptList).find_index (tag, index); }
Behdad Esfahbodf45107f2009-05-17 20:13:02 -04002247
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -04002248 inline unsigned int get_feature_count (void) const
2249 { return (this+featureList).len; }
Jonathan Kewda132932014-04-27 14:05:24 +01002250 inline hb_tag_t get_feature_tag (unsigned int i) const
2251 { return i == Index::NOT_FOUND_INDEX ? HB_TAG_NONE : (this+featureList).get_tag (i); }
Behdad Esfahbode21899b2009-11-04 16:36:14 -05002252 inline unsigned int get_feature_tags (unsigned int start_offset,
2253 unsigned int *feature_count /* IN/OUT */,
2254 hb_tag_t *feature_tags /* OUT */) const
2255 { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); }
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -04002256 inline const Feature& get_feature (unsigned int i) const
2257 { return (this+featureList)[i]; }
2258 inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const
2259 { return (this+featureList).find_index (tag, index); }
2260
2261 inline unsigned int get_lookup_count (void) const
2262 { return (this+lookupList).len; }
2263 inline const Lookup& get_lookup (unsigned int i) const
2264 { return (this+lookupList)[i]; }
Behdad Esfahbodf45107f2009-05-17 20:13:02 -04002265
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03002266 inline bool sanitize (hb_sanitize_context_t *c) const
2267 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05002268 TRACE_SANITIZE (this);
Behdad Esfahbod0ab8c862012-05-11 01:25:34 +02002269 return TRACE_RETURN (version.sanitize (c) && likely (version.major == 1) &&
2270 scriptList.sanitize (c, this) &&
2271 featureList.sanitize (c, this) &&
2272 lookupList.sanitize (c, this));
Behdad Esfahbodcd3827e2009-08-04 02:09:34 -04002273 }
2274
Behdad Esfahbod212aba62009-05-24 00:50:27 -04002275 protected:
Behdad Esfahbod87fcdcb2009-05-24 01:03:24 -04002276 FixedVersion version; /* Version of the GSUB/GPOS table--initially set
Behdad Esfahbod76271002014-07-11 14:54:42 -04002277 * to 0x00010000u */
Behdad Esfahbodf45107f2009-05-17 20:13:02 -04002278 OffsetTo<ScriptList>
2279 scriptList; /* ScriptList table */
2280 OffsetTo<FeatureList>
2281 featureList; /* FeatureList table */
2282 OffsetTo<LookupList>
2283 lookupList; /* LookupList table */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04002284 public:
2285 DEFINE_SIZE_STATIC (10);
Behdad Esfahbodf45107f2009-05-17 20:13:02 -04002286};
Behdad Esfahbod66bf7ce2009-05-17 08:28:42 -04002287
Behdad Esfahbod6f20f722009-05-17 20:28:01 -04002288
Behdad Esfahbod7d52e662012-11-16 18:49:54 -08002289} /* namespace OT */
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -04002290
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -04002291
Behdad Esfahbod5f5b24f2009-08-02 20:03:12 -04002292#endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */