text:
/*
 * Copyright © 2007,2008,2009,2010  Red Hat, Inc.
 * Copyright © 2012  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Red Hat Author(s): Behdad Esfahbod
 * Google Author(s): Behdad Esfahbod
 */

#ifndef HB_OPEN_TYPE_HH
#define HB_OPEN_TYPE_HH

#include "hb.hh"
#include "hb-blob.hh"
#include "hb-face.hh"
#include "hb-machinery.hh"
#include "hb-subset.hh"

namespace OT {

/*
 *
 * The OpenType Font File: Data Types
 */

/* "The following data types are used in the OpenType font file.
 *  All OpenType fonts use Motorola-style byte ordering (Big Endian):" */

/*
 * Int types
 */

/* Integer types in big-endian order and no alignment requirement */
template <typename Type, unsigned int Size>
struct IntType
{
  typedef Type type;
  typedef hb_conditional<hb_is_signed (Type), signed, unsigned> wide_type;

  IntType& operator = (wide_type i) { v = i; return *this; }
  operator wide_type () const { return v; }
  bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; }
  bool operator != (const IntType &o) const { return !(*this == o); }

  IntType& operator += (unsigned count) { *this = *this + count; return *this; }
  IntType& operator -= (unsigned count) { *this = *this - count; return *this; }
  IntType& operator ++ () { *this += 1; return *this; }
  IntType& operator -- () { *this -= 1; return *this; }
  IntType operator ++ (int) { IntType c (*this); ++*this; return c; }
  IntType operator -- (int) { IntType c (*this); --*this; return c; }

  HB_INTERNAL static int cmp (const IntType *a, const IntType *b)
  { return b->cmp (*a); }
  HB_INTERNAL static int cmp (const void *a, const void *b)
  {
    IntType *pa = (IntType *) a;
    IntType *pb = (IntType *) b;

    return pb->cmp (*pa);
  }
  template <typename Type2>
  int cmp (Type2 a) const
  {
    Type b = v;
    if (sizeof (Type) < sizeof (int) && sizeof (Type2) < sizeof (int))
      return (int) a - (int) b;
    else
      return a < b ? -1 : a == b ? 0 : +1;
  }
  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (likely (c->check_struct (this)));
  }
  protected:
  BEInt<Type, Size> v;
  public:
  DEFINE_SIZE_STATIC (Size);
};

typedef IntType<uint8_t,  1> HBUINT8;	/* 8-bit unsigned integer. */
typedef IntType<int8_t,   1> HBINT8;	/* 8-bit signed integer. */
typedef IntType<uint16_t, 2> HBUINT16;	/* 16-bit unsigned integer. */
typedef IntType<int16_t,  2> HBINT16;	/* 16-bit signed integer. */
typedef IntType<uint32_t, 4> HBUINT32;	/* 32-bit unsigned integer. */
typedef IntType<int32_t,  4> HBINT32;	/* 32-bit signed integer. */
/* Note: we cannot defined a signed HBINT24 because there's no corresponding C type.
 * Works for unsigned, but not signed, since we rely on compiler for sign-extension. */
typedef IntType<uint32_t, 3> HBUINT24;	/* 24-bit unsigned integer. */

/* 16-bit signed integer (HBINT16) that describes a quantity in FUnits. */
typedef HBINT16 FWORD;

/* 32-bit signed integer (HBINT32) that describes a quantity in FUnits. */
typedef HBINT32 FWORD32;

/* 16-bit unsigned integer (HBUINT16) that describes a quantity in FUnits. */
typedef HBUINT16 UFWORD;

/* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */
struct F2DOT14 : HBINT16
{
  F2DOT14& operator = (uint16_t i ) { HBINT16::operator= (i); return *this; }
  // 16384 means 1<<14
  float to_float () const  { return ((int32_t) v) / 16384.f; }
  void set_float (float f) { v = roundf (f * 16384.f); }
  public:
  DEFINE_SIZE_STATIC (2);
};

/* 32-bit signed fixed-point number (16.16). */
struct HBFixed : HBINT32
{
  HBFixed& operator = (uint32_t i) { HBINT32::operator= (i); return *this; }
  // 65536 means 1<<16
  float to_float () const  { return ((int32_t) v) / 65536.f; }
  void set_float (float f) { v = roundf (f * 65536.f); }
  public:
  DEFINE_SIZE_STATIC (4);
};

/* Date represented in number of seconds since 12:00 midnight, January 1,
 * 1904. The value is represented as a signed 64-bit integer. */
struct LONGDATETIME
{
  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (likely (c->check_struct (this)));
  }
  protected:
  HBINT32 major;
  HBUINT32 minor;
  public:
  DEFINE_SIZE_STATIC (8);
};

/* Array of four uint8s (length = 32 bits) used to identify a script, language
 * system, feature, or baseline */
struct Tag : HBUINT32
{
  Tag& operator = (hb_tag_t i) { HBUINT32::operator= (i); return *this; }
  /* What the char* converters return is NOT nul-terminated.  Print using "%.4s" */
  operator const char* () const { return reinterpret_cast<const char *> (&this->v); }
  operator char* ()             { return reinterpret_cast<char *> (&this->v); }
  public:
  DEFINE_SIZE_STATIC (4);
};

/* Glyph index number, same as uint16 (length = 16 bits) */
struct HBGlyphID : HBUINT16
{
  HBGlyphID& operator = (uint16_t i) { HBUINT16::operator= (i); return *this; }
};

/* Script/language-system/feature index */
struct Index : HBUINT16 {
  static constexpr unsigned NOT_FOUND_INDEX = 0xFFFFu;
  Index& operator = (uint16_t i) { HBUINT16::operator= (i); return *this; }
};
DECLARE_NULL_NAMESPACE_BYTES (OT, Index);

typedef Index NameID;

/* Offset, Null offset = 0 */
template <typename Type, bool has_null=true>
struct Offset : Type
{
  Offset& operator = (typename Type::type i) { Type::operator= (i); return *this; }

  typedef Type type;

  bool is_null () const { return has_null && 0 == *this; }

  void *serialize (hb_serialize_context_t *c, const void *base)
  {
    void *t = c->start_embed<void> ();
    c->check_assign (*this, (unsigned) ((char *) t - (char *) base));
    return t;
  }

  public:
  DEFINE_SIZE_STATIC (sizeof (Type));
};

typedef Offset<HBUINT16> Offset16;
typedef Offset<HBUINT32> Offset32;

/* CheckSum */
struct CheckSum : HBUINT32
{
  CheckSum& operator = (uint32_t i) { HBUINT32::operator= (i); return *this; }

  /* This is reference implementation from the spec. */
  static uint32_t CalcTableChecksum (const HBUINT32 *Table, uint32_t Length)
  {
    uint32_t Sum = 0L;
    assert (0 == (Length & 3));
    const HBUINT32 *EndPtr = Table + Length / HBUINT32::static_size;

    while (Table < EndPtr)
      Sum += *Table++;
    return Sum;
  }

  /* Note: data should be 4byte aligned and have 4byte padding at the end. */
  void set_for_data (const void *data, unsigned int length)
  { *this = CalcTableChecksum ((const HBUINT32 *) data, length); }

  public:
  DEFINE_SIZE_STATIC (4);
};

/*
 * Version Numbers
 */

template <typename FixedType=HBUINT16>
struct FixedVersion
{
  uint32_t to_int () const { return (major << (sizeof (FixedType) * 8)) + minor; }

  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (c->check_struct (this));
  }

  FixedType major;
  FixedType minor;
  public:
  DEFINE_SIZE_STATIC (2 * sizeof (FixedType));
};

/*
 * Template subclasses of Offset that do the dereferencing.
 * Use: (base+offset)
 */

template <typename Type, bool has_null>
struct _hb_has_null
{
  static const Type *get_null () { return nullptr; }
  static Type *get_crap ()       { return nullptr; }
};
template <typename Type>
struct _hb_has_null<Type, true>
{
  static const Type *get_null () { return &Null (Type); }
  static       Type *get_crap () { return &Crap (Type); }
};

template <typename Type, typename OffsetType=HBUINT16, bool has_null=true>
struct OffsetTo : Offset<OffsetType, has_null>
{
  HB_DELETE_COPY_ASSIGN (OffsetTo);
  OffsetTo () = default;

  OffsetTo& operator = (typename OffsetType::type i) { OffsetType::operator= (i); return *this; }

  const Type& operator () (const void *base) const
  {
    if (unlikely (this->is_null ())) return *_hb_has_null<Type, has_null>::get_null ();
    return StructAtOffset<const Type> (base, *this);
  }
  Type& operator () (void *base) const
  {
    if (unlikely (this->is_null ())) return *_hb_has_null<Type, has_null>::get_crap ();
    return StructAtOffset<Type> (base, *this);
  }

  template <typename Base,
	    hb_enable_if (hb_is_convertible (const Base, const void *))>
  friend const Type& operator + (const Base &base, const OffsetTo &offset) { return offset ((const void *) base); }
  template <typename Base,
	    hb_enable_if (hb_is_convertible (const Base, const void *))>
  friend const Type& operator + (const OffsetTo &offset, const Base &base) { return offset ((const void *) base); }
  template <typename Base,
	    hb_enable_if (hb_is_convertible (Base, void *))>
  friend Type& operator + (Base &&base, OffsetTo &offset) { return offset ((void *) base); }
  template <typename Base,
	    hb_enable_if (hb_is_convertible (Base, void *))>
  friend Type& operator + (OffsetTo &offset, Base &&base) { return offset ((void *) base); }

  Type& serialize (hb_serialize_context_t *c, const void *base)
  {
    return * (Type *) Offset<OffsetType>::serialize (c, base);
  }

  template <typename ...Ts>
  bool serialize_subset (hb_subset_context_t *c, const OffsetTo& src,
			 const void *src_base, Ts&&... ds)
  {
    *this = 0;
    if (src.is_null ())
      return false;

    auto *s = c->serializer;

    s->push ();

    bool ret = c->dispatch (src_base+src, hb_forward<Ts> (ds)...);

    if (ret || !has_null)
      s->add_link (*this, s->pop_pack ());
    else
      s->pop_discard ();

    return ret;
  }

  /* TODO: Somehow merge this with previous function into a serialize_dispatch(). */
  /* Workaround clang bug: https://bugs.llvm.org/show_bug.cgi?id=23029
   * Can't compile: whence = hb_serialize_context_t::Head followed by Ts&&...
   */
  template <typename ...Ts>
  bool serialize_copy (hb_serialize_context_t *c, const OffsetTo& src,
		       const void *src_base, unsigned dst_bias,
		       hb_serialize_context_t::whence_t whence,
		       Ts&&... ds)
  {
    *this = 0;
    if (src.is_null ())
      return false;

    c->push ();

    bool ret = c->copy (src_base+src, hb_forward<Ts> (ds)...);

    c->add_link (*this, c->pop_pack (), whence, dst_bias);

    return ret;
  }

  bool serialize_copy (hb_serialize_context_t *c, const OffsetTo& src,
		       const void *src_base, unsigned dst_bias = 0)
  { return serialize_copy (c, src, src_base, dst_bias, hb_serialize_context_t::Head); }

  bool sanitize_shallow (hb_sanitize_context_t *c, const void *base) const
  {
    TRACE_SANITIZE (this);
    if (unlikely (!c->check_struct (this))) return_trace (false);
    if (unlikely (this->is_null ())) return_trace (true);
    if (unlikely (!c->check_range (base, *this))) return_trace (false);
    return_trace (true);
  }

  template <typename ...Ts>
  bool sanitize (hb_sanitize_context_t *c, const void *base, Ts&&... ds) const
  {
    TRACE_SANITIZE (this);
    return_trace (sanitize_shallow (c, base) &&
		  (this->is_null () ||
		   c->dispatch (StructAtOffset<Type> (base, *this), hb_forward<Ts> (ds)...) ||
		   neuter (c)));
  }

