michael@0: /* michael@0: * Copyright © 2007,2008,2009,2010 Red Hat, Inc. michael@0: * Copyright © 2010,2012 Google, Inc. michael@0: * michael@0: * This is part of HarfBuzz, a text shaping library. michael@0: * michael@0: * Permission is hereby granted, without written agreement and without michael@0: * license or royalty fees, to use, copy, modify, and distribute this michael@0: * software and its documentation for any purpose, provided that the michael@0: * above copyright notice and the following two paragraphs appear in michael@0: * all copies of this software. michael@0: * michael@0: * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR michael@0: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES michael@0: * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN michael@0: * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH michael@0: * DAMAGE. michael@0: * michael@0: * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, michael@0: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND michael@0: * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS michael@0: * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO michael@0: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. michael@0: * michael@0: * Red Hat Author(s): Behdad Esfahbod michael@0: * Google Author(s): Behdad Esfahbod michael@0: */ michael@0: michael@0: #ifndef HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH michael@0: #define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH michael@0: michael@0: #include "hb-buffer-private.hh" michael@0: #include "hb-ot-layout-gdef-table.hh" michael@0: #include "hb-set-private.hh" michael@0: michael@0: michael@0: namespace OT { michael@0: michael@0: michael@0: michael@0: #define TRACE_DISPATCH(this) \ michael@0: hb_auto_trace_t trace \ michael@0: (&c->debug_depth, c->get_name (), this, HB_FUNC, \ michael@0: ""); michael@0: michael@0: #ifndef HB_DEBUG_CLOSURE michael@0: #define HB_DEBUG_CLOSURE (HB_DEBUG+0) michael@0: #endif michael@0: michael@0: #define TRACE_CLOSURE(this) \ michael@0: hb_auto_trace_t trace \ michael@0: (&c->debug_depth, c->get_name (), this, HB_FUNC, \ michael@0: ""); michael@0: michael@0: struct hb_closure_context_t michael@0: { michael@0: inline const char *get_name (void) { return "CLOSURE"; } michael@0: static const unsigned int max_debug_depth = HB_DEBUG_CLOSURE; michael@0: typedef hb_void_t return_t; michael@0: typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); michael@0: template michael@0: inline return_t dispatch (const T &obj) { obj.closure (this); return HB_VOID; } michael@0: static return_t default_return_value (void) { return HB_VOID; } michael@0: bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; } michael@0: return_t recurse (unsigned int lookup_index) michael@0: { michael@0: if (unlikely (nesting_level_left == 0 || !recurse_func)) michael@0: return default_return_value (); michael@0: michael@0: nesting_level_left--; michael@0: recurse_func (this, lookup_index); michael@0: nesting_level_left++; michael@0: return HB_VOID; michael@0: } michael@0: michael@0: hb_face_t *face; michael@0: hb_set_t *glyphs; michael@0: recurse_func_t recurse_func; michael@0: unsigned int nesting_level_left; michael@0: unsigned int debug_depth; michael@0: michael@0: hb_closure_context_t (hb_face_t *face_, michael@0: hb_set_t *glyphs_, michael@0: unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) : michael@0: face (face_), michael@0: glyphs (glyphs_), michael@0: recurse_func (NULL), michael@0: nesting_level_left (nesting_level_left_), michael@0: debug_depth (0) {} michael@0: michael@0: void set_recurse_func (recurse_func_t func) { recurse_func = func; } michael@0: }; michael@0: michael@0: michael@0: michael@0: #ifndef HB_DEBUG_WOULD_APPLY michael@0: #define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0) michael@0: #endif michael@0: michael@0: #define TRACE_WOULD_APPLY(this) \ michael@0: hb_auto_trace_t trace \ michael@0: (&c->debug_depth, c->get_name (), this, HB_FUNC, \ michael@0: "%d glyphs", c->len); michael@0: michael@0: struct hb_would_apply_context_t michael@0: { michael@0: inline const char *get_name (void) { return "WOULD_APPLY"; } michael@0: static const unsigned int max_debug_depth = HB_DEBUG_WOULD_APPLY; michael@0: typedef bool return_t; michael@0: template michael@0: inline return_t dispatch (const T &obj) { return obj.would_apply (this); } michael@0: static return_t default_return_value (void) { return false; } michael@0: bool stop_sublookup_iteration (return_t r) const { return r; } michael@0: michael@0: hb_face_t *face; michael@0: const hb_codepoint_t *glyphs; michael@0: unsigned int len; michael@0: bool zero_context; michael@0: unsigned int debug_depth; michael@0: michael@0: hb_would_apply_context_t (hb_face_t *face_, michael@0: const hb_codepoint_t *glyphs_, michael@0: unsigned int len_, michael@0: bool zero_context_) : michael@0: face (face_), michael@0: glyphs (glyphs_), michael@0: len (len_), michael@0: zero_context (zero_context_), michael@0: debug_depth (0) {} michael@0: }; michael@0: michael@0: michael@0: michael@0: #ifndef HB_DEBUG_COLLECT_GLYPHS michael@0: #define HB_DEBUG_COLLECT_GLYPHS (HB_DEBUG+0) michael@0: #endif michael@0: michael@0: #define TRACE_COLLECT_GLYPHS(this) \ michael@0: hb_auto_trace_t trace \ michael@0: (&c->debug_depth, c->get_name (), this, HB_FUNC, \ michael@0: ""); michael@0: michael@0: struct hb_collect_glyphs_context_t michael@0: { michael@0: inline const char *get_name (void) { return "COLLECT_GLYPHS"; } michael@0: static const unsigned int max_debug_depth = HB_DEBUG_COLLECT_GLYPHS; michael@0: typedef hb_void_t return_t; michael@0: typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index); michael@0: template michael@0: inline return_t dispatch (const T &obj) { obj.collect_glyphs (this); return HB_VOID; } michael@0: static return_t default_return_value (void) { return HB_VOID; } michael@0: bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; } michael@0: return_t recurse (unsigned int lookup_index) michael@0: { michael@0: if (unlikely (nesting_level_left == 0 || !recurse_func)) michael@0: return default_return_value (); michael@0: michael@0: /* Note that GPOS sets recurse_func to NULL already, so it doesn't get michael@0: * past the previous check. For GSUB, we only want to collect the output michael@0: * glyphs in the recursion. If output is not requested, we can go home now. michael@0: * michael@0: * Note further, that the above is not exactly correct. A recursed lookup michael@0: * is allowed to match input that is not matched in the context, but that's michael@0: * not how most fonts are built. It's possible to relax that and recurse michael@0: * with all sets here if it proves to be an issue. michael@0: */ michael@0: michael@0: if (output == hb_set_get_empty ()) michael@0: return HB_VOID; michael@0: michael@0: hb_set_t *old_before = before; michael@0: hb_set_t *old_input = input; michael@0: hb_set_t *old_after = after; michael@0: before = input = after = hb_set_get_empty (); michael@0: michael@0: nesting_level_left--; michael@0: recurse_func (this, lookup_index); michael@0: nesting_level_left++; michael@0: michael@0: before = old_before; michael@0: input = old_input; michael@0: after = old_after; michael@0: michael@0: return HB_VOID; michael@0: } michael@0: michael@0: hb_face_t *face; michael@0: hb_set_t *before; michael@0: hb_set_t *input; michael@0: hb_set_t *after; michael@0: hb_set_t *output; michael@0: recurse_func_t recurse_func; michael@0: unsigned int nesting_level_left; michael@0: unsigned int debug_depth; michael@0: michael@0: hb_collect_glyphs_context_t (hb_face_t *face_, michael@0: hb_set_t *glyphs_before, /* OUT. May be NULL */ michael@0: hb_set_t *glyphs_input, /* OUT. May be NULL */ michael@0: hb_set_t *glyphs_after, /* OUT. May be NULL */ michael@0: hb_set_t *glyphs_output, /* OUT. May be NULL */ michael@0: unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) : michael@0: face (face_), michael@0: before (glyphs_before ? glyphs_before : hb_set_get_empty ()), michael@0: input (glyphs_input ? glyphs_input : hb_set_get_empty ()), michael@0: after (glyphs_after ? glyphs_after : hb_set_get_empty ()), michael@0: output (glyphs_output ? glyphs_output : hb_set_get_empty ()), michael@0: recurse_func (NULL), michael@0: nesting_level_left (nesting_level_left_), michael@0: debug_depth (0) {} michael@0: michael@0: void set_recurse_func (recurse_func_t func) { recurse_func = func; } michael@0: }; michael@0: michael@0: michael@0: michael@0: struct hb_get_coverage_context_t michael@0: { michael@0: inline const char *get_name (void) { return "GET_COVERAGE"; } michael@0: static const unsigned int max_debug_depth = 0; michael@0: typedef const Coverage &return_t; michael@0: template michael@0: inline return_t dispatch (const T &obj) { return obj.get_coverage (); } michael@0: static return_t default_return_value (void) { return Null(Coverage); } michael@0: michael@0: hb_get_coverage_context_t (void) : michael@0: debug_depth (0) {} michael@0: michael@0: unsigned int debug_depth; michael@0: }; michael@0: michael@0: michael@0: michael@0: #ifndef HB_DEBUG_APPLY michael@0: #define HB_DEBUG_APPLY (HB_DEBUG+0) michael@0: #endif michael@0: michael@0: #define TRACE_APPLY(this) \ michael@0: hb_auto_trace_t trace \ michael@0: (&c->debug_depth, c->get_name (), this, HB_FUNC, \ michael@0: "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); michael@0: michael@0: struct hb_apply_context_t michael@0: { michael@0: inline const char *get_name (void) { return "APPLY"; } michael@0: static const unsigned int max_debug_depth = HB_DEBUG_APPLY; michael@0: typedef bool return_t; michael@0: typedef return_t (*recurse_func_t) (hb_apply_context_t *c, unsigned int lookup_index); michael@0: template michael@0: inline return_t dispatch (const T &obj) { return obj.apply (this); } michael@0: static return_t default_return_value (void) { return false; } michael@0: bool stop_sublookup_iteration (return_t r) const { return r; } michael@0: return_t recurse (unsigned int lookup_index) michael@0: { michael@0: if (unlikely (nesting_level_left == 0 || !recurse_func)) michael@0: return default_return_value (); michael@0: michael@0: nesting_level_left--; michael@0: bool ret = recurse_func (this, lookup_index); michael@0: nesting_level_left++; michael@0: return ret; michael@0: } michael@0: michael@0: unsigned int table_index; /* GSUB/GPOS */ michael@0: hb_font_t *font; michael@0: hb_face_t *face; michael@0: hb_buffer_t *buffer; michael@0: hb_direction_t direction; michael@0: hb_mask_t lookup_mask; michael@0: bool auto_zwj; michael@0: recurse_func_t recurse_func; michael@0: unsigned int nesting_level_left; michael@0: unsigned int lookup_props; michael@0: const GDEF &gdef; michael@0: bool has_glyph_classes; michael@0: unsigned int debug_depth; michael@0: michael@0: michael@0: hb_apply_context_t (unsigned int table_index_, michael@0: hb_font_t *font_, michael@0: hb_buffer_t *buffer_) : michael@0: table_index (table_index_), michael@0: font (font_), face (font->face), buffer (buffer_), michael@0: direction (buffer_->props.direction), michael@0: lookup_mask (1), michael@0: auto_zwj (true), michael@0: recurse_func (NULL), michael@0: nesting_level_left (MAX_NESTING_LEVEL), michael@0: lookup_props (0), michael@0: gdef (*hb_ot_layout_from_face (face)->gdef), michael@0: has_glyph_classes (gdef.has_glyph_classes ()), michael@0: debug_depth (0) {} michael@0: michael@0: inline void set_lookup_mask (hb_mask_t mask) { lookup_mask = mask; } michael@0: inline void set_auto_zwj (bool auto_zwj_) { auto_zwj = auto_zwj_; } michael@0: inline void set_recurse_func (recurse_func_t func) { recurse_func = func; } michael@0: inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; } michael@0: inline void set_lookup (const Lookup &l) { lookup_props = l.get_props (); } michael@0: michael@0: struct matcher_t michael@0: { michael@0: inline matcher_t (void) : michael@0: lookup_props (0), michael@0: ignore_zwnj (false), michael@0: ignore_zwj (false), michael@0: mask (-1), michael@0: #define arg1(arg) (arg) /* Remove the macro to see why it's needed! */ michael@0: syllable arg1(0), michael@0: #undef arg1 michael@0: match_func (NULL), michael@0: match_data (NULL) {}; michael@0: michael@0: typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data); michael@0: michael@0: inline void set_ignore_zwnj (bool ignore_zwnj_) { ignore_zwnj = ignore_zwnj_; } michael@0: inline void set_ignore_zwj (bool ignore_zwj_) { ignore_zwj = ignore_zwj_; } michael@0: inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; } michael@0: inline void set_mask (hb_mask_t mask_) { mask = mask_; } michael@0: inline void set_syllable (uint8_t syllable_) { syllable = syllable_; } michael@0: inline void set_match_func (match_func_t match_func_, michael@0: const void *match_data_) michael@0: { match_func = match_func_; match_data = match_data_; } michael@0: michael@0: enum may_match_t { michael@0: MATCH_NO, michael@0: MATCH_YES, michael@0: MATCH_MAYBE michael@0: }; michael@0: michael@0: inline may_match_t may_match (const hb_glyph_info_t &info, michael@0: const USHORT *glyph_data) const michael@0: { michael@0: if (!(info.mask & mask) || michael@0: (syllable && syllable != info.syllable ())) michael@0: return MATCH_NO; michael@0: michael@0: if (match_func) michael@0: return match_func (info.codepoint, *glyph_data, match_data) ? MATCH_YES : MATCH_NO; michael@0: michael@0: return MATCH_MAYBE; michael@0: } michael@0: michael@0: enum may_skip_t { michael@0: SKIP_NO, michael@0: SKIP_YES, michael@0: SKIP_MAYBE michael@0: }; michael@0: michael@0: inline may_skip_t michael@0: may_skip (const hb_apply_context_t *c, michael@0: const hb_glyph_info_t &info) const michael@0: { michael@0: unsigned int property; michael@0: michael@0: property = _hb_glyph_info_get_glyph_props (&info); michael@0: michael@0: if (!c->match_properties (info.codepoint, property, lookup_props)) michael@0: return SKIP_YES; michael@0: michael@0: if (unlikely (_hb_glyph_info_is_default_ignorable (&info) && michael@0: (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info)) && michael@0: (ignore_zwj || !_hb_glyph_info_is_zwj (&info)) && michael@0: !_hb_glyph_info_ligated (&info))) michael@0: return SKIP_MAYBE; michael@0: michael@0: return SKIP_NO; michael@0: } michael@0: michael@0: protected: michael@0: unsigned int lookup_props; michael@0: bool ignore_zwnj; michael@0: bool ignore_zwj; michael@0: hb_mask_t mask; michael@0: uint8_t syllable; michael@0: match_func_t match_func; michael@0: const void *match_data; michael@0: }; michael@0: michael@0: struct skipping_forward_iterator_t michael@0: { michael@0: inline skipping_forward_iterator_t (hb_apply_context_t *c_, michael@0: unsigned int start_index_, michael@0: unsigned int num_items_, michael@0: bool context_match = false) : michael@0: idx (start_index_), michael@0: c (c_), michael@0: match_glyph_data (NULL), michael@0: num_items (num_items_), michael@0: end (c->buffer->len) michael@0: { michael@0: matcher.set_lookup_props (c->lookup_props); michael@0: /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */ michael@0: matcher.set_ignore_zwnj (context_match || c->table_index == 1); michael@0: /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */ michael@0: matcher.set_ignore_zwj (context_match || c->table_index == 1 || c->auto_zwj); michael@0: if (!context_match) michael@0: matcher.set_mask (c->lookup_mask); michael@0: matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0); michael@0: } michael@0: inline void set_lookup_props (unsigned int lookup_props) { matcher.set_lookup_props (lookup_props); } michael@0: inline void set_syllable (unsigned int syllable) { matcher.set_syllable (syllable); } michael@0: inline void set_match_func (matcher_t::match_func_t match_func, michael@0: const void *match_data, michael@0: const USHORT glyph_data[]) michael@0: { michael@0: matcher.set_match_func (match_func, match_data); michael@0: match_glyph_data = glyph_data; michael@0: } michael@0: michael@0: inline bool has_no_chance (void) const { return unlikely (num_items && idx + num_items >= end); } michael@0: inline void reject (void) { num_items++; match_glyph_data--; } michael@0: inline bool next (void) michael@0: { michael@0: assert (num_items > 0); michael@0: while (!has_no_chance ()) michael@0: { michael@0: idx++; michael@0: const hb_glyph_info_t &info = c->buffer->info[idx]; michael@0: michael@0: matcher_t::may_skip_t skip = matcher.may_skip (c, info); michael@0: if (unlikely (skip == matcher_t::SKIP_YES)) michael@0: continue; michael@0: michael@0: matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data); michael@0: if (match == matcher_t::MATCH_YES || michael@0: (match == matcher_t::MATCH_MAYBE && michael@0: skip == matcher_t::SKIP_NO)) michael@0: { michael@0: num_items--; michael@0: match_glyph_data++; michael@0: return true; michael@0: } michael@0: michael@0: if (skip == matcher_t::SKIP_NO) michael@0: return false; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: unsigned int idx; michael@0: protected: michael@0: hb_apply_context_t *c; michael@0: matcher_t matcher; michael@0: const USHORT *match_glyph_data; michael@0: michael@0: unsigned int num_items; michael@0: unsigned int end; michael@0: }; michael@0: michael@0: struct skipping_backward_iterator_t michael@0: { michael@0: inline skipping_backward_iterator_t (hb_apply_context_t *c_, michael@0: unsigned int start_index_, michael@0: unsigned int num_items_, michael@0: bool context_match = false) : michael@0: idx (start_index_), michael@0: c (c_), michael@0: match_glyph_data (NULL), michael@0: num_items (num_items_) michael@0: { michael@0: matcher.set_lookup_props (c->lookup_props); michael@0: /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */ michael@0: matcher.set_ignore_zwnj (context_match || c->table_index == 1); michael@0: /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */ michael@0: matcher.set_ignore_zwj (context_match || c->table_index == 1 || c->auto_zwj); michael@0: if (!context_match) michael@0: matcher.set_mask (c->lookup_mask); michael@0: matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0); michael@0: } michael@0: inline void set_lookup_props (unsigned int lookup_props) { matcher.set_lookup_props (lookup_props); } michael@0: inline void set_syllable (unsigned int syllable) { matcher.set_syllable (syllable); } michael@0: inline void set_match_func (matcher_t::match_func_t match_func, michael@0: const void *match_data, michael@0: const USHORT glyph_data[]) michael@0: { michael@0: matcher.set_match_func (match_func, match_data); michael@0: match_glyph_data = glyph_data; michael@0: } michael@0: michael@0: inline bool has_no_chance (void) const { return unlikely (idx < num_items); } michael@0: inline void reject (void) { num_items++; } michael@0: inline bool prev (void) michael@0: { michael@0: assert (num_items > 0); michael@0: while (!has_no_chance ()) michael@0: { michael@0: idx--; michael@0: const hb_glyph_info_t &info = c->buffer->out_info[idx]; michael@0: michael@0: matcher_t::may_skip_t skip = matcher.may_skip (c, info); michael@0: michael@0: if (unlikely (skip == matcher_t::SKIP_YES)) michael@0: continue; michael@0: michael@0: matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data); michael@0: if (match == matcher_t::MATCH_YES || michael@0: (match == matcher_t::MATCH_MAYBE && michael@0: skip == matcher_t::SKIP_NO)) michael@0: { michael@0: num_items--; michael@0: match_glyph_data++; michael@0: return true; michael@0: } michael@0: michael@0: if (skip == matcher_t::SKIP_NO) michael@0: return false; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: unsigned int idx; michael@0: protected: michael@0: hb_apply_context_t *c; michael@0: matcher_t matcher; michael@0: const USHORT *match_glyph_data; michael@0: michael@0: unsigned int num_items; michael@0: }; michael@0: michael@0: inline bool michael@0: match_properties_mark (hb_codepoint_t glyph, michael@0: unsigned int glyph_props, michael@0: unsigned int lookup_props) const michael@0: { michael@0: /* If using mark filtering sets, the high short of michael@0: * lookup_props has the set index. michael@0: */ michael@0: if (lookup_props & LookupFlag::UseMarkFilteringSet) michael@0: return gdef.mark_set_covers (lookup_props >> 16, glyph); michael@0: michael@0: /* The second byte of lookup_props has the meaning michael@0: * "ignore marks of attachment type different than michael@0: * the attachment type specified." michael@0: */ michael@0: if (lookup_props & LookupFlag::MarkAttachmentType) michael@0: return (lookup_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: inline bool michael@0: match_properties (hb_codepoint_t glyph, michael@0: unsigned int glyph_props, michael@0: unsigned int lookup_props) const michael@0: { michael@0: /* Not covered, if, for example, glyph class is ligature and michael@0: * lookup_props includes LookupFlags::IgnoreLigatures michael@0: */ michael@0: if (glyph_props & lookup_props & LookupFlag::IgnoreFlags) michael@0: return false; michael@0: michael@0: if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) michael@0: return match_properties_mark (glyph, glyph_props, lookup_props); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: inline bool michael@0: check_glyph_property (hb_glyph_info_t *info, michael@0: unsigned int lookup_props) const michael@0: { michael@0: unsigned int property; michael@0: michael@0: property = _hb_glyph_info_get_glyph_props (info); michael@0: michael@0: return match_properties (info->codepoint, property, lookup_props); michael@0: } michael@0: michael@0: inline void _set_glyph_props (hb_codepoint_t glyph_index, michael@0: unsigned int class_guess = 0, michael@0: bool ligature = false) const michael@0: { michael@0: unsigned int add_in = _hb_glyph_info_get_glyph_props (&buffer->cur()) & michael@0: HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE; michael@0: add_in |= HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED; michael@0: if (ligature) michael@0: add_in |= HB_OT_LAYOUT_GLYPH_PROPS_LIGATED; michael@0: if (likely (has_glyph_classes)) michael@0: _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | gdef.get_glyph_props (glyph_index)); michael@0: else if (class_guess) michael@0: _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | class_guess); michael@0: } michael@0: michael@0: inline void replace_glyph (hb_codepoint_t glyph_index) const michael@0: { michael@0: _set_glyph_props (glyph_index); michael@0: buffer->replace_glyph (glyph_index); michael@0: } michael@0: inline void replace_glyph_inplace (hb_codepoint_t glyph_index) const michael@0: { michael@0: _set_glyph_props (glyph_index); michael@0: buffer->cur().codepoint = glyph_index; michael@0: } michael@0: inline void replace_glyph_with_ligature (hb_codepoint_t glyph_index, michael@0: unsigned int class_guess) const michael@0: { michael@0: _set_glyph_props (glyph_index, class_guess, true); michael@0: buffer->replace_glyph (glyph_index); michael@0: } michael@0: inline void output_glyph (hb_codepoint_t glyph_index, michael@0: unsigned int class_guess) const michael@0: { michael@0: _set_glyph_props (glyph_index, class_guess); michael@0: buffer->output_glyph (glyph_index); michael@0: } michael@0: }; michael@0: michael@0: michael@0: michael@0: typedef bool (*intersects_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data); michael@0: typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data); michael@0: typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data); michael@0: michael@0: struct ContextClosureFuncs michael@0: { michael@0: intersects_func_t intersects; michael@0: }; michael@0: struct ContextCollectGlyphsFuncs michael@0: { michael@0: collect_glyphs_func_t collect; michael@0: }; michael@0: struct ContextApplyFuncs michael@0: { michael@0: match_func_t match; michael@0: }; michael@0: michael@0: michael@0: static inline bool intersects_glyph (hb_set_t *glyphs, const USHORT &value, const void *data HB_UNUSED) michael@0: { michael@0: return glyphs->has (value); michael@0: } michael@0: static inline bool intersects_class (hb_set_t *glyphs, const USHORT &value, const void *data) michael@0: { michael@0: const ClassDef &class_def = *reinterpret_cast(data); michael@0: return class_def.intersects_class (glyphs, value); michael@0: } michael@0: static inline bool intersects_coverage (hb_set_t *glyphs, const USHORT &value, const void *data) michael@0: { michael@0: const OffsetTo &coverage = (const OffsetTo&)value; michael@0: return (data+coverage).intersects (glyphs); michael@0: } michael@0: michael@0: static inline bool intersects_array (hb_closure_context_t *c, michael@0: unsigned int count, michael@0: const USHORT values[], michael@0: intersects_func_t intersects_func, michael@0: const void *intersects_data) michael@0: { michael@0: for (unsigned int i = 0; i < count; i++) michael@0: if (likely (!intersects_func (c->glyphs, values[i], intersects_data))) michael@0: return false; michael@0: return true; michael@0: } michael@0: michael@0: michael@0: static inline void collect_glyph (hb_set_t *glyphs, const USHORT &value, const void *data HB_UNUSED) michael@0: { michael@0: glyphs->add (value); michael@0: } michael@0: static inline void collect_class (hb_set_t *glyphs, const USHORT &value, const void *data) michael@0: { michael@0: const ClassDef &class_def = *reinterpret_cast(data); michael@0: class_def.add_class (glyphs, value); michael@0: } michael@0: static inline void collect_coverage (hb_set_t *glyphs, const USHORT &value, const void *data) michael@0: { michael@0: const OffsetTo &coverage = (const OffsetTo&)value; michael@0: (data+coverage).add_coverage (glyphs); michael@0: } michael@0: static inline void collect_array (hb_collect_glyphs_context_t *c HB_UNUSED, michael@0: hb_set_t *glyphs, michael@0: unsigned int count, michael@0: const USHORT values[], michael@0: collect_glyphs_func_t collect_func, michael@0: const void *collect_data) michael@0: { michael@0: for (unsigned int i = 0; i < count; i++) michael@0: collect_func (glyphs, values[i], collect_data); michael@0: } michael@0: michael@0: michael@0: static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, const void *data HB_UNUSED) michael@0: { michael@0: return glyph_id == value; michael@0: } michael@0: static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, const void *data) michael@0: { michael@0: const ClassDef &class_def = *reinterpret_cast(data); michael@0: return class_def.get_class (glyph_id) == value; michael@0: } michael@0: static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, const void *data) michael@0: { michael@0: const OffsetTo &coverage = (const OffsetTo&)value; michael@0: return (data+coverage).get_coverage (glyph_id) != NOT_COVERED; michael@0: } michael@0: michael@0: static inline bool would_match_input (hb_would_apply_context_t *c, michael@0: unsigned int count, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: match_func_t match_func, michael@0: const void *match_data) michael@0: { michael@0: if (count != c->len) michael@0: return false; michael@0: michael@0: for (unsigned int i = 1; i < count; i++) michael@0: if (likely (!match_func (c->glyphs[i], input[i - 1], match_data))) michael@0: return false; michael@0: michael@0: return true; michael@0: } michael@0: static inline bool match_input (hb_apply_context_t *c, michael@0: unsigned int count, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: match_func_t match_func, michael@0: const void *match_data, michael@0: unsigned int *end_offset, michael@0: unsigned int match_positions[MAX_CONTEXT_LENGTH], michael@0: bool *p_is_mark_ligature = NULL, michael@0: unsigned int *p_total_component_count = NULL) michael@0: { michael@0: TRACE_APPLY (NULL); michael@0: michael@0: if (unlikely (count > MAX_CONTEXT_LENGTH)) TRACE_RETURN (false); michael@0: michael@0: hb_buffer_t *buffer = c->buffer; michael@0: michael@0: hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, buffer->idx, count - 1); michael@0: skippy_iter.set_match_func (match_func, match_data, input); michael@0: if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); michael@0: michael@0: /* michael@0: * This is perhaps the trickiest part of OpenType... Remarks: michael@0: * michael@0: * - If all components of the ligature were marks, we call this a mark ligature. michael@0: * michael@0: * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize michael@0: * it as a ligature glyph. michael@0: * michael@0: * - Ligatures cannot be formed across glyphs attached to different components michael@0: * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and michael@0: * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother. michael@0: * However, it would be wrong to ligate that SHADDA,FATHA sequence.o michael@0: * There is an exception to this: If a ligature tries ligating with marks that michael@0: * belong to it itself, go ahead, assuming that the font designer knows what michael@0: * they are doing (otherwise it can break Indic stuff when a matra wants to michael@0: * ligate with a conjunct...) michael@0: */ michael@0: michael@0: bool is_mark_ligature = _hb_glyph_info_is_mark (&buffer->cur()); michael@0: michael@0: unsigned int total_component_count = 0; michael@0: total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->cur()); michael@0: michael@0: unsigned int first_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); michael@0: unsigned int first_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->cur()); michael@0: michael@0: match_positions[0] = buffer->idx; michael@0: for (unsigned int i = 1; i < count; i++) michael@0: { michael@0: if (!skippy_iter.next ()) return TRACE_RETURN (false); michael@0: michael@0: match_positions[i] = skippy_iter.idx; michael@0: michael@0: unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]); michael@0: unsigned int this_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]); michael@0: michael@0: if (first_lig_id && first_lig_comp) { michael@0: /* If first component was attached to a previous ligature component, michael@0: * all subsequent components should be attached to the same ligature michael@0: * component, otherwise we shouldn't ligate them. */ michael@0: if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp) michael@0: return TRACE_RETURN (false); michael@0: } else { michael@0: /* If first component was NOT attached to a previous ligature component, michael@0: * all subsequent components should also NOT be attached to any ligature michael@0: * component, unless they are attached to the first component itself! */ michael@0: if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id)) michael@0: return TRACE_RETURN (false); michael@0: } michael@0: michael@0: is_mark_ligature = is_mark_ligature && _hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx]); michael@0: total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->info[skippy_iter.idx]); michael@0: } michael@0: michael@0: *end_offset = skippy_iter.idx - buffer->idx + 1; michael@0: michael@0: if (p_is_mark_ligature) michael@0: *p_is_mark_ligature = is_mark_ligature; michael@0: michael@0: if (p_total_component_count) michael@0: *p_total_component_count = total_component_count; michael@0: michael@0: return TRACE_RETURN (true); michael@0: } michael@0: static inline void ligate_input (hb_apply_context_t *c, michael@0: unsigned int count, /* Including the first glyph */ michael@0: unsigned int match_positions[MAX_CONTEXT_LENGTH], /* Including the first glyph */ michael@0: unsigned int match_length, michael@0: hb_codepoint_t lig_glyph, michael@0: bool is_mark_ligature, michael@0: unsigned int total_component_count) michael@0: { michael@0: TRACE_APPLY (NULL); michael@0: michael@0: hb_buffer_t *buffer = c->buffer; michael@0: michael@0: buffer->merge_clusters (buffer->idx, buffer->idx + match_length); michael@0: michael@0: /* michael@0: * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave michael@0: * the ligature to keep its old ligature id. This will allow it to attach to michael@0: * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH, michael@0: * and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a michael@0: * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature michael@0: * later, we don't want them to lose their ligature id/component, otherwise michael@0: * GPOS will fail to correctly position the mark ligature on top of the michael@0: * LAM,LAM,HEH ligature. See: michael@0: * https://bugzilla.gnome.org/show_bug.cgi?id=676343 michael@0: * michael@0: * - If a ligature is formed of components that some of which are also ligatures michael@0: * themselves, and those ligature components had marks attached to *their* michael@0: * components, we have to attach the marks to the new ligature component michael@0: * positions! Now *that*'s tricky! And these marks may be following the michael@0: * last component of the whole sequence, so we should loop forward looking michael@0: * for them and update them. michael@0: * michael@0: * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a michael@0: * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature michael@0: * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature michael@0: * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to michael@0: * the new ligature with a component value of 2. michael@0: * michael@0: * This in fact happened to a font... See: michael@0: * https://bugzilla.gnome.org/show_bug.cgi?id=437633 michael@0: */ michael@0: michael@0: unsigned int klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE; michael@0: unsigned int lig_id = is_mark_ligature ? 0 : _hb_allocate_lig_id (buffer); michael@0: unsigned int last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); michael@0: unsigned int last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur()); michael@0: unsigned int components_so_far = last_num_components; michael@0: michael@0: if (!is_mark_ligature) michael@0: { michael@0: _hb_glyph_info_set_lig_props_for_ligature (&buffer->cur(), lig_id, total_component_count); michael@0: if (_hb_glyph_info_get_general_category (&buffer->cur()) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) michael@0: { michael@0: _hb_glyph_info_set_general_category (&buffer->cur(), HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER); michael@0: _hb_glyph_info_set_modified_combining_class (&buffer->cur(), 0); michael@0: } michael@0: } michael@0: c->replace_glyph_with_ligature (lig_glyph, klass); michael@0: michael@0: for (unsigned int i = 1; i < count; i++) michael@0: { michael@0: while (buffer->idx < match_positions[i]) michael@0: { michael@0: if (!is_mark_ligature) { michael@0: unsigned int new_lig_comp = components_so_far - last_num_components + michael@0: MIN (MAX (_hb_glyph_info_get_lig_comp (&buffer->cur()), 1u), last_num_components); michael@0: _hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp); michael@0: } michael@0: buffer->next_glyph (); michael@0: } michael@0: michael@0: last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); michael@0: last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur()); michael@0: components_so_far += last_num_components; michael@0: michael@0: /* Skip the base glyph */ michael@0: buffer->idx++; michael@0: } michael@0: michael@0: if (!is_mark_ligature && last_lig_id) { michael@0: /* Re-adjust components for any marks following. */ michael@0: for (unsigned int i = buffer->idx; i < buffer->len; i++) { michael@0: if (last_lig_id == _hb_glyph_info_get_lig_id (&buffer->info[i])) { michael@0: unsigned int new_lig_comp = components_so_far - last_num_components + michael@0: MIN (MAX (_hb_glyph_info_get_lig_comp (&buffer->info[i]), 1u), last_num_components); michael@0: _hb_glyph_info_set_lig_props_for_mark (&buffer->info[i], lig_id, new_lig_comp); michael@0: } else michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: michael@0: static inline bool match_backtrack (hb_apply_context_t *c, michael@0: unsigned int count, michael@0: const USHORT backtrack[], michael@0: match_func_t match_func, michael@0: const void *match_data) michael@0: { michael@0: TRACE_APPLY (NULL); michael@0: michael@0: hb_apply_context_t::skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true); michael@0: skippy_iter.set_match_func (match_func, match_data, backtrack); michael@0: if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); michael@0: michael@0: for (unsigned int i = 0; i < count; i++) michael@0: if (!skippy_iter.prev ()) michael@0: return TRACE_RETURN (false); michael@0: michael@0: return TRACE_RETURN (true); michael@0: } michael@0: michael@0: static inline bool match_lookahead (hb_apply_context_t *c, michael@0: unsigned int count, michael@0: const USHORT lookahead[], michael@0: match_func_t match_func, michael@0: const void *match_data, michael@0: unsigned int offset) michael@0: { michael@0: TRACE_APPLY (NULL); michael@0: michael@0: hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true); michael@0: skippy_iter.set_match_func (match_func, match_data, lookahead); michael@0: if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); michael@0: michael@0: for (unsigned int i = 0; i < count; i++) michael@0: if (!skippy_iter.next ()) michael@0: return TRACE_RETURN (false); michael@0: michael@0: return TRACE_RETURN (true); michael@0: } michael@0: michael@0: michael@0: michael@0: struct LookupRecord michael@0: { michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (c->check_struct (this)); michael@0: } michael@0: michael@0: USHORT sequenceIndex; /* Index into current glyph michael@0: * sequence--first glyph = 0 */ michael@0: USHORT lookupListIndex; /* Lookup to apply to that michael@0: * position--zero--based */ michael@0: public: michael@0: DEFINE_SIZE_STATIC (4); michael@0: }; michael@0: michael@0: michael@0: template michael@0: static inline void recurse_lookups (context_t *c, michael@0: unsigned int lookupCount, michael@0: const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */) michael@0: { michael@0: for (unsigned int i = 0; i < lookupCount; i++) michael@0: c->recurse (lookupRecord[i].lookupListIndex); michael@0: } michael@0: michael@0: static inline bool apply_lookup (hb_apply_context_t *c, michael@0: unsigned int count, /* Including the first glyph */ michael@0: unsigned int match_positions[MAX_CONTEXT_LENGTH], /* Including the first glyph */ michael@0: unsigned int lookupCount, michael@0: const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ michael@0: unsigned int match_length) michael@0: { michael@0: TRACE_APPLY (NULL); michael@0: michael@0: hb_buffer_t *buffer = c->buffer; michael@0: unsigned int end; michael@0: michael@0: /* All positions are distance from beginning of *output* buffer. michael@0: * Adjust. */ michael@0: { michael@0: unsigned int bl = buffer->backtrack_len (); michael@0: end = bl + match_length; michael@0: michael@0: int delta = bl - buffer->idx; michael@0: /* Convert positions to new indexing. */ michael@0: for (unsigned int j = 0; j < count; j++) michael@0: match_positions[j] += delta; michael@0: } michael@0: michael@0: for (unsigned int i = 0; i < lookupCount; i++) michael@0: { michael@0: unsigned int idx = lookupRecord[i].sequenceIndex; michael@0: if (idx >= count) michael@0: continue; michael@0: michael@0: buffer->move_to (match_positions[idx]); michael@0: michael@0: unsigned int orig_len = buffer->backtrack_len () + buffer->lookahead_len (); michael@0: if (!c->recurse (lookupRecord[i].lookupListIndex)) michael@0: continue; michael@0: michael@0: unsigned int new_len = buffer->backtrack_len () + buffer->lookahead_len (); michael@0: int delta = new_len - orig_len; michael@0: michael@0: if (!delta) michael@0: continue; michael@0: michael@0: /* Recursed lookup changed buffer len. Adjust. */ michael@0: michael@0: /* end can't go back past the current match position. */ michael@0: end = MAX ((int) match_positions[idx] + 1, int (end) + delta); michael@0: michael@0: unsigned int next = idx + 1; /* next now is the position after the recursed lookup. */ michael@0: michael@0: if (delta > 0) michael@0: { michael@0: if (unlikely (delta + count > MAX_CONTEXT_LENGTH)) michael@0: break; michael@0: } michael@0: else michael@0: { michael@0: /* NOTE: delta is negative. */ michael@0: delta = MAX (delta, (int) next - (int) count); michael@0: next -= delta; michael@0: } michael@0: michael@0: /* Shift! */ michael@0: memmove (match_positions + next + delta, match_positions + next, michael@0: (count - next) * sizeof (match_positions[0])); michael@0: next += delta; michael@0: count += delta; michael@0: michael@0: /* Fill in new entries. */ michael@0: for (unsigned int j = idx + 1; j < next; j++) michael@0: match_positions[j] = match_positions[j - 1] + 1; michael@0: michael@0: /* And fixup the rest. */ michael@0: for (; next < count; next++) michael@0: match_positions[next] += delta; michael@0: } michael@0: michael@0: buffer->move_to (end); michael@0: michael@0: return TRACE_RETURN (true); michael@0: } michael@0: michael@0: michael@0: michael@0: /* Contextual lookups */ michael@0: michael@0: struct ContextClosureLookupContext michael@0: { michael@0: ContextClosureFuncs funcs; michael@0: const void *intersects_data; michael@0: }; michael@0: michael@0: struct ContextCollectGlyphsLookupContext michael@0: { michael@0: ContextCollectGlyphsFuncs funcs; michael@0: const void *collect_data; michael@0: }; michael@0: michael@0: struct ContextApplyLookupContext michael@0: { michael@0: ContextApplyFuncs funcs; michael@0: const void *match_data; michael@0: }; michael@0: michael@0: static inline void context_closure_lookup (hb_closure_context_t *c, michael@0: unsigned int inputCount, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: unsigned int lookupCount, michael@0: const LookupRecord lookupRecord[], michael@0: ContextClosureLookupContext &lookup_context) michael@0: { michael@0: if (intersects_array (c, michael@0: inputCount ? inputCount - 1 : 0, input, michael@0: lookup_context.funcs.intersects, lookup_context.intersects_data)) michael@0: recurse_lookups (c, michael@0: lookupCount, lookupRecord); michael@0: } michael@0: michael@0: static inline void context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c, michael@0: unsigned int inputCount, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: unsigned int lookupCount, michael@0: const LookupRecord lookupRecord[], michael@0: ContextCollectGlyphsLookupContext &lookup_context) michael@0: { michael@0: collect_array (c, c->input, michael@0: inputCount ? inputCount - 1 : 0, input, michael@0: lookup_context.funcs.collect, lookup_context.collect_data); michael@0: recurse_lookups (c, michael@0: lookupCount, lookupRecord); michael@0: } michael@0: michael@0: static inline bool context_would_apply_lookup (hb_would_apply_context_t *c, michael@0: unsigned int inputCount, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: unsigned int lookupCount HB_UNUSED, michael@0: const LookupRecord lookupRecord[] HB_UNUSED, michael@0: ContextApplyLookupContext &lookup_context) michael@0: { michael@0: return would_match_input (c, michael@0: inputCount, input, michael@0: lookup_context.funcs.match, lookup_context.match_data); michael@0: } michael@0: static inline bool context_apply_lookup (hb_apply_context_t *c, michael@0: unsigned int inputCount, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: unsigned int lookupCount, michael@0: const LookupRecord lookupRecord[], michael@0: ContextApplyLookupContext &lookup_context) michael@0: { michael@0: unsigned int match_length = 0; michael@0: unsigned int match_positions[MAX_CONTEXT_LENGTH]; michael@0: return match_input (c, michael@0: inputCount, input, michael@0: lookup_context.funcs.match, lookup_context.match_data, michael@0: &match_length, match_positions) michael@0: && apply_lookup (c, michael@0: inputCount, match_positions, michael@0: lookupCount, lookupRecord, michael@0: match_length); michael@0: } michael@0: michael@0: struct Rule michael@0: { michael@0: inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: const LookupRecord *lookupRecord = &StructAtOffset (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); michael@0: context_closure_lookup (c, michael@0: inputCount, input, michael@0: lookupCount, lookupRecord, michael@0: lookup_context); michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: const LookupRecord *lookupRecord = &StructAtOffset (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); michael@0: context_collect_glyphs_lookup (c, michael@0: inputCount, input, michael@0: lookupCount, lookupRecord, michael@0: lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: const LookupRecord *lookupRecord = &StructAtOffset (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); michael@0: return TRACE_RETURN (context_would_apply_lookup (c, inputCount, input, lookupCount, lookupRecord, lookup_context)); michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: const LookupRecord *lookupRecord = &StructAtOffset (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); michael@0: return TRACE_RETURN (context_apply_lookup (c, inputCount, input, lookupCount, lookupRecord, lookup_context)); michael@0: } michael@0: michael@0: public: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return inputCount.sanitize (c) michael@0: && lookupCount.sanitize (c) michael@0: && c->check_range (input, michael@0: input[0].static_size * inputCount michael@0: + lookupRecordX[0].static_size * lookupCount); michael@0: } michael@0: michael@0: protected: michael@0: USHORT inputCount; /* Total number of glyphs in input michael@0: * glyph sequence--includes the first michael@0: * glyph */ michael@0: USHORT lookupCount; /* Number of LookupRecords */ michael@0: USHORT input[VAR]; /* Array of match inputs--start with michael@0: * second glyph */ michael@0: LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in michael@0: * design order */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY2 (4, input, lookupRecordX); michael@0: }; michael@0: michael@0: struct RuleSet michael@0: { michael@0: inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: unsigned int num_rules = rule.len; michael@0: for (unsigned int i = 0; i < num_rules; i++) michael@0: (this+rule[i]).closure (c, lookup_context); michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: unsigned int num_rules = rule.len; michael@0: for (unsigned int i = 0; i < num_rules; i++) michael@0: (this+rule[i]).collect_glyphs (c, lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: unsigned int num_rules = rule.len; michael@0: for (unsigned int i = 0; i < num_rules; i++) michael@0: { michael@0: if ((this+rule[i]).would_apply (c, lookup_context)) michael@0: return TRACE_RETURN (true); michael@0: } michael@0: return TRACE_RETURN (false); michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: unsigned int num_rules = rule.len; michael@0: for (unsigned int i = 0; i < num_rules; i++) michael@0: { michael@0: if ((this+rule[i]).apply (c, lookup_context)) michael@0: return TRACE_RETURN (true); michael@0: } michael@0: return TRACE_RETURN (false); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (rule.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: OffsetArrayOf michael@0: rule; /* Array of Rule tables michael@0: * ordered by preference */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (2, rule); michael@0: }; michael@0: michael@0: michael@0: struct ContextFormat1 michael@0: { michael@0: inline void closure (hb_closure_context_t *c) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: michael@0: const Coverage &cov = (this+coverage); michael@0: michael@0: struct ContextClosureLookupContext lookup_context = { michael@0: {intersects_glyph}, michael@0: NULL michael@0: }; michael@0: michael@0: unsigned int count = ruleSet.len; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: if (cov.intersects_coverage (c->glyphs, i)) { michael@0: const RuleSet &rule_set = this+ruleSet[i]; michael@0: rule_set.closure (c, lookup_context); michael@0: } michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: (this+coverage).add_coverage (c->input); michael@0: michael@0: struct ContextCollectGlyphsLookupContext lookup_context = { michael@0: {collect_glyph}, michael@0: NULL michael@0: }; michael@0: michael@0: unsigned int count = ruleSet.len; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: (this+ruleSet[i]).collect_glyphs (c, lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: michael@0: const RuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])]; michael@0: struct ContextApplyLookupContext lookup_context = { michael@0: {match_glyph}, michael@0: NULL michael@0: }; michael@0: return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); michael@0: } michael@0: michael@0: inline const Coverage &get_coverage (void) const michael@0: { michael@0: return this+coverage; michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); michael@0: if (likely (index == NOT_COVERED)) michael@0: return TRACE_RETURN (false); michael@0: michael@0: const RuleSet &rule_set = this+ruleSet[index]; michael@0: struct ContextApplyLookupContext lookup_context = { michael@0: {match_glyph}, michael@0: NULL michael@0: }; michael@0: return TRACE_RETURN (rule_set.apply (c, lookup_context)); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT format; /* Format identifier--format = 1 */ michael@0: OffsetTo michael@0: coverage; /* Offset to Coverage table--from michael@0: * beginning of table */ michael@0: OffsetArrayOf michael@0: ruleSet; /* Array of RuleSet tables michael@0: * ordered by Coverage Index */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (6, ruleSet); michael@0: }; michael@0: michael@0: michael@0: struct ContextFormat2 michael@0: { michael@0: inline void closure (hb_closure_context_t *c) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: if (!(this+coverage).intersects (c->glyphs)) michael@0: return; michael@0: michael@0: const ClassDef &class_def = this+classDef; michael@0: michael@0: struct ContextClosureLookupContext lookup_context = { michael@0: {intersects_class}, michael@0: &class_def michael@0: }; michael@0: michael@0: unsigned int count = ruleSet.len; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: if (class_def.intersects_class (c->glyphs, i)) { michael@0: const RuleSet &rule_set = this+ruleSet[i]; michael@0: rule_set.closure (c, lookup_context); michael@0: } michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: (this+coverage).add_coverage (c->input); michael@0: michael@0: const ClassDef &class_def = this+classDef; michael@0: struct ContextCollectGlyphsLookupContext lookup_context = { michael@0: {collect_class}, michael@0: &class_def michael@0: }; michael@0: michael@0: unsigned int count = ruleSet.len; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: (this+ruleSet[i]).collect_glyphs (c, lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: michael@0: const ClassDef &class_def = this+classDef; michael@0: unsigned int index = class_def.get_class (c->glyphs[0]); michael@0: const RuleSet &rule_set = this+ruleSet[index]; michael@0: struct ContextApplyLookupContext lookup_context = { michael@0: {match_class}, michael@0: &class_def michael@0: }; michael@0: return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); michael@0: } michael@0: michael@0: inline const Coverage &get_coverage (void) const michael@0: { michael@0: return this+coverage; michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); michael@0: if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); michael@0: michael@0: const ClassDef &class_def = this+classDef; michael@0: index = class_def.get_class (c->buffer->cur().codepoint); michael@0: const RuleSet &rule_set = this+ruleSet[index]; michael@0: struct ContextApplyLookupContext lookup_context = { michael@0: {match_class}, michael@0: &class_def michael@0: }; michael@0: return TRACE_RETURN (rule_set.apply (c, lookup_context)); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT format; /* Format identifier--format = 2 */ michael@0: OffsetTo michael@0: coverage; /* Offset to Coverage table--from michael@0: * beginning of table */ michael@0: OffsetTo michael@0: classDef; /* Offset to glyph ClassDef table--from michael@0: * beginning of table */ michael@0: OffsetArrayOf michael@0: ruleSet; /* Array of RuleSet tables michael@0: * ordered by class */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (8, ruleSet); michael@0: }; michael@0: michael@0: michael@0: struct ContextFormat3 michael@0: { michael@0: inline void closure (hb_closure_context_t *c) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: if (!(this+coverage[0]).intersects (c->glyphs)) michael@0: return; michael@0: michael@0: const LookupRecord *lookupRecord = &StructAtOffset (coverage, coverage[0].static_size * glyphCount); michael@0: struct ContextClosureLookupContext lookup_context = { michael@0: {intersects_coverage}, michael@0: this michael@0: }; michael@0: context_closure_lookup (c, michael@0: glyphCount, (const USHORT *) (coverage + 1), michael@0: lookupCount, lookupRecord, michael@0: lookup_context); michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: (this+coverage[0]).add_coverage (c->input); michael@0: michael@0: const LookupRecord *lookupRecord = &StructAtOffset (coverage, coverage[0].static_size * glyphCount); michael@0: struct ContextCollectGlyphsLookupContext lookup_context = { michael@0: {collect_coverage}, michael@0: this michael@0: }; michael@0: michael@0: context_collect_glyphs_lookup (c, michael@0: glyphCount, (const USHORT *) (coverage + 1), michael@0: lookupCount, lookupRecord, michael@0: lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: michael@0: const LookupRecord *lookupRecord = &StructAtOffset (coverage, coverage[0].static_size * glyphCount); michael@0: struct ContextApplyLookupContext lookup_context = { michael@0: {match_coverage}, michael@0: this michael@0: }; michael@0: return TRACE_RETURN (context_would_apply_lookup (c, glyphCount, (const USHORT *) (coverage + 1), lookupCount, lookupRecord, lookup_context)); michael@0: } michael@0: michael@0: inline const Coverage &get_coverage (void) const michael@0: { michael@0: return this+coverage[0]; michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: unsigned int index = (this+coverage[0]).get_coverage (c->buffer->cur().codepoint); michael@0: if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); michael@0: michael@0: const LookupRecord *lookupRecord = &StructAtOffset (coverage, coverage[0].static_size * glyphCount); michael@0: struct ContextApplyLookupContext lookup_context = { michael@0: {match_coverage}, michael@0: this michael@0: }; michael@0: return TRACE_RETURN (context_apply_lookup (c, glyphCount, (const USHORT *) (coverage + 1), lookupCount, lookupRecord, lookup_context)); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!c->check_struct (this)) return TRACE_RETURN (false); michael@0: unsigned int count = glyphCount; michael@0: if (!c->check_array (coverage, coverage[0].static_size, count)) return TRACE_RETURN (false); michael@0: for (unsigned int i = 0; i < count; i++) michael@0: if (!coverage[i].sanitize (c, this)) return TRACE_RETURN (false); michael@0: LookupRecord *lookupRecord = &StructAtOffset (coverage, coverage[0].static_size * count); michael@0: return TRACE_RETURN (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT format; /* Format identifier--format = 3 */ michael@0: USHORT glyphCount; /* Number of glyphs in the input glyph michael@0: * sequence */ michael@0: USHORT lookupCount; /* Number of LookupRecords */ michael@0: OffsetTo michael@0: coverage[VAR]; /* Array of offsets to Coverage michael@0: * table in glyph sequence order */ michael@0: LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in michael@0: * design order */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY2 (6, coverage, lookupRecordX); michael@0: }; michael@0: michael@0: struct Context michael@0: { michael@0: template michael@0: inline typename context_t::return_t dispatch (context_t *c) const michael@0: { michael@0: TRACE_DISPATCH (this); michael@0: switch (u.format) { michael@0: case 1: return TRACE_RETURN (c->dispatch (u.format1)); michael@0: case 2: return TRACE_RETURN (c->dispatch (u.format2)); michael@0: case 3: return TRACE_RETURN (c->dispatch (u.format3)); michael@0: default:return TRACE_RETURN (c->default_return_value ()); michael@0: } michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!u.format.sanitize (c)) return TRACE_RETURN (false); michael@0: switch (u.format) { michael@0: case 1: return TRACE_RETURN (u.format1.sanitize (c)); michael@0: case 2: return TRACE_RETURN (u.format2.sanitize (c)); michael@0: case 3: return TRACE_RETURN (u.format3.sanitize (c)); michael@0: default:return TRACE_RETURN (true); michael@0: } michael@0: } michael@0: michael@0: protected: michael@0: union { michael@0: USHORT format; /* Format identifier */ michael@0: ContextFormat1 format1; michael@0: ContextFormat2 format2; michael@0: ContextFormat3 format3; michael@0: } u; michael@0: }; michael@0: michael@0: michael@0: /* Chaining Contextual lookups */ michael@0: michael@0: struct ChainContextClosureLookupContext michael@0: { michael@0: ContextClosureFuncs funcs; michael@0: const void *intersects_data[3]; michael@0: }; michael@0: michael@0: struct ChainContextCollectGlyphsLookupContext michael@0: { michael@0: ContextCollectGlyphsFuncs funcs; michael@0: const void *collect_data[3]; michael@0: }; michael@0: michael@0: struct ChainContextApplyLookupContext michael@0: { michael@0: ContextApplyFuncs funcs; michael@0: const void *match_data[3]; michael@0: }; michael@0: michael@0: static inline void chain_context_closure_lookup (hb_closure_context_t *c, michael@0: unsigned int backtrackCount, michael@0: const USHORT backtrack[], michael@0: unsigned int inputCount, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: unsigned int lookaheadCount, michael@0: const USHORT lookahead[], michael@0: unsigned int lookupCount, michael@0: const LookupRecord lookupRecord[], michael@0: ChainContextClosureLookupContext &lookup_context) michael@0: { michael@0: if (intersects_array (c, michael@0: backtrackCount, backtrack, michael@0: lookup_context.funcs.intersects, lookup_context.intersects_data[0]) michael@0: && intersects_array (c, michael@0: inputCount ? inputCount - 1 : 0, input, michael@0: lookup_context.funcs.intersects, lookup_context.intersects_data[1]) michael@0: && intersects_array (c, michael@0: lookaheadCount, lookahead, michael@0: lookup_context.funcs.intersects, lookup_context.intersects_data[2])) michael@0: recurse_lookups (c, michael@0: lookupCount, lookupRecord); michael@0: } michael@0: michael@0: static inline void chain_context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c, michael@0: unsigned int backtrackCount, michael@0: const USHORT backtrack[], michael@0: unsigned int inputCount, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: unsigned int lookaheadCount, michael@0: const USHORT lookahead[], michael@0: unsigned int lookupCount, michael@0: const LookupRecord lookupRecord[], michael@0: ChainContextCollectGlyphsLookupContext &lookup_context) michael@0: { michael@0: collect_array (c, c->before, michael@0: backtrackCount, backtrack, michael@0: lookup_context.funcs.collect, lookup_context.collect_data[0]); michael@0: collect_array (c, c->input, michael@0: inputCount ? inputCount - 1 : 0, input, michael@0: lookup_context.funcs.collect, lookup_context.collect_data[1]); michael@0: collect_array (c, c->after, michael@0: lookaheadCount, lookahead, michael@0: lookup_context.funcs.collect, lookup_context.collect_data[2]); michael@0: recurse_lookups (c, michael@0: lookupCount, lookupRecord); michael@0: } michael@0: michael@0: static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c, michael@0: unsigned int backtrackCount, michael@0: const USHORT backtrack[] HB_UNUSED, michael@0: unsigned int inputCount, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: unsigned int lookaheadCount, michael@0: const USHORT lookahead[] HB_UNUSED, michael@0: unsigned int lookupCount HB_UNUSED, michael@0: const LookupRecord lookupRecord[] HB_UNUSED, michael@0: ChainContextApplyLookupContext &lookup_context) michael@0: { michael@0: return (c->zero_context ? !backtrackCount && !lookaheadCount : true) michael@0: && would_match_input (c, michael@0: inputCount, input, michael@0: lookup_context.funcs.match, lookup_context.match_data[1]); michael@0: } michael@0: michael@0: static inline bool chain_context_apply_lookup (hb_apply_context_t *c, michael@0: unsigned int backtrackCount, michael@0: const USHORT backtrack[], michael@0: unsigned int inputCount, /* Including the first glyph (not matched) */ michael@0: const USHORT input[], /* Array of input values--start with second glyph */ michael@0: unsigned int lookaheadCount, michael@0: const USHORT lookahead[], michael@0: unsigned int lookupCount, michael@0: const LookupRecord lookupRecord[], michael@0: ChainContextApplyLookupContext &lookup_context) michael@0: { michael@0: unsigned int match_length = 0; michael@0: unsigned int match_positions[MAX_CONTEXT_LENGTH]; michael@0: return match_input (c, michael@0: inputCount, input, michael@0: lookup_context.funcs.match, lookup_context.match_data[1], michael@0: &match_length, match_positions) michael@0: && match_backtrack (c, michael@0: backtrackCount, backtrack, michael@0: lookup_context.funcs.match, lookup_context.match_data[0]) michael@0: && match_lookahead (c, michael@0: lookaheadCount, lookahead, michael@0: lookup_context.funcs.match, lookup_context.match_data[2], michael@0: match_length) michael@0: && apply_lookup (c, michael@0: inputCount, match_positions, michael@0: lookupCount, lookupRecord, michael@0: match_length); michael@0: } michael@0: michael@0: struct ChainRule michael@0: { michael@0: inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: const HeadlessArrayOf &input = StructAfter > (backtrack); michael@0: const ArrayOf &lookahead = StructAfter > (input); michael@0: const ArrayOf &lookup = StructAfter > (lookahead); michael@0: chain_context_closure_lookup (c, michael@0: backtrack.len, backtrack.array, michael@0: input.len, input.array, michael@0: lookahead.len, lookahead.array, michael@0: lookup.len, lookup.array, michael@0: lookup_context); michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: const HeadlessArrayOf &input = StructAfter > (backtrack); michael@0: const ArrayOf &lookahead = StructAfter > (input); michael@0: const ArrayOf &lookup = StructAfter > (lookahead); michael@0: chain_context_collect_glyphs_lookup (c, michael@0: backtrack.len, backtrack.array, michael@0: input.len, input.array, michael@0: lookahead.len, lookahead.array, michael@0: lookup.len, lookup.array, michael@0: lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: const HeadlessArrayOf &input = StructAfter > (backtrack); michael@0: const ArrayOf &lookahead = StructAfter > (input); michael@0: const ArrayOf &lookup = StructAfter > (lookahead); michael@0: return TRACE_RETURN (chain_context_would_apply_lookup (c, michael@0: backtrack.len, backtrack.array, michael@0: input.len, input.array, michael@0: lookahead.len, lookahead.array, lookup.len, michael@0: lookup.array, lookup_context)); michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: const HeadlessArrayOf &input = StructAfter > (backtrack); michael@0: const ArrayOf &lookahead = StructAfter > (input); michael@0: const ArrayOf &lookup = StructAfter > (lookahead); michael@0: return TRACE_RETURN (chain_context_apply_lookup (c, michael@0: backtrack.len, backtrack.array, michael@0: input.len, input.array, michael@0: lookahead.len, lookahead.array, lookup.len, michael@0: lookup.array, lookup_context)); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!backtrack.sanitize (c)) return TRACE_RETURN (false); michael@0: HeadlessArrayOf &input = StructAfter > (backtrack); michael@0: if (!input.sanitize (c)) return TRACE_RETURN (false); michael@0: ArrayOf &lookahead = StructAfter > (input); michael@0: if (!lookahead.sanitize (c)) return TRACE_RETURN (false); michael@0: ArrayOf &lookup = StructAfter > (lookahead); michael@0: return TRACE_RETURN (lookup.sanitize (c)); michael@0: } michael@0: michael@0: protected: michael@0: ArrayOf michael@0: backtrack; /* Array of backtracking values michael@0: * (to be matched before the input michael@0: * sequence) */ michael@0: HeadlessArrayOf michael@0: inputX; /* Array of input values (start with michael@0: * second glyph) */ michael@0: ArrayOf michael@0: lookaheadX; /* Array of lookahead values's (to be michael@0: * matched after the input sequence) */ michael@0: ArrayOf michael@0: lookupX; /* Array of LookupRecords--in michael@0: * design order) */ michael@0: public: michael@0: DEFINE_SIZE_MIN (8); michael@0: }; michael@0: michael@0: struct ChainRuleSet michael@0: { michael@0: inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: unsigned int num_rules = rule.len; michael@0: for (unsigned int i = 0; i < num_rules; i++) michael@0: (this+rule[i]).closure (c, lookup_context); michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: unsigned int num_rules = rule.len; michael@0: for (unsigned int i = 0; i < num_rules; i++) michael@0: (this+rule[i]).collect_glyphs (c, lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: unsigned int num_rules = rule.len; michael@0: for (unsigned int i = 0; i < num_rules; i++) michael@0: if ((this+rule[i]).would_apply (c, lookup_context)) michael@0: return TRACE_RETURN (true); michael@0: michael@0: return TRACE_RETURN (false); michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: unsigned int num_rules = rule.len; michael@0: for (unsigned int i = 0; i < num_rules; i++) michael@0: if ((this+rule[i]).apply (c, lookup_context)) michael@0: return TRACE_RETURN (true); michael@0: michael@0: return TRACE_RETURN (false); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (rule.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: OffsetArrayOf michael@0: rule; /* Array of ChainRule tables michael@0: * ordered by preference */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (2, rule); michael@0: }; michael@0: michael@0: struct ChainContextFormat1 michael@0: { michael@0: inline void closure (hb_closure_context_t *c) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: const Coverage &cov = (this+coverage); michael@0: michael@0: struct ChainContextClosureLookupContext lookup_context = { michael@0: {intersects_glyph}, michael@0: {NULL, NULL, NULL} michael@0: }; michael@0: michael@0: unsigned int count = ruleSet.len; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: if (cov.intersects_coverage (c->glyphs, i)) { michael@0: const ChainRuleSet &rule_set = this+ruleSet[i]; michael@0: rule_set.closure (c, lookup_context); michael@0: } michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: (this+coverage).add_coverage (c->input); michael@0: michael@0: struct ChainContextCollectGlyphsLookupContext lookup_context = { michael@0: {collect_glyph}, michael@0: {NULL, NULL, NULL} michael@0: }; michael@0: michael@0: unsigned int count = ruleSet.len; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: (this+ruleSet[i]).collect_glyphs (c, lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: michael@0: const ChainRuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])]; michael@0: struct ChainContextApplyLookupContext lookup_context = { michael@0: {match_glyph}, michael@0: {NULL, NULL, NULL} michael@0: }; michael@0: return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); michael@0: } michael@0: michael@0: inline const Coverage &get_coverage (void) const michael@0: { michael@0: return this+coverage; michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); michael@0: if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); michael@0: michael@0: const ChainRuleSet &rule_set = this+ruleSet[index]; michael@0: struct ChainContextApplyLookupContext lookup_context = { michael@0: {match_glyph}, michael@0: {NULL, NULL, NULL} michael@0: }; michael@0: return TRACE_RETURN (rule_set.apply (c, lookup_context)); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT format; /* Format identifier--format = 1 */ michael@0: OffsetTo michael@0: coverage; /* Offset to Coverage table--from michael@0: * beginning of table */ michael@0: OffsetArrayOf michael@0: ruleSet; /* Array of ChainRuleSet tables michael@0: * ordered by Coverage Index */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (6, ruleSet); michael@0: }; michael@0: michael@0: struct ChainContextFormat2 michael@0: { michael@0: inline void closure (hb_closure_context_t *c) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: if (!(this+coverage).intersects (c->glyphs)) michael@0: return; michael@0: michael@0: const ClassDef &backtrack_class_def = this+backtrackClassDef; michael@0: const ClassDef &input_class_def = this+inputClassDef; michael@0: const ClassDef &lookahead_class_def = this+lookaheadClassDef; michael@0: michael@0: struct ChainContextClosureLookupContext lookup_context = { michael@0: {intersects_class}, michael@0: {&backtrack_class_def, michael@0: &input_class_def, michael@0: &lookahead_class_def} michael@0: }; michael@0: michael@0: unsigned int count = ruleSet.len; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: if (input_class_def.intersects_class (c->glyphs, i)) { michael@0: const ChainRuleSet &rule_set = this+ruleSet[i]; michael@0: rule_set.closure (c, lookup_context); michael@0: } michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: (this+coverage).add_coverage (c->input); michael@0: michael@0: const ClassDef &backtrack_class_def = this+backtrackClassDef; michael@0: const ClassDef &input_class_def = this+inputClassDef; michael@0: const ClassDef &lookahead_class_def = this+lookaheadClassDef; michael@0: michael@0: struct ChainContextCollectGlyphsLookupContext lookup_context = { michael@0: {collect_class}, michael@0: {&backtrack_class_def, michael@0: &input_class_def, michael@0: &lookahead_class_def} michael@0: }; michael@0: michael@0: unsigned int count = ruleSet.len; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: (this+ruleSet[i]).collect_glyphs (c, lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: michael@0: const ClassDef &backtrack_class_def = this+backtrackClassDef; michael@0: const ClassDef &input_class_def = this+inputClassDef; michael@0: const ClassDef &lookahead_class_def = this+lookaheadClassDef; michael@0: michael@0: unsigned int index = input_class_def.get_class (c->glyphs[0]); michael@0: const ChainRuleSet &rule_set = this+ruleSet[index]; michael@0: struct ChainContextApplyLookupContext lookup_context = { michael@0: {match_class}, michael@0: {&backtrack_class_def, michael@0: &input_class_def, michael@0: &lookahead_class_def} michael@0: }; michael@0: return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); michael@0: } michael@0: michael@0: inline const Coverage &get_coverage (void) const michael@0: { michael@0: return this+coverage; michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); michael@0: if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); michael@0: michael@0: const ClassDef &backtrack_class_def = this+backtrackClassDef; michael@0: const ClassDef &input_class_def = this+inputClassDef; michael@0: const ClassDef &lookahead_class_def = this+lookaheadClassDef; michael@0: michael@0: index = input_class_def.get_class (c->buffer->cur().codepoint); michael@0: const ChainRuleSet &rule_set = this+ruleSet[index]; michael@0: struct ChainContextApplyLookupContext lookup_context = { michael@0: {match_class}, michael@0: {&backtrack_class_def, michael@0: &input_class_def, michael@0: &lookahead_class_def} michael@0: }; michael@0: return TRACE_RETURN (rule_set.apply (c, lookup_context)); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (coverage.sanitize (c, this) && backtrackClassDef.sanitize (c, this) && michael@0: inputClassDef.sanitize (c, this) && lookaheadClassDef.sanitize (c, this) && michael@0: ruleSet.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT format; /* Format identifier--format = 2 */ michael@0: OffsetTo michael@0: coverage; /* Offset to Coverage table--from michael@0: * beginning of table */ michael@0: OffsetTo michael@0: backtrackClassDef; /* Offset to glyph ClassDef table michael@0: * containing backtrack sequence michael@0: * data--from beginning of table */ michael@0: OffsetTo michael@0: inputClassDef; /* Offset to glyph ClassDef michael@0: * table containing input sequence michael@0: * data--from beginning of table */ michael@0: OffsetTo michael@0: lookaheadClassDef; /* Offset to glyph ClassDef table michael@0: * containing lookahead sequence michael@0: * data--from beginning of table */ michael@0: OffsetArrayOf michael@0: ruleSet; /* Array of ChainRuleSet tables michael@0: * ordered by class */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (12, ruleSet); michael@0: }; michael@0: michael@0: struct ChainContextFormat3 michael@0: { michael@0: inline void closure (hb_closure_context_t *c) const michael@0: { michael@0: TRACE_CLOSURE (this); michael@0: const OffsetArrayOf &input = StructAfter > (backtrack); michael@0: michael@0: if (!(this+input[0]).intersects (c->glyphs)) michael@0: return; michael@0: michael@0: const OffsetArrayOf &lookahead = StructAfter > (input); michael@0: const ArrayOf &lookup = StructAfter > (lookahead); michael@0: struct ChainContextClosureLookupContext lookup_context = { michael@0: {intersects_coverage}, michael@0: {this, this, this} michael@0: }; michael@0: chain_context_closure_lookup (c, michael@0: backtrack.len, (const USHORT *) backtrack.array, michael@0: input.len, (const USHORT *) input.array + 1, michael@0: lookahead.len, (const USHORT *) lookahead.array, michael@0: lookup.len, lookup.array, michael@0: lookup_context); michael@0: } michael@0: michael@0: inline void collect_glyphs (hb_collect_glyphs_context_t *c) const michael@0: { michael@0: TRACE_COLLECT_GLYPHS (this); michael@0: const OffsetArrayOf &input = StructAfter > (backtrack); michael@0: michael@0: (this+input[0]).add_coverage (c->input); michael@0: michael@0: const OffsetArrayOf &lookahead = StructAfter > (input); michael@0: const ArrayOf &lookup = StructAfter > (lookahead); michael@0: struct ChainContextCollectGlyphsLookupContext lookup_context = { michael@0: {collect_coverage}, michael@0: {this, this, this} michael@0: }; michael@0: chain_context_collect_glyphs_lookup (c, michael@0: backtrack.len, (const USHORT *) backtrack.array, michael@0: input.len, (const USHORT *) input.array + 1, michael@0: lookahead.len, (const USHORT *) lookahead.array, michael@0: lookup.len, lookup.array, michael@0: lookup_context); michael@0: } michael@0: michael@0: inline bool would_apply (hb_would_apply_context_t *c) const michael@0: { michael@0: TRACE_WOULD_APPLY (this); michael@0: michael@0: const OffsetArrayOf &input = StructAfter > (backtrack); michael@0: const OffsetArrayOf &lookahead = StructAfter > (input); michael@0: const ArrayOf &lookup = StructAfter > (lookahead); michael@0: struct ChainContextApplyLookupContext lookup_context = { michael@0: {match_coverage}, michael@0: {this, this, this} michael@0: }; michael@0: return TRACE_RETURN (chain_context_would_apply_lookup (c, michael@0: backtrack.len, (const USHORT *) backtrack.array, michael@0: input.len, (const USHORT *) input.array + 1, michael@0: lookahead.len, (const USHORT *) lookahead.array, michael@0: lookup.len, lookup.array, lookup_context)); michael@0: } michael@0: michael@0: inline const Coverage &get_coverage (void) const michael@0: { michael@0: const OffsetArrayOf &input = StructAfter > (backtrack); michael@0: return this+input[0]; michael@0: } michael@0: michael@0: inline bool apply (hb_apply_context_t *c) const michael@0: { michael@0: TRACE_APPLY (this); michael@0: const OffsetArrayOf &input = StructAfter > (backtrack); michael@0: michael@0: unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint); michael@0: if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); michael@0: michael@0: const OffsetArrayOf &lookahead = StructAfter > (input); michael@0: const ArrayOf &lookup = StructAfter > (lookahead); michael@0: struct ChainContextApplyLookupContext lookup_context = { michael@0: {match_coverage}, michael@0: {this, this, this} michael@0: }; michael@0: return TRACE_RETURN (chain_context_apply_lookup (c, michael@0: backtrack.len, (const USHORT *) backtrack.array, michael@0: input.len, (const USHORT *) input.array + 1, michael@0: lookahead.len, (const USHORT *) lookahead.array, michael@0: lookup.len, lookup.array, lookup_context)); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!backtrack.sanitize (c, this)) return TRACE_RETURN (false); michael@0: OffsetArrayOf &input = StructAfter > (backtrack); michael@0: if (!input.sanitize (c, this)) return TRACE_RETURN (false); michael@0: OffsetArrayOf &lookahead = StructAfter > (input); michael@0: if (!lookahead.sanitize (c, this)) return TRACE_RETURN (false); michael@0: ArrayOf &lookup = StructAfter > (lookahead); michael@0: return TRACE_RETURN (lookup.sanitize (c)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT format; /* Format identifier--format = 3 */ michael@0: OffsetArrayOf michael@0: backtrack; /* Array of coverage tables michael@0: * in backtracking sequence, in glyph michael@0: * sequence order */ michael@0: OffsetArrayOf michael@0: inputX ; /* Array of coverage michael@0: * tables in input sequence, in glyph michael@0: * sequence order */ michael@0: OffsetArrayOf michael@0: lookaheadX; /* Array of coverage tables michael@0: * in lookahead sequence, in glyph michael@0: * sequence order */ michael@0: ArrayOf michael@0: lookupX; /* Array of LookupRecords--in michael@0: * design order) */ michael@0: public: michael@0: DEFINE_SIZE_MIN (10); michael@0: }; michael@0: michael@0: struct ChainContext michael@0: { michael@0: template michael@0: inline typename context_t::return_t dispatch (context_t *c) const michael@0: { michael@0: TRACE_DISPATCH (this); michael@0: switch (u.format) { michael@0: case 1: return TRACE_RETURN (c->dispatch (u.format1)); michael@0: case 2: return TRACE_RETURN (c->dispatch (u.format2)); michael@0: case 3: return TRACE_RETURN (c->dispatch (u.format3)); michael@0: default:return TRACE_RETURN (c->default_return_value ()); michael@0: } michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!u.format.sanitize (c)) return TRACE_RETURN (false); michael@0: switch (u.format) { michael@0: case 1: return TRACE_RETURN (u.format1.sanitize (c)); michael@0: case 2: return TRACE_RETURN (u.format2.sanitize (c)); michael@0: case 3: return TRACE_RETURN (u.format3.sanitize (c)); michael@0: default:return TRACE_RETURN (true); michael@0: } michael@0: } michael@0: michael@0: protected: michael@0: union { michael@0: USHORT format; /* Format identifier */ michael@0: ChainContextFormat1 format1; michael@0: ChainContextFormat2 format2; michael@0: ChainContextFormat3 format3; michael@0: } u; michael@0: }; michael@0: michael@0: michael@0: struct ExtensionFormat1 michael@0: { michael@0: inline unsigned int get_type (void) const { return extensionLookupType; } michael@0: inline unsigned int get_offset (void) const { return extensionOffset; } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (c->check_struct (this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT format; /* Format identifier. Set to 1. */ michael@0: USHORT extensionLookupType; /* Lookup type of subtable referenced michael@0: * by ExtensionOffset (i.e. the michael@0: * extension subtable). */ michael@0: ULONG extensionOffset; /* Offset to the extension subtable, michael@0: * of lookup type subtable. */ michael@0: public: michael@0: DEFINE_SIZE_STATIC (8); michael@0: }; michael@0: michael@0: template michael@0: struct Extension michael@0: { michael@0: inline unsigned int get_type (void) const michael@0: { michael@0: switch (u.format) { michael@0: case 1: return u.format1.get_type (); michael@0: default:return 0; michael@0: } michael@0: } michael@0: inline unsigned int get_offset (void) const michael@0: { michael@0: switch (u.format) { michael@0: case 1: return u.format1.get_offset (); michael@0: default:return 0; michael@0: } michael@0: } michael@0: michael@0: template michael@0: inline const X& get_subtable (void) const michael@0: { michael@0: unsigned int offset = get_offset (); michael@0: if (unlikely (!offset)) return Null(typename T::LookupSubTable); michael@0: return StructAtOffset (this, offset); michael@0: } michael@0: michael@0: template michael@0: inline typename context_t::return_t dispatch (context_t *c) const michael@0: { michael@0: return get_subtable ().dispatch (c, get_type ()); michael@0: } michael@0: michael@0: inline bool sanitize_self (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!u.format.sanitize (c)) return TRACE_RETURN (false); michael@0: switch (u.format) { michael@0: case 1: return TRACE_RETURN (u.format1.sanitize (c)); michael@0: default:return TRACE_RETURN (true); michael@0: } michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!sanitize_self (c)) return TRACE_RETURN (false); michael@0: unsigned int offset = get_offset (); michael@0: if (unlikely (!offset)) return TRACE_RETURN (true); michael@0: return TRACE_RETURN (StructAtOffset (this, offset).sanitize (c, get_type ())); michael@0: } michael@0: michael@0: protected: michael@0: union { michael@0: USHORT format; /* Format identifier */ michael@0: ExtensionFormat1 format1; michael@0: } u; michael@0: }; michael@0: michael@0: michael@0: /* michael@0: * GSUB/GPOS Common michael@0: */ michael@0: michael@0: struct GSUBGPOS michael@0: { michael@0: static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB; michael@0: static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS; michael@0: michael@0: inline unsigned int get_script_count (void) const michael@0: { return (this+scriptList).len; } michael@0: inline const Tag& get_script_tag (unsigned int i) const michael@0: { return (this+scriptList).get_tag (i); } michael@0: inline unsigned int get_script_tags (unsigned int start_offset, michael@0: unsigned int *script_count /* IN/OUT */, michael@0: hb_tag_t *script_tags /* OUT */) const michael@0: { return (this+scriptList).get_tags (start_offset, script_count, script_tags); } michael@0: inline const Script& get_script (unsigned int i) const michael@0: { return (this+scriptList)[i]; } michael@0: inline bool find_script_index (hb_tag_t tag, unsigned int *index) const michael@0: { return (this+scriptList).find_index (tag, index); } michael@0: michael@0: inline unsigned int get_feature_count (void) const michael@0: { return (this+featureList).len; } michael@0: inline const Tag& get_feature_tag (unsigned int i) const michael@0: { return (this+featureList).get_tag (i); } michael@0: inline unsigned int get_feature_tags (unsigned int start_offset, michael@0: unsigned int *feature_count /* IN/OUT */, michael@0: hb_tag_t *feature_tags /* OUT */) const michael@0: { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); } michael@0: inline const Feature& get_feature (unsigned int i) const michael@0: { return (this+featureList)[i]; } michael@0: inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const michael@0: { return (this+featureList).find_index (tag, index); } michael@0: michael@0: inline unsigned int get_lookup_count (void) const michael@0: { return (this+lookupList).len; } michael@0: inline const Lookup& get_lookup (unsigned int i) const michael@0: { return (this+lookupList)[i]; } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (version.sanitize (c) && likely (version.major == 1) && michael@0: scriptList.sanitize (c, this) && michael@0: featureList.sanitize (c, this) && michael@0: lookupList.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: FixedVersion version; /* Version of the GSUB/GPOS table--initially set michael@0: * to 0x00010000 */ michael@0: OffsetTo michael@0: scriptList; /* ScriptList table */ michael@0: OffsetTo michael@0: featureList; /* FeatureList table */ michael@0: OffsetTo michael@0: lookupList; /* LookupList table */ michael@0: public: michael@0: DEFINE_SIZE_STATIC (10); michael@0: }; michael@0: michael@0: michael@0: } /* namespace OT */ michael@0: michael@0: michael@0: #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */