Blame src/hb-ot-layout-gsubgpos-private.hh

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