  /* Set the offset to Null */
  bool neuter (hb_sanitize_context_t *c) const
  {
    if (!has_null) return false;
    return c->try_set (this, 0);
  }
  DEFINE_SIZE_STATIC (sizeof (OffsetType));
};
/* Partial specializations. */
template <typename Type, bool has_null=true>
using LOffsetTo = OffsetTo<Type, HBUINT32, has_null>;
template <typename Type, typename OffsetType=HBUINT16>
using NNOffsetTo = OffsetTo<Type, OffsetType, false>;
template <typename Type>
using LNNOffsetTo = LOffsetTo<Type, false>;

/*
 * Array Types
 */

template <typename Type>
struct UnsizedArrayOf
{
  typedef Type item_t;
  static constexpr unsigned item_size = hb_static_size (Type);

  HB_DELETE_CREATE_COPY_ASSIGN (UnsizedArrayOf);

  const Type& operator [] (int i_) const
  {
    unsigned int i = (unsigned int) i_;
    const Type *p = &arrayZ[i];
    if (unlikely (p < arrayZ)) return Null (Type); /* Overflowed. */
    return *p;
  }
  Type& operator [] (int i_)
  {
    unsigned int i = (unsigned int) i_;
    Type *p = &arrayZ[i];
    if (unlikely (p < arrayZ)) return Crap (Type); /* Overflowed. */
    return *p;
  }

  unsigned int get_size (unsigned int len) const
  { return len * Type::static_size; }

  template <typename T> operator T * () { return arrayZ; }
  template <typename T> operator const T * () const { return arrayZ; }
  hb_array_t<Type> as_array (unsigned int len)
  { return hb_array (arrayZ, len); }
  hb_array_t<const Type> as_array (unsigned int len) const
  { return hb_array (arrayZ, len); }
  operator hb_array_t<      Type> ()       { return as_array (); }
  operator hb_array_t<const Type> () const { return as_array (); }

  template <typename T>
  Type &lsearch (unsigned int len, const T &x, Type &not_found = Crap (Type))
  { return *as_array (len).lsearch (x, &not_found); }
  template <typename T>
  const Type &lsearch (unsigned int len, const T &x, const Type &not_found = Null (Type)) const
  { return *as_array (len).lsearch (x, &not_found); }

  void qsort (unsigned int len, unsigned int start = 0, unsigned int end = (unsigned int) -1)
  { as_array (len).qsort (start, end); }

  bool serialize (hb_serialize_context_t *c, unsigned int items_len)
  {
    TRACE_SERIALIZE (this);
    if (unlikely (!c->extend (*this, items_len))) return_trace (false);
    return_trace (true);
  }
  template <typename Iterator,
	    hb_requires (hb_is_source_of (Iterator, Type))>
  bool serialize (hb_serialize_context_t *c, Iterator items)
  {
    TRACE_SERIALIZE (this);
    unsigned count = items.len ();
    if (unlikely (!serialize (c, count))) return_trace (false);
    /* TODO Umm. Just exhaust the iterator instead?  Being extra
     * cautious right now.. */
    for (unsigned i = 0; i < count; i++, ++items)
      arrayZ[i] = *items;
    return_trace (true);
  }

  UnsizedArrayOf* copy (hb_serialize_context_t *c, unsigned count) const
  {
    TRACE_SERIALIZE (this);
    auto *out = c->start_embed (this);
    if (unlikely (!as_array (count).copy (c))) return_trace (nullptr);
    return_trace (out);
  }

  template <typename ...Ts>
  bool sanitize (hb_sanitize_context_t *c, unsigned int count, Ts&&... ds) const
  {
    TRACE_SANITIZE (this);
    if (unlikely (!sanitize_shallow (c, count))) return_trace (false);
    if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true);
    for (unsigned int i = 0; i < count; i++)
      if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...)))
	return_trace (false);
    return_trace (true);
  }

  bool sanitize_shallow (hb_sanitize_context_t *c, unsigned int count) const
  {
    TRACE_SANITIZE (this);
    return_trace (c->check_array (arrayZ, count));
  }

  public:
  Type		arrayZ[HB_VAR_ARRAY];
  public:
  DEFINE_SIZE_UNBOUNDED (0);
};

/* Unsized array of offset's */
template <typename Type, typename OffsetType, bool has_null=true>
using UnsizedOffsetArrayOf = UnsizedArrayOf<OffsetTo<Type, OffsetType, has_null>>;

/* Unsized array of offsets relative to the beginning of the array itself. */
template <typename Type, typename OffsetType, bool has_null=true>
struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType, has_null>
{
  const Type& operator [] (int i_) const
  {
    unsigned int i = (unsigned int) i_;
    const OffsetTo<Type, OffsetType, has_null> *p = &this->arrayZ[i];
    if (unlikely (p < this->arrayZ)) return Null (Type); /* Overflowed. */
    return this+*p;
  }
  Type& operator [] (int i_)
  {
    unsigned int i = (unsigned int) i_;
    const OffsetTo<Type, OffsetType, has_null> *p = &this->arrayZ[i];
    if (unlikely (p < this->arrayZ)) return Crap (Type); /* Overflowed. */
    return this+*p;
  }

  template <typename ...Ts>
  bool sanitize (hb_sanitize_context_t *c, unsigned int count, Ts&&... ds) const
  {
    TRACE_SANITIZE (this);
    return_trace ((UnsizedOffsetArrayOf<Type, OffsetType, has_null>
		   ::sanitize (c, count, this, hb_forward<Ts> (ds)...)));
  }
};

/* An array with sorted elements.  Supports binary searching. */
template <typename Type>
struct SortedUnsizedArrayOf : UnsizedArrayOf<Type>
{
  hb_sorted_array_t<Type> as_array (unsigned int len)
  { return hb_sorted_array (this->arrayZ, len); }
  hb_sorted_array_t<const Type> as_array (unsigned int len) const
  { return hb_sorted_array (this->arrayZ, len); }
  operator hb_sorted_array_t<Type> ()             { return as_array (); }
  operator hb_sorted_array_t<const Type> () const { return as_array (); }

  template <typename T>
  Type &bsearch (unsigned int len, const T &x, Type &not_found = Crap (Type))
  { return *as_array (len).bsearch (x, &not_found); }
  template <typename T>
  const Type &bsearch (unsigned int len, const T &x, const Type &not_found = Null (Type)) const
  { return *as_array (len).bsearch (x, &not_found); }
  template <typename T>
  bool bfind (unsigned int len, const T &x, unsigned int *i = nullptr,
		     hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
		     unsigned int to_store = (unsigned int) -1) const
  { return as_array (len).bfind (x, i, not_found, to_store); }
};

/* An array with a number of elements. */
template <typename Type, typename LenType=HBUINT16>
struct ArrayOf
{
  typedef Type item_t;
  static constexpr unsigned item_size = hb_static_size (Type);

  HB_DELETE_CREATE_COPY_ASSIGN (ArrayOf);

  const Type& operator [] (int i_) const
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i >= len)) return Null (Type);
    return arrayZ[i];
  }
  Type& operator [] (int i_)
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i >= len)) return Crap (Type);
    return arrayZ[i];
  }

  unsigned int get_size () const
  { return len.static_size + len * Type::static_size; }

  explicit operator bool () const { return len; }

  void pop () { len--; }

  hb_array_t<      Type> as_array ()       { return hb_array (arrayZ, len); }
  hb_array_t<const Type> as_array () const { return hb_array (arrayZ, len); }

  /* Iterator. */
  typedef hb_array_t<const Type>   iter_t;
  typedef hb_array_t<      Type> writer_t;
    iter_t   iter () const { return as_array (); }
  writer_t writer ()       { return as_array (); }
  operator   iter_t () const { return   iter (); }
  operator writer_t ()       { return writer (); }

  hb_array_t<const Type> sub_array (unsigned int start_offset, unsigned int count) const
  { return as_array ().sub_array (start_offset, count); }
  hb_array_t<const Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) const
  { return as_array ().sub_array (start_offset, count); }
  hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int count)
  { return as_array ().sub_array (start_offset, count); }
  hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */)
  { return as_array ().sub_array (start_offset, count); }

  hb_success_t serialize (hb_serialize_context_t *c, unsigned items_len)
  {
    TRACE_SERIALIZE (this);
    if (unlikely (!c->extend_min (*this))) return_trace (false);
    c->check_assign (len, items_len);
    if (unlikely (!c->extend (*this))) return_trace (false);
    return_trace (true);
  }
  template <typename Iterator,
	    hb_requires (hb_is_source_of (Iterator, Type))>
  hb_success_t serialize (hb_serialize_context_t *c, Iterator items)
  {
    TRACE_SERIALIZE (this);
    unsigned count = items.len ();
    if (unlikely (!serialize (c, count))) return_trace (false);
    /* TODO Umm. Just exhaust the iterator instead?  Being extra
     * cautious right now.. */
    for (unsigned i = 0; i < count; i++, ++items)
      arrayZ[i] = *items;
    return_trace (true);
  }

  Type* serialize_append (hb_serialize_context_t *c)
  {
    TRACE_SERIALIZE (this);
    len++;
    if (unlikely (!len || !c->extend (*this)))
    {
      len--;
      return_trace (nullptr);
    }
    return_trace (&arrayZ[len - 1]);
  }

  ArrayOf* copy (hb_serialize_context_t *c) const
  {
    TRACE_SERIALIZE (this);
    auto *out = c->start_embed (this);
    if (unlikely (!c->extend_min (out))) return_trace (nullptr);
    c->check_assign (out->len, len);
    if (unlikely (!as_array ().copy (c))) return_trace (nullptr);
    return_trace (out);
  }

  template <typename ...Ts>
  bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const
  {
    TRACE_SANITIZE (this);
    if (unlikely (!sanitize_shallow (c))) return_trace (false);
    if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true);
    unsigned int count = len;
    for (unsigned int i = 0; i < count; i++)
      if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...)))
	return_trace (false);
    return_trace (true);
  }

  template <typename T>
  Type &lsearch (const T &x, Type &not_found = Crap (Type))
  { return *as_array ().lsearch (x, &not_found); }
  template <typename T>
  const Type &lsearch (const T &x, const Type &not_found = Null (Type)) const
  { return *as_array ().lsearch (x, &not_found); }

  void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1)
  { as_array ().qsort (start, end); }

  bool sanitize_shallow (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (len.sanitize (c) && c->check_array (arrayZ, len));
  }

  public:
  LenType	len;
  Type		arrayZ[HB_VAR_ARRAY];
  public:
  DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ);
};
template <typename Type>
using LArrayOf = ArrayOf<Type, HBUINT32>;
using PString = ArrayOf<HBUINT8, HBUINT8>;

/* Array of Offset's */
template <typename Type>
using OffsetArrayOf = ArrayOf<OffsetTo<Type, HBUINT16>>;
template <typename Type>
using LOffsetArrayOf = ArrayOf<OffsetTo<Type, HBUINT32>>;
template <typename Type>
using LOffsetLArrayOf = ArrayOf<OffsetTo<Type, HBUINT32>, HBUINT32>;

/* Array of offsets relative to the beginning of the array itself. */
template <typename Type>
struct OffsetListOf : OffsetArrayOf<Type>
{
  const Type& operator [] (int i_) const
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i >= this->len)) return Null (Type);
    return this+this->arrayZ[i];
  }
  const Type& operator [] (int i_)
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i >= this->len)) return Crap (Type);
    return this+this->arrayZ[i];
  }

  bool subset (hb_subset_context_t *c) const
  {
    TRACE_SUBSET (this);
    struct OffsetListOf<Type> *out = c->serializer->embed (*this);
    if (unlikely (!out)) return_trace (false);
    unsigned int count = this->len;
    for (unsigned int i = 0; i < count; i++)
      out->arrayZ[i].serialize_subset (c, this->arrayZ[i], this, out);
    return_trace (true);
  }

  template <typename ...Ts>
  bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const
  {
    TRACE_SANITIZE (this);
    return_trace (OffsetArrayOf<Type>::sanitize (c, this, hb_forward<Ts> (ds)...));
  }
};

/* An array starting at second element. */
template <typename Type, typename LenType=HBUINT16>
struct HeadlessArrayOf
{
  static constexpr unsigned item_size = Type::static_size;

  HB_DELETE_CREATE_COPY_ASSIGN (HeadlessArrayOf);

  const Type& operator [] (int i_) const
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i >= lenP1 || !i)) return Null (Type);
    return arrayZ[i-1];
  }
  Type& operator [] (int i_)
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i >= lenP1 || !i)) return Crap (Type);
    return arrayZ[i-1];
  }
  unsigned int get_size () const
  { return lenP1.static_size + get_length () * Type::static_size; }

  unsigned get_length () const { return lenP1 ? lenP1 - 1 : 0; }

  hb_array_t<      Type> as_array ()       { return hb_array (arrayZ, get_length ()); }
  hb_array_t<const Type> as_array () const { return hb_array (arrayZ, get_length ()); }

  /* Iterator. */
  typedef hb_array_t<const Type>   iter_t;
  typedef hb_array_t<      Type> writer_t;
    iter_t   iter () const { return as_array (); }
  writer_t writer ()       { return as_array (); }
  operator   iter_t () const { return   iter (); }
  operator writer_t ()       { return writer (); }

  bool serialize (hb_serialize_context_t *c, unsigned int items_len)
  {
    TRACE_SERIALIZE (this);
    if (unlikely (!c->extend_min (*this))) return_trace (false);
    c->check_assign (lenP1, items_len + 1);
    if (unlikely (!c->extend (*this))) return_trace (false);
    return_trace (true);
  }
  template <typename Iterator,
	    hb_requires (hb_is_source_of (Iterator, Type))>
  bool serialize (hb_serialize_context_t *c, Iterator items)
  {
    TRACE_SERIALIZE (this);
    unsigned count = items.len ();
    if (unlikely (!serialize (c, count))) return_trace (false);
    /* TODO Umm. Just exhaust the iterator instead?  Being extra
     * cautious right now.. */
    for (unsigned i = 0; i < count; i++, ++items)
      arrayZ[i] = *items;
    return_trace (true);
  }

  template <typename ...Ts>
  bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const
  {
    TRACE_SANITIZE (this);
    if (unlikely (!sanitize_shallow (c))) return_trace (false);
    if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true);
    unsigned int count = get_length ();
    for (unsigned int i = 0; i < count; i++)
      if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...)))
	return_trace (false);
    return_trace (true);
  }

  private:
  bool sanitize_shallow (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (lenP1.sanitize (c) &&
		  (!lenP1 || c->check_array (arrayZ, lenP1 - 1)));
  }

  public:
  LenType	lenP1;
  Type		arrayZ[HB_VAR_ARRAY];
  public:
  DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ);
};

/* An array storing length-1. */
template <typename Type, typename LenType=HBUINT16>
struct ArrayOfM1
{
  HB_DELETE_CREATE_COPY_ASSIGN (ArrayOfM1);

  const Type& operator [] (int i_) const
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i > lenM1)) return Null (Type);
    return arrayZ[i];
  }
  Type& operator [] (int i_)
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i > lenM1)) return Crap (Type);
    return arrayZ[i];
  }
  unsigned int get_size () const
  { return lenM1.static_size + (lenM1 + 1) * Type::static_size; }

  template <typename ...Ts>
  bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const
  {
    TRACE_SANITIZE (this);
    if (unlikely (!sanitize_shallow (c))) return_trace (false);
    unsigned int count = lenM1 + 1;
    for (unsigned int i = 0; i < count; i++)
      if (unlikely (!c->dispatch (arrayZ[i], hb_forward<Ts> (ds)...)))
	return_trace (false);
    return_trace (true);
  }

  private:
  bool sanitize_shallow (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (lenM1.sanitize (c) &&
		  (c->check_array (arrayZ, lenM1 + 1)));
  }

  public:
  LenType	lenM1;
  Type		arrayZ[HB_VAR_ARRAY];
  public:
  DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ);
};

/* An array with sorted elements.  Supports binary searching. */
template <typename Type, typename LenType=HBUINT16>
struct SortedArrayOf : ArrayOf<Type, LenType>
{
  hb_sorted_array_t<      Type> as_array ()       { return hb_sorted_array (this->arrayZ, this->len); }
  hb_sorted_array_t<const Type> as_array () const { return hb_sorted_array (this->arrayZ, this->len); }

  /* Iterator. */
  typedef hb_sorted_array_t<const Type>   iter_t;
  typedef hb_sorted_array_t<      Type> writer_t;
    iter_t   iter () const { return as_array (); }
  writer_t writer ()       { return as_array (); }
  operator   iter_t () const { return   iter (); }
  operator writer_t ()       { return writer (); }

  hb_sorted_array_t<const Type> sub_array (unsigned int start_offset, unsigned int count) const
  { return as_array ().sub_array (start_offset, count); }
  hb_sorted_array_t<const Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) const
  { return as_array ().sub_array (start_offset, count); }
  hb_sorted_array_t<Type> sub_array (unsigned int start_offset, unsigned int count)
  { return as_array ().sub_array (start_offset, count); }
  hb_sorted_array_t<Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */)
  { return as_array ().sub_array (start_offset, count); }

  bool serialize (hb_serialize_context_t *c, unsigned int items_len)
  {
    TRACE_SERIALIZE (this);
    bool ret = ArrayOf<Type, LenType>::serialize (c, items_len);
    return_trace (ret);
  }
  template <typename Iterator,
	    hb_requires (hb_is_sorted_source_of (Iterator, Type))>
  bool serialize (hb_serialize_context_t *c, Iterator items)
  {
    TRACE_SERIALIZE (this);
    bool ret = ArrayOf<Type, LenType>::serialize (c, items);
    return_trace (ret);
  }

  template <typename T>
  Type &bsearch (const T &x, Type &not_found = Crap (Type))
  { return *as_array ().bsearch (x, &not_found); }
  template <typename T>
  const Type &bsearch (const T &x, const Type &not_found = Null (Type)) const
  { return *as_array ().bsearch (x, &not_found); }
  template <typename T>
  bool bfind (const T &x, unsigned int *i = nullptr,
	      hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
	      unsigned int to_store = (unsigned int) -1) const
  { return as_array ().bfind (x, i, not_found, to_store); }
};

/*
 * Binary-search arrays
 */

template <typename LenType=HBUINT16>
struct BinSearchHeader
{
  operator uint32_t () const { return len; }

  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (c->check_struct (this));
  }

  BinSearchHeader& operator = (unsigned int v)
  {
    len = v;
    assert (len == v);
    entrySelector = hb_max (1u, hb_bit_storage (v)) - 1;
    searchRange = 16 * (1u << entrySelector);
    rangeShift = v * 16 > searchRange
		 ? 16 * v - searchRange
		 : 0;
    return *this;
  }

  protected:
  LenType	len;
  LenType	searchRange;
  LenType	entrySelector;
  LenType	rangeShift;

  public:
  DEFINE_SIZE_STATIC (8);
};

template <typename Type, typename LenType=HBUINT16>
using BinSearchArrayOf = SortedArrayOf<Type, BinSearchHeader<LenType>>;

struct VarSizedBinSearchHeader
{

  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (c->check_struct (this));
  }

  HBUINT16	unitSize;	/* Size of a lookup unit for this search in bytes. */
  HBUINT16	nUnits;		/* Number of units of the preceding size to be searched. */
  HBUINT16	searchRange;	/* The value of unitSize times the largest power of 2
				 * that is less than or equal to the value of nUnits. */
  HBUINT16	entrySelector;	/* The log base 2 of the largest power of 2 less than
				 * or equal to the value of nUnits. */
  HBUINT16	rangeShift;	/* The value of unitSize times the difference of the
				 * value of nUnits minus the largest power of 2 less
				 * than or equal to the value of nUnits. */
  public:
  DEFINE_SIZE_STATIC (10);
};

template <typename Type>
struct VarSizedBinSearchArrayOf
{
  static constexpr unsigned item_size = Type::static_size;

  HB_DELETE_CREATE_COPY_ASSIGN (VarSizedBinSearchArrayOf);

  bool last_is_terminator () const
  {
    if (unlikely (!header.nUnits)) return false;

    /* Gah.
     *
     * "The number of termination values that need to be included is table-specific.
     * The value that indicates binary search termination is 0xFFFF." */
    const HBUINT16 *words = &StructAtOffset<HBUINT16> (&bytesZ, (header.nUnits - 1) * header.unitSize);
    unsigned int count = Type::TerminationWordCount;
    for (unsigned int i = 0; i < count; i++)
      if (words[i] != 0xFFFFu)
	return false;
    return true;
  }

  const Type& operator [] (int i_) const
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i >= get_length ())) return Null (Type);
    return StructAtOffset<Type> (&bytesZ, i * header.unitSize);
  }
  Type& operator [] (int i_)
  {
    unsigned int i = (unsigned int) i_;
    if (unlikely (i >= get_length ())) return Crap (Type);
    return StructAtOffset<Type> (&bytesZ, i * header.unitSize);
  }
  unsigned int get_length () const
  { return header.nUnits - last_is_terminator (); }
  unsigned int get_size () const
  { return header.static_size + header.nUnits * header.unitSize; }

  template <typename ...Ts>
  bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const
  {
    TRACE_SANITIZE (this);
    if (unlikely (!sanitize_shallow (c))) return_trace (false);
    if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true);
    unsigned int count = get_length ();
    for (unsigned int i = 0; i < count; i++)
      if (unlikely (!(*this)[i].sanitize (c, hb_forward<Ts> (ds)...)))
	return_trace (false);
    return_trace (true);
  }

  template <typename T>
  const Type *bsearch (const T &key) const
  {
    unsigned pos;
    return hb_bsearch_impl (&pos,
			    key,
			    (const void *) bytesZ,
			    get_length (),
			    header.unitSize,
			    _hb_cmp_method<T, Type>)
	   ? (const Type *) (((const char *) &bytesZ) + (pos * header.unitSize))
	   : nullptr;
  }

  private:
  bool sanitize_shallow (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (header.sanitize (c) &&
		  Type::static_size <= header.unitSize &&
		  c->check_range (bytesZ.arrayZ,
				  header.nUnits,
				  header.unitSize));
  }

  protected:
  VarSizedBinSearchHeader	header;
  UnsizedArrayOf<HBUINT8>	bytesZ;
  public:
  DEFINE_SIZE_ARRAY (10, bytesZ);
};

} /* namespace OT */

#endif /* HB_OPEN_TYPE_HH */

repo_language: C

mime_type: text/x-c


text:
/*
 * Copyright © 2011  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#include "hb.hh"

#ifdef HAVE_GOBJECT

/**
 * SECTION:hb-gobject
 * @title: hb-gobject
 * @short_description: GObject integration support
 * @include: hb-gobject.h
 *
 * Support for using HarfBuzz with the GObject library to provide
 * type data.
 *
 * The types and functions listed here are solely a linkage between
 * HarfBuzz's public data types and the GTypes used by the GObject framework.
 * HarfBuzz uses GObject introspection to generate its Python bindings
 * (and potentially other language bindings); client programs should never need
 * to access the GObject-integration mechanics.
 *
 * For client programs using the GNOME and GTK software stack, please see the
 * GLib and FreeType integration pages.
 **/

/* g++ didn't like older gtype.h gcc-only code path. */
#include <glib.h>
#if !GLIB_CHECK_VERSION(2,29,16)
#undef __GNUC__
#undef __GNUC_MINOR__
#define __GNUC__ 2
#define __GNUC_MINOR__ 6
#endif

#include "hb-gobject.h"

#define HB_DEFINE_BOXED_TYPE(name,copy_func,free_func) \
GType \
hb_gobject_##name##_get_type () \
{ \
   static gsize type_id = 0; \
   if (g_once_init_enter (&type_id)) { \
      GType id = g_boxed_type_register_static (g_intern_static_string ("hb_" #name "_t"), \
					       (GBoxedCopyFunc) copy_func, \
					       (GBoxedFreeFunc) free_func); \
      g_once_init_leave (&type_id, id); \
   } \
   return type_id; \
}

#define HB_DEFINE_OBJECT_TYPE(name) \
	HB_DEFINE_BOXED_TYPE (name, hb_##name##_reference, hb_##name##_destroy)

#define HB_DEFINE_VALUE_TYPE(name) \
	static hb_##name##_t *_hb_##name##_reference (const hb_##name##_t *l) \
	{ \
	  hb_##name##_t *c = (hb_##name##_t *) calloc (1, sizeof (hb_##name##_t)); \
	  if (unlikely (!c)) return nullptr; \
	  *c = *l; \
	  return c; \
	} \
	static void _hb_##name##_destroy (hb_##name##_t *l) { free (l); } \
	HB_DEFINE_BOXED_TYPE (name, _hb_##name##_reference, _hb_##name##_destroy)

HB_DEFINE_OBJECT_TYPE (buffer)
HB_DEFINE_OBJECT_TYPE (blob)
HB_DEFINE_OBJECT_TYPE (face)
HB_DEFINE_OBJECT_TYPE (font)
HB_DEFINE_OBJECT_TYPE (font_funcs)
HB_DEFINE_OBJECT_TYPE (set)
HB_DEFINE_OBJECT_TYPE (map)
HB_DEFINE_OBJECT_TYPE (shape_plan)
HB_DEFINE_OBJECT_TYPE (unicode_funcs)
HB_DEFINE_VALUE_TYPE (feature)
HB_DEFINE_VALUE_TYPE (glyph_info)
HB_DEFINE_VALUE_TYPE (glyph_position)
HB_DEFINE_VALUE_TYPE (segment_properties)
HB_DEFINE_VALUE_TYPE (user_data_key)

HB_DEFINE_VALUE_TYPE (ot_math_glyph_variant)
HB_DEFINE_VALUE_TYPE (ot_math_glyph_part)

#endif


text:
#!/bin/sh

LC_ALL=C
export LC_ALL

test -z "$srcdir" && srcdir=.
stat=0

test "x$HBHEADERS" = x && HBHEADERS=`cd "$srcdir"; find . -maxdepth 1 -name 'hb*.h'`
test "x$HBSOURCES" = x && HBSOURCES=`cd "$srcdir"; find . -maxdepth 1 -name 'hb*.cc'`

for x in $HBHEADERS; do
	test -f "$srcdir/$x" -a ! -f "$x" && x="$srcdir/$x"
	if ! grep -q HB_BEGIN_DECLS "$x" || ! grep -q HB_END_DECLS "$x"; then
		echo "Ouch, file $x does not have HB_BEGIN_DECLS / HB_END_DECLS, but it should"
		stat=1
	fi
done
for x in $HBSOURCES; do
	test -f "$srcdir/$x" -a ! -f "$x" && x="$srcdir/$x"
	if grep -q HB_BEGIN_DECLS "$x" || grep -q HB_END_DECLS "$x"; then
		echo "Ouch, file $x has HB_BEGIN_DECLS / HB_END_DECLS, but it shouldn't"
		stat=1
	fi
done

exit $stat


text:
/*
 * Copyright © 2011  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#ifndef HB_H_IN
#error "Include <hb.h> instead."
#endif

#ifndef HB_VERSION_H
#define HB_VERSION_H

#include "hb-common.h"

HB_BEGIN_DECLS

#define HB_VERSION_MAJOR @HB_VERSION_MAJOR@
#define HB_VERSION_MINOR @HB_VERSION_MINOR@
#define HB_VERSION_MICRO @HB_VERSION_MICRO@

#define HB_VERSION_STRING "@HB_VERSION@"

#define HB_VERSION_ATLEAST(major,minor,micro) \
	((major)*10000+(minor)*100+(micro) <= \
	 HB_VERSION_MAJOR*10000+HB_VERSION_MINOR*100+HB_VERSION_MICRO)

HB_EXTERN void
hb_version (unsigned int *major,
	    unsigned int *minor,
	    unsigned int *micro);

HB_EXTERN const char *
hb_version_string (void);

HB_EXTERN hb_bool_t
hb_version_atleast (unsigned int major,
		    unsigned int minor,
		    unsigned int micro);

HB_END_DECLS

#endif /* HB_VERSION_H */


text:
/*
 * Copyright © 2018  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#ifndef HB_OT_SHAPE_COMPLEX_MYANMAR_HH
#define HB_OT_SHAPE_COMPLEX_MYANMAR_HH

#include "hb.hh"

#include "hb-ot-shape-complex-indic.hh"

/* buffer var allocations */
#define myanmar_category() indic_category() /* myanmar_category_t */
#define myanmar_position() indic_position() /* myanmar_position_t */

/* Note: This enum is duplicated in the -machine.rl source file.
 * Not sure how to avoid duplication. */
enum myanmar_category_t {
  OT_As  = 18,  /* Asat */
  OT_D0  = 20, /* Digit zero */
  OT_DB  = OT_N, /* Dot below */
  OT_GB  = OT_PLACEHOLDER,
  OT_MH  = 21, /* Various consonant medial types */
  OT_MR  = 22, /* Various consonant medial types */
  OT_MW  = 23, /* Various consonant medial types */
  OT_MY  = 24, /* Various consonant medial types */
  OT_PT  = 25, /* Pwo and other tones */
  //OT_VAbv = 26,
  //OT_VBlw = 27,
  //OT_VPre = 28,
  //OT_VPst = 29,
  OT_VS   = 30, /* Variation selectors */
  OT_P    = 31, /* Punctuation */
  OT_D    = 32, /* Digits except zero */
};

static inline void
set_myanmar_properties (hb_glyph_info_t &info)
{
  hb_codepoint_t u = info.codepoint;
  unsigned int type = hb_indic_get_categories (u);
  unsigned int cat = type & 0x7Fu;
  indic_position_t pos = (indic_position_t) (type >> 8);

  /* Myanmar
   * https://docs.microsoft.com/en-us/typography/script-development/myanmar#analyze
   */
  if (unlikely (hb_in_range<hb_codepoint_t> (u, 0xFE00u, 0xFE0Fu)))
    cat = OT_VS;

  switch (u)
  {
    case 0x104Eu:
      cat = OT_C; /* The spec says C, IndicSyllableCategory doesn't have. */
      break;

    case 0x002Du: case 0x00A0u: case 0x00D7u: case 0x2012u:
    case 0x2013u: case 0x2014u: case 0x2015u: case 0x2022u:
    case 0x25CCu: case 0x25FBu: case 0x25FCu: case 0x25FDu:
    case 0x25FEu:
      cat = OT_GB;
      break;

    case 0x1004u: case 0x101Bu: case 0x105Au:
      cat = OT_Ra;
      break;

    case 0x1032u: case 0x1036u:
      cat = OT_A;
      break;

    case 0x1039u:
      cat = OT_H;
      break;

    case 0x103Au:
      cat = OT_As;
      break;

    case 0x1041u: case 0x1042u: case 0x1043u: case 0x1044u:
    case 0x1045u: case 0x1046u: case 0x1047u: case 0x1048u:
    case 0x1049u: case 0x1090u: case 0x1091u: case 0x1092u:
    case 0x1093u: case 0x1094u: case 0x1095u: case 0x1096u:
    case 0x1097u: case 0x1098u: case 0x1099u:
      cat = OT_D;
      break;

    case 0x1040u:
      cat = OT_D; /* XXX The spec says D0, but Uniscribe doesn't seem to do. */
      break;

    case 0x103Eu: case 0x1060u:
      cat = OT_MH;
      break;

    case 0x103Cu:
      cat = OT_MR;
      break;

    case 0x103Du: case 0x1082u:
      cat = OT_MW;
      break;

    case 0x103Bu: case 0x105Eu: case 0x105Fu:
      cat = OT_MY;
      break;

    case 0x1063u: case 0x1064u: case 0x1069u: case 0x106Au:
    case 0x106Bu: case 0x106Cu: case 0x106Du: case 0xAA7Bu:
      cat = OT_PT;
      break;

    case 0x1038u: case 0x1087u: case 0x1088u: case 0x1089u:
    case 0x108Au: case 0x108Bu: case 0x108Cu: case 0x108Du:
    case 0x108Fu: case 0x109Au: case 0x109Bu: case 0x109Cu:
      cat = OT_SM;
      break;

    case 0x104Au: case 0x104Bu:
      cat = OT_P;
      break;

    case 0xAA74u: case 0xAA75u: case 0xAA76u:
      /* https://github.com/harfbuzz/harfbuzz/issues/218 */
      cat = OT_C;
      break;
  }

  if (cat == OT_M)
  {
    switch ((int) pos)
    {
      case POS_PRE_C:	cat = (myanmar_category_t) OT_VPre;
			pos = POS_PRE_M; break;
      case POS_ABOVE_C:	cat = (myanmar_category_t) OT_VAbv;   break;
      case POS_BELOW_C:	cat = (myanmar_category_t) OT_VBlw;   break;
      case POS_POST_C:	cat = (myanmar_category_t) OT_VPst;   break;
    }
  }

  info.myanmar_category() = cat;
  info.myanmar_position() = pos;
}

#endif /* HB_OT_SHAPE_COMPLEX_MYANMAR_HH */


text:
/*
 * Copyright © 2011,2012  Google, Inc.
 * Copyright © 2018  Ebrahim Byagowi
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#ifndef HB_OT_OS2_TABLE_HH
#define HB_OT_OS2_TABLE_HH

#include "hb-open-type.hh"
#include "hb-ot-os2-unicode-ranges.hh"

#include "hb-set.hh"

/*
 * OS/2 and Windows Metrics
 * https://docs.microsoft.com/en-us/typography/opentype/spec/os2
 */
#define HB_OT_TAG_OS2 HB_TAG('O','S','/','2')

namespace OT {

struct OS2V1Tail
{
  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (c->check_struct (this));
  }

  public:
  HBUINT32	ulCodePageRange1;
  HBUINT32	ulCodePageRange2;
  public:
  DEFINE_SIZE_STATIC (8);
};

struct OS2V2Tail
{
  bool has_data () const { return sxHeight || sCapHeight; }

  const OS2V2Tail * operator -> () const { return this; }

  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (c->check_struct (this));
  }

  public:
  HBINT16	sxHeight;
  HBINT16	sCapHeight;
  HBUINT16	usDefaultChar;
  HBUINT16	usBreakChar;
  HBUINT16	usMaxContext;
  public:
  DEFINE_SIZE_STATIC (10);
};

struct OS2V5Tail
{
  inline bool get_optical_size (unsigned int *lower, unsigned int *upper) const
  {
    unsigned int lower_optical_size = usLowerOpticalPointSize;
    unsigned int upper_optical_size = usUpperOpticalPointSize;

    /* Per https://docs.microsoft.com/en-us/typography/opentype/spec/os2#lps */
    if (lower_optical_size < upper_optical_size &&
	lower_optical_size >= 1 && lower_optical_size <= 0xFFFE &&
	upper_optical_size >= 2 && upper_optical_size <= 0xFFFF)
    {
      *lower = lower_optical_size;
      *upper = upper_optical_size;
      return true;
    }
    return false;
  }

  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    return_trace (c->check_struct (this));
  }

  public:
  HBUINT16	usLowerOpticalPointSize;
  HBUINT16	usUpperOpticalPointSize;
  public:
  DEFINE_SIZE_STATIC (4);
};

struct OS2
{
  static constexpr hb_tag_t tableTag = HB_OT_TAG_OS2;

  bool has_data () const { return usWeightClass || usWidthClass || usFirstCharIndex || usLastCharIndex; }

  const OS2V1Tail &v1 () const { return version >= 1 ? v1X : Null (OS2V1Tail); }
  const OS2V2Tail &v2 () const { return version >= 2 ? v2X : Null (OS2V2Tail); }
  const OS2V5Tail &v5 () const { return version >= 5 ? v5X : Null (OS2V5Tail); }

  enum selection_flag_t {
    ITALIC		= 1u<<0,
    UNDERSCORE		= 1u<<1,
    NEGATIVE		= 1u<<2,
    OUTLINED		= 1u<<3,
    STRIKEOUT		= 1u<<4,
    BOLD		= 1u<<5,
    REGULAR		= 1u<<6,
    USE_TYPO_METRICS	= 1u<<7,
    WWS			= 1u<<8,
    OBLIQUE		= 1u<<9
  };

  bool        is_italic () const { return fsSelection & ITALIC; }
  bool       is_oblique () const { return fsSelection & OBLIQUE; }
  bool use_typo_metrics () const { return fsSelection & USE_TYPO_METRICS; }

  enum width_class_t {
    FWIDTH_ULTRA_CONDENSED	= 1, /* 50% */
    FWIDTH_EXTRA_CONDENSED	= 2, /* 62.5% */
    FWIDTH_CONDENSED		= 3, /* 75% */
    FWIDTH_SEMI_CONDENSED	= 4, /* 87.5% */
    FWIDTH_NORMAL		= 5, /* 100% */
    FWIDTH_SEMI_EXPANDED	= 6, /* 112.5% */
    FWIDTH_EXPANDED		= 7, /* 125% */
    FWIDTH_EXTRA_EXPANDED	= 8, /* 150% */
    FWIDTH_ULTRA_EXPANDED	= 9  /* 200% */
  };

  float get_width () const
  {
    switch (usWidthClass) {
    case FWIDTH_ULTRA_CONDENSED:return 50.f;
    case FWIDTH_EXTRA_CONDENSED:return 62.5f;
    case FWIDTH_CONDENSED:	return 75.f;
    case FWIDTH_SEMI_CONDENSED:	return 87.5f;
    default:
    case FWIDTH_NORMAL:		return 100.f;
    case FWIDTH_SEMI_EXPANDED:	return 112.5f;
    case FWIDTH_EXPANDED:	return 125.f;
    case FWIDTH_EXTRA_EXPANDED:	return 150.f;
    case FWIDTH_ULTRA_EXPANDED:	return 200.f;
    }
  }

  bool subset (hb_subset_context_t *c) const
  {
    TRACE_SUBSET (this);
    OS2 *os2_prime = c->serializer->embed (this);
    if (unlikely (!os2_prime)) return_trace (false);

    uint16_t min_cp, max_cp;
    find_min_and_max_codepoint (c->plan->unicodes, &min_cp, &max_cp);
    os2_prime->usFirstCharIndex = min_cp;
    os2_prime->usLastCharIndex = max_cp;

    _update_unicode_ranges (c->plan->unicodes, os2_prime->ulUnicodeRange);

    return_trace (true);
  }

  void _update_unicode_ranges (const hb_set_t *codepoints,
			       HBUINT32 ulUnicodeRange[4]) const
  {
    HBUINT32	newBits[4];
    for (unsigned int i = 0; i < 4; i++)
      newBits[i] = 0;

    hb_codepoint_t cp = HB_SET_VALUE_INVALID;
    while (codepoints->next (&cp)) {
      unsigned int bit = _hb_ot_os2_get_unicode_range_bit (cp);
      if (bit < 128)
      {
	unsigned int block = bit / 32;
	unsigned int bit_in_block = bit % 32;
	unsigned int mask = 1 << bit_in_block;
	newBits[block] = newBits[block] | mask;
      }
      if (cp >= 0x10000 && cp <= 0x110000)
      {
	/* the spec says that bit 57 ("Non Plane 0") implies that there's
	   at least one codepoint beyond the BMP; so I also include all
	   the non-BMP codepoints here */
	newBits[1] = newBits[1] | (1 << 25);
      }
    }

    for (unsigned int i = 0; i < 4; i++)
      ulUnicodeRange[i] = ulUnicodeRange[i] & newBits[i]; // set bits only if set in the original
  }

  static void find_min_and_max_codepoint (const hb_set_t *codepoints,
					  uint16_t *min_cp, /* OUT */
					  uint16_t *max_cp  /* OUT */)
  {
    *min_cp = hb_min (0xFFFFu, codepoints->get_min ());
    *max_cp = hb_min (0xFFFFu, codepoints->get_max ());
  }

  /* https://github.com/Microsoft/Font-Validator/blob/520aaae/OTFontFileVal/val_OS2.cs#L644-L681 */
  enum font_page_t
  {
    FONT_PAGE_HEBREW		= 0xB100, /* Hebrew Windows 3.1 font page */
    FONT_PAGE_SIMP_ARABIC	= 0xB200, /* Simplified Arabic Windows 3.1 font page */
    FONT_PAGE_TRAD_ARABIC	= 0xB300, /* Traditional Arabic Windows 3.1 font page */
    FONT_PAGE_OEM_ARABIC	= 0xB400, /* OEM Arabic Windows 3.1 font page */
    FONT_PAGE_SIMP_FARSI	= 0xBA00, /* Simplified Farsi Windows 3.1 font page */
    FONT_PAGE_TRAD_FARSI	= 0xBB00, /* Traditional Farsi Windows 3.1 font page */
    FONT_PAGE_THAI		= 0xDE00  /* Thai Windows 3.1 font page */
  };
  font_page_t get_font_page () const
  { return (font_page_t) (version == 0 ? fsSelection & 0xFF00 : 0); }

  unsigned get_size () const
  {
    unsigned result = min_size;
    if (version >= 1) result += v1X.get_size ();
    if (version >= 2) result += v2X.get_size ();
    if (version >= 5) result += v5X.get_size ();
    return result;
  }

  bool sanitize (hb_sanitize_context_t *c) const
  {
    TRACE_SANITIZE (this);
    if (unlikely (!c->check_struct (this))) return_trace (false);
    if (unlikely (version >= 1 && !v1X.sanitize (c))) return_trace (false);
    if (unlikely (version >= 2 && !v2X.sanitize (c))) return_trace (false);
    if (unlikely (version >= 5 && !v5X.sanitize (c))) return_trace (false);
    return_trace (true);
  }

  public:
  HBUINT16	version;
  HBINT16	xAvgCharWidth;
  HBUINT16	usWeightClass;
  HBUINT16	usWidthClass;
  HBUINT16	fsType;
  HBINT16	ySubscriptXSize;
  HBINT16	ySubscriptYSize;
  HBINT16	ySubscriptXOffset;
  HBINT16	ySubscriptYOffset;
  HBINT16	ySuperscriptXSize;
  HBINT16	ySuperscriptYSize;
  HBINT16	ySuperscriptXOffset;
  HBINT16	ySuperscriptYOffset;
  HBINT16	yStrikeoutSize;
  HBINT16	yStrikeoutPosition;
  HBINT16	sFamilyClass;
  HBUINT8	panose[10];
  HBUINT32	ulUnicodeRange[4];
  Tag		achVendID;
  HBUINT16	fsSelection;
  HBUINT16	usFirstCharIndex;
  HBUINT16	usLastCharIndex;
  HBINT16	sTypoAscender;
  HBINT16	sTypoDescender;
  HBINT16	sTypoLineGap;
  HBUINT16	usWinAscent;
  HBUINT16	usWinDescent;
  OS2V1Tail	v1X;
  OS2V2Tail	v2X;
  OS2V5Tail	v5X;
  public:
  DEFINE_SIZE_MIN (78);
};

} /* namespace OT */

#endif /* HB_OT_OS2_TABLE_HH */


text:
/*
 * Copyright © 2018  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Garret Rieger
 */

#ifndef HB_OT_OS2_UNICODE_RANGES_HH
#define HB_OT_OS2_UNICODE_RANGES_HH

#include "hb.hh"

namespace OT {

struct OS2Range
{
  int cmp (hb_codepoint_t key) const
  { return (key < start) ? -1 : key <= end ? 0 : +1; }

  hb_codepoint_t start;
  hb_codepoint_t end;
  unsigned int bit;
};

/* Note: The contents of this array was generated using gen-os2-unicode-ranges.py. */
static const OS2Range _hb_os2_unicode_ranges[] =
{
  {     0x0,     0x7F,   0}, // Basic Latin
  {    0x80,     0xFF,   1}, // Latin-1 Supplement
  {   0x100,    0x17F,   2}, // Latin Extended-A
  {   0x180,    0x24F,   3}, // Latin Extended-B
  {   0x250,    0x2AF,   4}, // IPA Extensions
  {   0x2B0,    0x2FF,   5}, // Spacing Modifier Letters
  {   0x300,    0x36F,   6}, // Combining Diacritical Marks
  {   0x370,    0x3FF,   7}, // Greek and Coptic
  {   0x400,    0x4FF,   9}, // Cyrillic
  {   0x500,    0x52F,   9}, // Cyrillic Supplement
  {   0x530,    0x58F,  10}, // Armenian
  {   0x590,    0x5FF,  11}, // Hebrew
  {   0x600,    0x6FF,  13}, // Arabic
  {   0x700,    0x74F,  71}, // Syriac
  {   0x750,    0x77F,  13}, // Arabic Supplement
  {   0x780,    0x7BF,  72}, // Thaana
  {   0x7C0,    0x7FF,  14}, // NKo
  {   0x900,    0x97F,  15}, // Devanagari
  {   0x980,    0x9FF,  16}, // Bengali
  {   0xA00,    0xA7F,  17}, // Gurmukhi
  {   0xA80,    0xAFF,  18}, // Gujarati
  {   0xB00,    0xB7F,  19}, // Oriya
  {   0xB80,    0xBFF,  20}, // Tamil
  {   0xC00,    0xC7F,  21}, // Telugu
  {   0xC80,    0xCFF,  22}, // Kannada
  {   0xD00,    0xD7F,  23}, // Malayalam
  {   0xD80,    0xDFF,  73}, // Sinhala
  {   0xE00,    0xE7F,  24}, // Thai
  {   0xE80,    0xEFF,  25}, // Lao
  {   0xF00,    0xFFF,  70}, // Tibetan
  {  0x1000,   0x109F,  74}, // Myanmar
  {  0x10A0,   0x10FF,  26}, // Georgian
  {  0x1100,   0x11FF,  28}, // Hangul Jamo
  {  0x1200,   0x137F,  75}, // Ethiopic
  {  0x1380,   0x139F,  75}, // Ethiopic Supplement
  {  0x13A0,   0x13FF,  76}, // Cherokee
  {  0x1400,   0x167F,  77}, // Unified Canadian Aboriginal Syllabics
  {  0x1680,   0x169F,  78}, // Ogham
  {  0x16A0,   0x16FF,  79}, // Runic
  {  0x1700,   0x171F,  84}, // Tagalog
  {  0x1720,   0x173F,  84}, // Hanunoo
  {  0x1740,   0x175F,  84}, // Buhid
  {  0x1760,   0x177F,  84}, // Tagbanwa
  {  0x1780,   0x17FF,  80}, // Khmer
  {  0x1800,   0x18AF,  81}, // Mongolian
  {  0x1900,   0x194F,  93}, // Limbu
  {  0x1950,   0x197F,  94}, // Tai Le
  {  0x1980,   0x19DF,  95}, // New Tai Lue
  {  0x19E0,   0x19FF,  80}, // Khmer Symbols
  {  0x1A00,   0x1A1F,  96}, // Buginese
  {  0x1B00,   0x1B7F,  27}, // Balinese
  {  0x1B80,   0x1BBF, 112}, // Sundanese
  {  0x1C00,   0x1C4F, 113}, // Lepcha
  {  0x1C50,   0x1C7F, 114}, // Ol Chiki
  {  0x1D00,   0x1D7F,   4}, // Phonetic Extensions
  {  0x1D80,   0x1DBF,   4}, // Phonetic Extensions Supplement
  {  0x1DC0,   0x1DFF,   6}, // Combining Diacritical Marks Supplement
  {  0x1E00,   0x1EFF,  29}, // Latin Extended Additional
  {  0x1F00,   0x1FFF,  30}, // Greek Extended
  {  0x2000,   0x206F,  31}, // General Punctuation
  {  0x2070,   0x209F,  32}, // Superscripts And Subscripts
  {  0x20A0,   0x20CF,  33}, // Currency Symbols
  {  0x20D0,   0x20FF,  34}, // Combining Diacritical Marks For Symbols
  {  0x2100,   0x214F,  35}, // Letterlike Symbols
  {  0x2150,   0x218F,  36}, // Number Forms
  {  0x2190,   0x21FF,  37}, // Arrows
  {  0x2200,   0x22FF,  38}, // Mathematical Operators
  {  0x2300,   0x23FF,  39}, // Miscellaneous Technical
  {  0x2400,   0x243F,  40}, // Control Pictures
  {  0x2440,   0x245F,  41}, // Optical Character Recognition
  {  0x2460,   0x24FF,  42}, // Enclosed Alphanumerics
  {  0x2500,   0x257F,  43}, // Box Drawing
  {  0x2580,   0x259F,  44}, // Block Elements
  {  0x25A0,   0x25FF,  45}, // Geometric Shapes
  {  0x2600,   0x26FF,  46}, // Miscellaneous Symbols
  {  0x2700,   0x27BF,  47}, // Dingbats
  {  0x27C0,   0x27EF,  38}, // Miscellaneous Mathematical Symbols-A
  {  0x27F0,   0x27FF,  37}, // Supplemental Arrows-A
  {  0x2800,   0x28FF,  82}, // Braille Patterns
  {  0x2900,   0x297F,  37}, // Supplemental Arrows-B
  {  0x2980,   0x29FF,  38}, // Miscellaneous Mathematical Symbols-B
  {  0x2A00,   0x2AFF,  38}, // Supplemental Mathematical Operators
  {  0x2B00,   0x2BFF,  37}, // Miscellaneous Symbols and Arrows
  {  0x2C00,   0x2C5F,  97}, // Glagolitic
  {  0x2C60,   0x2C7F,  29}, // Latin Extended-C
  {  0x2C80,   0x2CFF,   8}, // Coptic
  {  0x2D00,   0x2D2F,  26}, // Georgian Supplement
  {  0x2D30,   0x2D7F,  98}, // Tifinagh
  {  0x2D80,   0x2DDF,  75}, // Ethiopic Extended
  {  0x2DE0,   0x2DFF,   9}, // Cyrillic Extended-A
  {  0x2E00,   0x2E7F,  31}, // Supplemental Punctuation
  {  0x2E80,   0x2EFF,  59}, // CJK Radicals Supplement
  {  0x2F00,   0x2FDF,  59}, // Kangxi Radicals
  {  0x2FF0,   0x2FFF,  59}, // Ideographic Description Characters
  {  0x3000,   0x303F,  48}, // CJK Symbols And Punctuation
  {  0x3040,   0x309F,  49}, // Hiragana
  {  0x30A0,   0x30FF,  50}, // Katakana
  {  0x3100,   0x312F,  51}, // Bopomofo
  {  0x3130,   0x318F,  52}, // Hangul Compatibility Jamo
  {  0x3190,   0x319F,  59}, // Kanbun
  {  0x31A0,   0x31BF,  51}, // Bopomofo Extended
  {  0x31C0,   0x31EF,  61}, // CJK Strokes
  {  0x31F0,   0x31FF,  50}, // Katakana Phonetic Extensions
  {  0x3200,   0x32FF,  54}, // Enclosed CJK Letters And Months
  {  0x3300,   0x33FF,  55}, // CJK Compatibility
  {  0x3400,   0x4DBF,  59}, // CJK Unified Ideographs Extension A
  {  0x4DC0,   0x4DFF,  99}, // Yijing Hexagram Symbols
  {  0x4E00,   0x9FFF,  59}, // CJK Unified Ideographs
  {  0xA000,   0xA48F,  83}, // Yi Syllables
  {  0xA490,   0xA4CF,  83}, // Yi Radicals
  {  0xA500,   0xA63F,  12}, // Vai
  {  0xA640,   0xA69F,   9}, // Cyrillic Extended-B
  {  0xA700,   0xA71F,   5}, // Modifier Tone Letters
  {  0xA720,   0xA7FF,  29}, // Latin Extended-D
  {  0xA800,   0xA82F, 100}, // Syloti Nagri
  {  0xA840,   0xA87F,  53}, // Phags-pa
  {  0xA880,   0xA8DF, 115}, // Saurashtra
  {  0xA900,   0xA92F, 116}, // Kayah Li
  {  0xA930,   0xA95F, 117}, // Rejang
  {  0xAA00,   0xAA5F, 118}, // Cham
  {  0xAC00,   0xD7AF,  56}, // Hangul Syllables
  {  0xD800,   0xDFFF,  57}, // Non-Plane 0 *
  {  0xE000,   0xF8FF,  60}, // Private Use Area (plane 0)
  {  0xF900,   0xFAFF,  61}, // CJK Compatibility Ideographs
  {  0xFB00,   0xFB4F,  62}, // Alphabetic Presentation Forms
  {  0xFB50,   0xFDFF,  63}, // Arabic Presentation Forms-A
  {  0xFE00,   0xFE0F,  91}, // Variation Selectors
  {  0xFE10,   0xFE1F,  65}, // Vertical Forms
  {  0xFE20,   0xFE2F,  64}, // Combining Half Marks
  {  0xFE30,   0xFE4F,  65}, // CJK Compatibility Forms
  {  0xFE50,   0xFE6F,  66}, // Small Form Variants
  {  0xFE70,   0xFEFF,  67}, // Arabic Presentation Forms-B
  {  0xFF00,   0xFFEF,  68}, // Halfwidth And Fullwidth Forms
  {  0xFFF0,   0xFFFF,  69}, // Specials
  { 0x10000,  0x1007F, 101}, // Linear B Syllabary
  { 0x10080,  0x100FF, 101}, // Linear B Ideograms
  { 0x10100,  0x1013F, 101}, // Aegean Numbers
  { 0x10140,  0x1018F, 102}, // Ancient Greek Numbers
  { 0x10190,  0x101CF, 119}, // Ancient Symbols
  { 0x101D0,  0x101FF, 120}, // Phaistos Disc
  { 0x10280,  0x1029F, 121}, // Lycian
  { 0x102A0,  0x102DF, 121}, // Carian
  { 0x10300,  0x1032F,  85}, // Old Italic
  { 0x10330,  0x1034F,  86}, // Gothic
  { 0x10380,  0x1039F, 103}, // Ugaritic
  { 0x103A0,  0x103DF, 104}, // Old Persian
  { 0x10400,  0x1044F,  87}, // Deseret
  { 0x10450,  0x1047F, 105}, // Shavian
  { 0x10480,  0x104AF, 106}, // Osmanya
  { 0x10800,  0x1083F, 107}, // Cypriot Syllabary
  { 0x10900,  0x1091F,  58}, // Phoenician
  { 0x10920,  0x1093F, 121}, // Lydian
  { 0x10A00,  0x10A5F, 108}, // Kharoshthi
  { 0x12000,  0x123FF, 110}, // Cuneiform
  { 0x12400,  0x1247F, 110}, // Cuneiform Numbers and Punctuation
  { 0x1D000,  0x1D0FF,  88}, // Byzantine Musical Symbols
  { 0x1D100,  0x1D1FF,  88}, // Musical Symbols
  { 0x1D200,  0x1D24F,  88}, // Ancient Greek Musical Notation
  { 0x1D300,  0x1D35F, 109}, // Tai Xuan Jing Symbols
  { 0x1D360,  0x1D37F, 111}, // Counting Rod Numerals
  { 0x1D400,  0x1D7FF,  89}, // Mathematical Alphanumeric Symbols
  { 0x1F000,  0x1F02F, 122}, // Mahjong Tiles
  { 0x1F030,  0x1F09F, 122}, // Domino Tiles
  { 0x20000,  0x2A6DF,  59}, // CJK Unified Ideographs Extension B
  { 0x2F800,  0x2FA1F,  61}, // CJK Compatibility Ideographs Supplement
  { 0xE0000,  0xE007F,  92}, // Tags
  { 0xE0100,  0xE01EF,  91}, // Variation Selectors Supplement
  { 0xF0000,  0xFFFFD,  90}, // Private Use (plane 15)
  {0x100000, 0x10FFFD,  90}, // Private Use (plane 16)
};

/**
 * _hb_ot_os2_get_unicode_range_bit:
 * Returns the bit to be set in os/2 ulUnicodeOS2Range for a given codepoint.
 **/
static unsigned int
_hb_ot_os2_get_unicode_range_bit (hb_codepoint_t cp)
{
  auto *range = hb_sorted_array (_hb_os2_unicode_ranges).bsearch (cp);
  return range ? range->bit : -1;
}

} /* namespace OT */

#endif /* HB_OT_OS2_UNICODE_RANGES_HH */


text:
/*
 * Copyright © 2011  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#include "hb-shaper-impl.hh"

#ifndef HB_NO_FALLBACK_SHAPE

/*
 * shaper face data
 */

struct hb_fallback_face_data_t {};

hb_fallback_face_data_t *
_hb_fallback_shaper_face_data_create (hb_face_t *face HB_UNUSED)
{
  return (hb_fallback_face_data_t *) HB_SHAPER_DATA_SUCCEEDED;
}

void
_hb_fallback_shaper_face_data_destroy (hb_fallback_face_data_t *data HB_UNUSED)
{
}

/*
 * shaper font data
 */

struct hb_fallback_font_data_t {};

hb_fallback_font_data_t *
_hb_fallback_shaper_font_data_create (hb_font_t *font HB_UNUSED)
{
  return (hb_fallback_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
}

void
_hb_fallback_shaper_font_data_destroy (hb_fallback_font_data_t *data HB_UNUSED)
{
}

/*
 * shaper
 */

hb_bool_t
_hb_fallback_shape (hb_shape_plan_t    *shape_plan HB_UNUSED,
		    hb_font_t          *font,
		    hb_buffer_t        *buffer,
		    const hb_feature_t *features HB_UNUSED,
		    unsigned int        num_features HB_UNUSED)
{
  /* TODO
   *
   * - Apply fallback kern.
   * - Handle Variation Selectors?
   * - Apply normalization?
   *
   * This will make the fallback shaper into a dumb "TrueType"
   * shaper which many people unfortunately still request.
   */

  hb_codepoint_t space;
  bool has_space = (bool) font->get_nominal_glyph (' ', &space);

  buffer->clear_positions ();

  hb_direction_t direction = buffer->props.direction;
  hb_unicode_funcs_t *unicode = buffer->unicode;
  unsigned int count = buffer->len;
  hb_glyph_info_t *info = buffer->info;
  hb_glyph_position_t *pos = buffer->pos;
  for (unsigned int i = 0; i < count; i++)
  {
    if (has_space && unicode->is_default_ignorable (info[i].codepoint)) {
      info[i].codepoint = space;
      pos[i].x_advance = 0;
      pos[i].y_advance = 0;
      continue;
    }
    (void) font->get_nominal_glyph (info[i].codepoint, &info[i].codepoint);
    font->get_glyph_advance_for_direction (info[i].codepoint,
					   direction,
					   &pos[i].x_advance,
					   &pos[i].y_advance);
    font->subtract_glyph_origin_for_direction (info[i].codepoint,
					       direction,
					       &pos[i].x_offset,
					       &pos[i].y_offset);
  }

  if (HB_DIRECTION_IS_BACKWARD (direction))
    hb_buffer_reverse (buffer);

  buffer->safe_to_break_all ();

  return true;
}

#endif


text:
#line 1 "hb-ot-shape-complex-use-machine.rl"
/*
 * Copyright © 2015  Mozilla Foundation.
 * Copyright © 2015  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Mozilla Author(s): Jonathan Kew
 * Google Author(s): Behdad Esfahbod
 */

#ifndef HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH
#define HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH

#include "hb.hh"

#line 38 "hb-ot-shape-complex-use-machine.hh"
static const unsigned char _use_syllable_machine_trans_keys[] = {
	12u, 48u, 1u, 15u, 1u, 1u, 12u, 48u, 1u, 1u, 0u, 48u, 21u, 21u, 11u, 48u,
	11u, 48u, 1u, 15u, 1u, 1u, 11u, 48u, 22u, 48u, 23u, 48u, 24u, 47u, 25u, 47u,
	26u, 47u, 45u, 46u, 46u, 46u, 24u, 48u, 24u, 48u, 24u, 48u, 1u, 1u, 24u, 48u,
	23u, 48u, 23u, 48u, 23u, 48u, 22u, 48u, 22u, 48u, 22u, 48u, 22u, 48u, 11u, 48u,
	1u, 48u, 11u, 48u, 13u, 21u, 4u, 4u, 13u, 13u, 11u, 48u, 11u, 48u, 41u, 42u,
	42u, 42u, 11u, 48u, 11u, 48u, 22u, 48u, 23u, 48u, 24u, 47u, 25u, 47u, 26u, 47u,
	45u, 46u, 46u, 46u, 24u, 48u, 24u, 48u, 24u, 48u, 24u, 48u, 23u, 48u, 23u, 48u,
	23u, 48u, 22u, 48u, 22u, 48u, 22u, 48u, 22u, 48u, 11u, 48u, 1u, 48u, 1u, 15u,
	4u, 4u, 13u, 21u, 13u, 13u, 12u, 48u, 1u, 48u, 11u, 48u, 41u, 42u, 42u, 42u,
	21u, 42u, 1u, 5u, 0
};

static const char _use_syllable_machine_key_spans[] = {
	37, 15, 1, 37, 1, 49, 1, 38,
	38, 15, 1, 38, 27, 26, 24, 23,
	22, 2, 1, 25, 25, 25, 1, 25,
	26, 26, 26, 27, 27, 27, 27, 38,
	48, 38, 9, 1, 1, 38, 38, 2,
	1, 38, 38, 27, 26, 24, 23, 22,
	2, 1, 25, 25, 25, 25, 26, 26,
	26, 27, 27, 27, 27, 38, 48, 15,
	1, 9, 1, 37, 48, 38, 2, 1,
	22, 5
};

static const short _use_syllable_machine_index_offsets[] = {
	0, 38, 54, 56, 94, 96, 146, 148,
	187, 226, 242, 244, 283, 311, 338, 363,
	387, 410, 413, 415, 441, 467, 493, 495,
	521, 548, 575, 602, 630, 658, 686, 714,
	753, 802, 841, 851, 853, 855, 894, 933,
	936, 938, 977, 1016, 1044, 1071, 1096, 1120,
	1143, 1146, 1148, 1174, 1200, 1226, 1252, 1279,
	1306, 1333, 1361, 1389, 1417, 1445, 1484, 1533,
	1549, 1551, 1561, 1563, 1601, 1650, 1689, 1692,
	1694, 1717
};

static const char _use_syllable_machine_indicies[] = {
	1, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	1, 0, 0, 0, 1, 0, 3, 2,
	2, 2, 2, 2, 2, 2, 2, 2,
	2, 2, 2, 2, 4, 2, 3, 2,
	6, 5, 5, 5, 5, 5, 5, 5,
	5, 5, 5, 5, 5, 5, 5, 5,
	5, 5, 5, 5, 5, 5, 5, 5,
	5, 5, 5, 5, 5, 5, 5, 5,
	6, 5, 5, 5, 6, 5, 7, 5,
	8, 9, 10, 8, 11, 12, 10, 10,
	10, 10, 10, 3, 13, 14, 10, 15,
	8, 8, 16, 17, 10, 10, 18, 19,
	20, 21, 22, 23, 24, 18, 25, 26,
	27, 28, 29, 30, 10, 31, 32, 33,
	10, 34, 35, 36, 37, 38, 39, 40,
	13, 10, 42, 41, 44, 1, 43, 43,
	45, 43, 43, 43, 43, 43, 46, 47,
	48, 49, 50, 51, 52, 53, 47, 54,
	46, 55, 56, 57, 58, 43, 59, 60,
	61, 43, 43, 43, 43, 62, 63, 64,
	65, 1, 43, 44, 1, 43, 43, 45,
	43, 43, 43, 43, 43, 66, 47, 48,
	49, 50, 51, 52, 53, 47, 54, 55,
	55, 56, 57, 58, 43, 59, 60, 61,
	43, 43, 43, 43, 62, 63, 64, 65,
	1, 43, 44, 67, 67, 67, 67, 67,
	67, 67, 67, 67, 67, 67, 67, 67,
	68, 67, 44, 67, 44, 1, 43, 43,
	45, 43, 43, 43, 43, 43, 43, 47,
	48, 49, 50, 51, 52, 53, 47, 54,
	55, 55, 56, 57, 58, 43, 59, 60,
	61, 43, 43, 43, 43, 62, 63, 64,
	65, 1, 43, 47, 48, 49, 50, 51,
	43, 43, 43, 43, 43, 43, 56, 57,
	58, 43, 59, 60, 61, 43, 43, 43,
	43, 48, 63, 64, 65, 69, 43, 48,
	49, 50, 51, 43, 43, 43, 43, 43,
	43, 43, 43, 43, 43, 59, 60, 61,
	43, 43, 43, 43, 43, 63, 64, 65,
	69, 43, 49, 50, 51, 43, 43, 43,
	43, 43, 43, 43, 43, 43, 43, 43,
	43, 43, 43, 43, 43, 43, 43, 63,
	64, 65, 43, 50, 51, 43, 43, 43,
	43, 43, 43, 43, 43, 43, 43, 43,
	43, 43, 43, 43, 43, 43, 43, 63,
	64, 65, 43, 51, 43, 43, 43, 43,
	43, 43, 43, 43, 43, 43, 43, 43,
	43, 43, 43, 43, 43, 43, 63, 64,
	65, 43, 63, 64, 43, 64, 43, 49,
	50, 51, 43, 43, 43, 43, 43, 43,
	43, 43, 43, 43, 59, 60, 61, 43,
	43, 43, 43, 43, 63, 64, 65, 69,
	43, 49, 50, 51, 43, 43, 43, 43,
	43, 43, 43, 43, 43, 43, 43, 60,
	61, 43, 43, 43, 43, 43, 63, 64,
	65, 69, 43, 49, 50, 51, 43, 43,
	43, 43, 43, 43, 43, 43, 43, 43,
	43, 43, 61, 43, 43, 43, 43, 43,
	63, 64, 65, 69, 43, 71, 70, 49,
	50, 51, 43, 43, 43, 43, 43, 43,
	43, 43, 43, 43, 43, 43, 43, 43,
	43, 43, 43, 43, 63, 64, 65, 69,
	43, 48, 49, 50, 51, 43, 43, 43,
	43, 43, 43, 56, 57, 58, 43, 59,
	60, 61, 43, 43, 43, 43, 48, 63,
	64, 65, 69, 43, 48, 49, 50, 51,
	43, 43, 43, 43, 43, 43, 43, 57,
	58, 43, 59, 60, 61, 43, 43, 43,
	43, 48, 63, 64, 65, 69, 43, 48,
	49, 50, 51, 43, 43, 43, 43, 43,
	43, 43, 43, 58, 43, 59, 60, 61,
	43, 43, 43, 43, 48, 63, 64, 65,
	69, 43, 47, 48, 49, 50, 51, 43,
	53, 47, 43, 43, 43, 56, 57, 58,
	43, 59, 60, 61, 43, 43, 43, 43,
	48, 63, 64, 65, 69, 43, 47, 48,
	49, 50, 51, 43, 72, 47, 43, 43,
	43, 56, 57, 58, 43, 59, 60, 61,
	43, 43, 43, 43, 48, 63, 64, 65,
	69, 43, 47, 48, 49, 50, 51, 43,
	43, 47, 43, 43, 43, 56, 57, 58,
	43, 59, 60, 61, 43, 43, 43, 43,
	48, 63, 64, 65, 69, 43, 47, 48,
	49, 50, 51, 52, 53, 47, 43, 43,
	43, 56, 57, 58, 43, 59, 60, 61,
	43, 43, 43, 43, 48, 63, 64, 65,
	69, 43, 44, 1, 43, 43, 45, 43,
	43, 43, 43, 43, 43, 47, 48, 49,
	50, 51, 52, 53, 47, 54, 43, 55,
	56, 57, 58, 43, 59, 60, 61, 43,
	43, 43, 43, 62, 63, 64, 65, 1,
	43, 44, 67, 67, 67, 67, 67, 67,
	67, 67, 67, 67, 67, 67, 67, 68,
	67, 67, 67, 67, 67, 67, 67, 48,
	49, 50, 51, 67, 67, 67, 67, 67,
	67, 67, 67, 67, 67, 59, 60, 61,
	67, 67, 67, 67, 67, 63, 64, 65,
	69, 67, 44, 1, 43, 43, 45, 43,
	43, 43, 43, 43, 43, 47, 48, 49,
	50, 51, 52, 53, 47, 54, 46, 55,
	56, 57, 58, 43, 59, 60, 61, 43,
	43, 43, 43, 62, 63, 64, 65, 1,
	43, 74, 73, 73, 73, 73, 73, 73,
	73, 75, 73, 11, 76, 74, 73, 44,
	1, 43, 43, 45, 43, 43, 43, 43,
	43, 77, 47, 48, 49, 50, 51, 52,
	53, 47, 54, 46, 55, 56, 57, 58,
	43, 59, 60, 61, 43, 78, 79, 43,
	62, 63, 64, 65, 1, 43, 44, 1,
	43, 43, 45, 43, 43, 43, 43, 43,
	43, 47, 48, 49, 50, 51, 52, 53,
	47, 54, 46, 55, 56, 57, 58, 43,
	59, 60, 61, 43, 78, 79, 43, 62,
	63, 64, 65, 1, 43, 78, 79, 80,
	79, 80, 3, 6, 81, 81, 82, 81,
	81, 81, 81, 81, 83, 18, 19, 20,
	21, 22, 23, 24, 18, 25, 27, 27,
	28, 29, 30, 81, 31, 32, 33, 81,
	81, 81, 81, 37, 38, 39, 40, 6,
	81, 3, 6, 81, 81, 82, 81, 81,
	81, 81, 81, 81, 18, 19, 20, 21,
	22, 23, 24, 18, 25, 27, 27, 28,
	29, 30, 81, 31, 32, 33, 81, 81,
	81, 81, 37, 38, 39, 40, 6, 81,
	18, 19, 20, 21, 22, 81, 81, 81,
	81, 81, 81, 28, 29, 30, 81, 31,
	32, 33, 81, 81, 81, 81, 19, 38,
	39, 40, 84, 81, 19, 20, 21, 22,
	81, 81, 81, 81, 81, 81, 81, 81,
	81, 81, 31, 32, 33, 81, 81, 81,
	81, 81, 38, 39, 40, 84, 81, 20,
	21, 22, 81, 81, 81, 81, 81, 81,
	81, 81, 81, 81, 81, 81, 81, 81,
	81, 81, 81, 81, 38, 39, 40, 81,
	21, 22, 81, 81, 81, 81, 81, 81,
	81, 81, 81, 81, 81, 81, 81, 81,
	81, 81, 81, 81, 38, 39, 40, 81,
	22, 81, 81, 81, 81, 81, 81, 81,
	81, 81, 81, 81, 81, 81, 81, 81,
	81, 81, 81, 38, 39, 40, 81, 38,
	39, 81, 39, 81, 20, 21, 22, 81,
	81, 81, 81, 81, 81, 81, 81, 81,
	81, 31, 32, 33, 81, 81, 81, 81,
	81, 38, 39, 40, 84, 81, 20, 21,
	22, 81, 81, 81, 81, 81, 81, 81,
	81, 81, 81, 81, 32, 33, 81, 81,
	81, 81, 81, 38, 39, 40, 84, 81,
	20, 21, 22, 81, 81, 81, 81, 81,
	81, 81, 81, 81, 81, 81, 81, 33,
	81, 81, 81, 81, 81, 38, 39, 40,
	84, 81, 20, 21, 22, 81, 81, 81,
	81, 81, 81, 81, 81, 81, 81, 81,
	81, 81, 81, 81, 81, 81, 81, 38,
	39, 40, 84, 81, 19, 20, 21, 22,
	81, 81, 81, 81, 81, 81, 28, 29,
	30, 81, 31, 32, 33, 81, 81, 81,
	81, 19, 38, 39, 40, 84, 81, 19,
	20, 21, 22, 81, 81, 81, 81, 81,
	81, 81, 29, 30, 81, 31, 32, 33,
	81, 81, 81, 81, 19, 38, 39, 40,
	84, 81, 19, 20, 21, 22, 81, 81,
	81, 81, 81, 81, 81, 81, 30, 81,
	31, 32, 33, 81, 81, 81, 81, 19,
	38, 39, 40, 84, 81, 18, 19, 20,
	21, 22, 81, 24, 18, 81, 81, 81,
	28, 29, 30, 81, 31, 32, 33, 81,
	81, 81, 81, 19, 38, 39, 40, 84,
	81, 18, 19, 20, 21, 22, 81, 85,
	18, 81, 81, 81, 28, 29, 30, 81,
	31, 32, 33, 81, 81, 81, 81, 19,
	38, 39, 40, 84, 81, 18, 19, 20,
	21, 22, 81, 81, 18, 81, 81, 81,
	28, 29, 30, 81, 31, 32, 33, 81,
	81, 81, 81, 19, 38, 39, 40, 84,
	81, 18, 19, 20, 21, 22, 23, 24,
	18, 81, 81, 81, 28, 29, 30, 81,
	31, 32, 33, 81, 81, 81, 81, 19,
	38, 39, 40, 84, 81, 3, 6, 81,
	81, 82, 81, 81, 81, 81, 81, 81,
	18, 19, 20, 21, 22, 23, 24, 18,
	25, 81, 27, 28, 29, 30, 81, 31,
	32, 33, 81, 81, 81, 81, 37, 38,
	39, 40, 6, 81, 3, 81, 81, 81,
	81, 81, 81, 81, 81, 81, 81, 81,
	81, 81, 4, 81, 81, 81, 81, 81,
	81, 81, 19, 20, 21, 22, 81, 81,
	81, 81, 81, 81, 81, 81, 81, 81,
	31, 32, 33, 81, 81, 81, 81, 81,
	38, 39, 40, 84, 81, 3, 86, 86,
	86, 86, 86, 86, 86, 86, 86, 86,
	86, 86, 86, 4, 86, 87, 81, 14,
	81, 81, 81, 81, 81, 81, 81, 88,
	81, 14, 81, 6, 86, 86, 86, 86,
	86, 86, 86, 86, 86, 86, 86, 86,
	86, 86, 86, 86, 86, 86, 86, 86,
	86, 86, 86, 86, 86, 86, 86, 86,
	86, 86, 86, 6, 86, 86, 86, 6,
	86, 9, 81, 81, 81, 9, 81, 81,
	81, 81, 81, 3, 6, 14, 81, 82,
	81, 81, 81, 81, 81, 81, 18, 19,
	20, 21, 22, 23, 24, 18, 25, 26,
	27, 28, 29, 30, 81, 31, 32, 33,
	81, 34, 35, 81, 37, 38, 39, 40,
	6, 81, 3, 6, 81, 81, 82, 81,
	81, 81, 81, 81, 81, 18, 19, 20,
	21, 22, 23, 24, 18, 25, 26, 27,
	28, 29, 30, 81, 31, 32, 33, 81,
	81, 81, 81, 37, 38, 39, 40, 6,
	81, 34, 35, 81, 35, 81, 78, 80,
	80, 80, 80, 80, 80, 80, 80, 80,
	80, 80, 80, 80, 80, 80, 80, 80,
	80, 80, 78, 79, 80, 9, 86, 86,
	86, 9, 86, 0
};

static const char _use_syllable_machine_trans_targs[] = {
	5, 9, 5, 41, 2, 5, 1, 53,
	6, 7, 5, 34, 37, 63, 64, 67,
	68, 72, 43, 44, 45, 46, 47, 57,
	58, 60, 69, 61, 54, 55, 56, 50,
	51, 52, 70, 71, 73, 62, 48, 49,
	5, 5, 5, 5, 8, 0, 33, 12,
	13, 14, 15, 16, 27, 28, 30, 31,
	24, 25, 26, 19, 20, 21, 32, 17,
	18, 5, 11, 5, 10, 22, 5, 23,
	29, 5, 35, 36, 5, 38, 39, 40,
	5, 5, 3, 42, 4, 59, 5, 65,
	66
};

static const char _use_syllable_machine_trans_actions[] = {
	1, 0, 2, 3, 0, 4, 0, 5,
	0, 5, 8, 0, 5, 9, 0, 9,
	3, 0, 5, 5, 0, 0, 0, 5,
	5, 5, 3, 3, 5, 5, 5, 5,
	5, 5, 0, 0, 0, 3, 0, 0,
	10, 11, 12, 13, 5, 0, 5, 0,
	0, 0, 0, 0, 0, 0, 0, 5,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 14, 5, 15, 0, 0, 16, 0,
	0, 17, 0, 0, 18, 5, 0, 0,
	19, 20, 0, 3, 0, 5, 21, 0,
	0
};

static const char _use_syllable_machine_to_state_actions[] = {
	0, 0, 0, 0, 0, 6, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0
};

static const char _use_syllable_machine_from_state_actions[] = {
	0, 0, 0, 0, 0, 7, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0
};

static const short _use_syllable_machine_eof_trans[] = {
	1, 3, 3, 6, 6, 0, 42, 44,
	44, 68, 68, 44, 44, 44, 44, 44,
	44, 44, 44, 44, 44, 44, 71, 44,
	44, 44, 44, 44, 44, 44, 44, 44,
	68, 44, 74, 77, 74, 44, 44, 81,
	81, 82, 82, 82, 82, 82, 82, 82,
	82, 82, 82, 82, 82, 82, 82, 82,
	82, 82, 82, 82, 82, 82, 82, 87,
	82, 82, 82, 87, 82, 82, 82, 82,
	81, 87
};

static const int use_syllable_machine_start = 5;
static const int use_syllable_machine_first_final = 5;
static const int use_syllable_machine_error = -1;

static const int use_syllable_machine_en_main = 5;

#line 38 "hb-ot-shape-complex-use-machine.rl"

#line 162 "hb-ot-shape-complex-use-machine.rl"

#define found_syllable(syllable_type) \
  HB_STMT_START { \
    if (0) fprintf (stderr, "syllable %d..%d %s\n", ts, te, #syllable_type); \
    for (unsigned int i = ts; i < te; i++) \
      info[i].syllable() = (syllable_serial << 4) | use_##syllable_type; \
    syllable_serial++; \
    if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
  } HB_STMT_END

static void
find_syllables_use (hb_buffer_t *buffer)
{
  unsigned int p, pe, eof, ts, te, act;
  int cs;
  hb_glyph_info_t *info = buffer->info;

#line 396 "hb-ot-shape-complex-use-machine.hh"
	{
	cs = use_syllable_machine_start;
	ts = 0;
	te = 0;
	act = 0;
	}

#line 182 "hb-ot-shape-complex-use-machine.rl"

  p = 0;
  pe = eof = buffer->len;

  unsigned int syllable_serial = 1;

#line 412 "hb-ot-shape-complex-use-machine.hh"
	{
	int _slen;
	int _trans;
	const unsigned char *_keys;
	const char *_inds;
	if ( p == pe )
		goto _test_eof;
_resume:
	switch ( _use_syllable_machine_from_state_actions[cs] ) {
	case 7:
#line 1 "NONE"
	{ts = p;}
	break;
#line 426 "hb-ot-shape-complex-use-machine.hh"
	}

	_keys = _use_syllable_machine_trans_keys + (cs<<1);
	_inds = _use_syllable_machine_indicies + _use_syllable_machine_index_offsets[cs];

	_slen = _use_syllable_machine_key_spans[cs];
	_trans = _inds[ _slen > 0 && _keys[0] <=( info[p].use_category()) &&
		( info[p].use_category()) <= _keys[1] ?
		( info[p].use_category()) - _keys[0] : _slen ];

_eof_trans:
	cs = _use_syllable_machine_trans_targs[_trans];

	if ( _use_syllable_machine_trans_actions[_trans] == 0 )
		goto _again;

	switch ( _use_syllable_machine_trans_actions[_trans] ) {
	case 5:
#line 1 "NONE"
	{te = p+1;}
	break;
	case 12:
#line 150 "hb-ot-shape-complex-use-machine.rl"
	{te = p+1;{ found_syllable (independent_cluster); }}
	break;
	case 14:
#line 153 "hb-ot-shape-complex-use-machine.rl"
	{te = p+1;{ found_syllable (standard_cluster); }}
	break;
	case 10:
#line 157 "hb-ot-shape-complex-use-machine.rl"
	{te = p+1;{ found_syllable (broken_cluster); }}
	break;
	case 8:
#line 158 "hb-ot-shape-complex-use-machine.rl"
	{te = p+1;{ found_syllable (non_cluster); }}
	break;
	case 11:
#line 150 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (independent_cluster); }}
	break;
	case 15:
#line 151 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (virama_terminated_cluster); }}
	break;
	case 16:
#line 152 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (sakot_terminated_cluster); }}
	break;
	case 13:
#line 153 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (standard_cluster); }}
	break;
	case 18:
#line 154 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (number_joiner_terminated_cluster); }}
	break;
	case 17:
#line 155 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (numeral_cluster); }}
	break;
	case 19:
#line 156 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (symbol_cluster); }}
	break;
	case 20:
#line 157 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (broken_cluster); }}
	break;
	case 21:
#line 158 "hb-ot-shape-complex-use-machine.rl"
	{te = p;p--;{ found_syllable (non_cluster); }}
	break;
	case 1:
#line 153 "hb-ot-shape-complex-use-machine.rl"
	{{p = ((te))-1;}{ found_syllable (standard_cluster); }}
	break;
	case 4:
#line 157 "hb-ot-shape-complex-use-machine.rl"
	{{p = ((te))-1;}{ found_syllable (broken_cluster); }}
	break;
	case 2:
#line 1 "NONE"
	{	switch( act ) {
	case 8:
	{{p = ((te))-1;} found_syllable (broken_cluster); }
	break;
	case 9:
	{{p = ((te))-1;} found_syllable (non_cluster); }
	break;
	}
	}
	break;
	case 3:
#line 1 "NONE"
	{te = p+1;}
#line 157 "hb-ot-shape-complex-use-machine.rl"
	{act = 8;}
	break;
	case 9:
#line 1 "NONE"
	{te = p+1;}
#line 158 "hb-ot-shape-complex-use-machine.rl"
	{act = 9;}
	break;
#line 532 "hb-ot-shape-complex-use-machine.hh"
	}

_again:
	switch ( _use_syllable_machine_to_state_actions[cs] ) {
	case 6:
#line 1 "NONE"
	{ts = 0;}
	break;
#line 541 "hb-ot-shape-complex-use-machine.hh"
	}

	if ( ++p != pe )
		goto _resume;
	_test_eof: {}
	if ( p == eof )
	{
	if ( _use_syllable_machine_eof_trans[cs] > 0 ) {
		_trans = _use_syllable_machine_eof_trans[cs] - 1;
		goto _eof_trans;
	}
	}

	}

#line 190 "hb-ot-shape-complex-use-machine.rl"

}

#undef found_syllable

#endif /* HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH */