2017-08-18 01:55:54 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2017 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
|
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#ifndef HB_AAT_LAYOUT_COMMON_HH
|
|
|
|
#define HB_AAT_LAYOUT_COMMON_HH
|
2017-08-18 01:55:54 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-aat-layout.hh"
|
2017-08-18 01:55:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace AAT {
|
|
|
|
|
|
|
|
using namespace OT;
|
|
|
|
|
|
|
|
|
2018-01-09 15:48:51 +01:00
|
|
|
/*
|
|
|
|
* Lookup Table
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T> struct Lookup;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat0
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-01-09 17:55:17 +01:00
|
|
|
inline const T* get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
2018-01-09 17:55:17 +01:00
|
|
|
if (unlikely (glyph_id >= num_glyphs)) return nullptr;
|
|
|
|
return &arrayZ[glyph_id];
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-07-17 18:45:25 +02:00
|
|
|
return_trace (arrayZ.sanitize (c, c->get_num_glyphs ()));
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format identifier--format = 0 */
|
2018-01-09 15:48:51 +01:00
|
|
|
UnsizedArrayOf<T>
|
|
|
|
arrayZ; /* Array of lookup values, indexed by glyph index. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (2, arrayZ);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupSegmentSingle
|
|
|
|
{
|
|
|
|
inline int cmp (hb_codepoint_t g) const {
|
|
|
|
return g < first ? -1 : g <= last ? 0 : +1 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && value.sanitize (c));
|
|
|
|
}
|
|
|
|
|
|
|
|
GlyphID last; /* Last GlyphID in this segment */
|
|
|
|
GlyphID first; /* First GlyphID in this segment */
|
|
|
|
T value; /* The lookup value (only one) */
|
|
|
|
public:
|
2018-01-11 09:15:34 +01:00
|
|
|
DEFINE_SIZE_STATIC (4 + T::static_size);
|
2018-01-09 15:48:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat2
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-01-09 17:55:17 +01:00
|
|
|
inline const T* get_value (hb_codepoint_t glyph_id) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
const LookupSegmentSingle<T> *v = segments.bsearch (glyph_id);
|
2018-01-09 17:55:17 +01:00
|
|
|
return v ? &v->value : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (segments.sanitize (c));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format identifier--format = 2 */
|
2018-10-08 04:27:00 +02:00
|
|
|
VarSizedBinSearchArrayOf<LookupSegmentSingle<T> >
|
2018-01-09 15:48:51 +01:00
|
|
|
segments; /* The actual segments. These must already be sorted,
|
|
|
|
* according to the first word in each one (the last
|
|
|
|
* glyph in each segment). */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (8, segments);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupSegmentArray
|
|
|
|
{
|
2018-01-09 17:55:17 +01:00
|
|
|
inline const T* get_value (hb_codepoint_t glyph_id, const void *base) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
2018-01-09 17:55:17 +01:00
|
|
|
return first <= glyph_id && glyph_id <= last ? &(base+valuesZ)[glyph_id - first] : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int cmp (hb_codepoint_t g) const {
|
|
|
|
return g < first ? -1 : g <= last ? 0 : +1 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
first <= last &&
|
|
|
|
valuesZ.sanitize (c, base, last - first + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
GlyphID last; /* Last GlyphID in this segment */
|
|
|
|
GlyphID first; /* First GlyphID in this segment */
|
2018-09-15 19:43:33 +02:00
|
|
|
OffsetTo<UnsizedArrayOf<T>, HBUINT16, false>
|
2018-01-09 15:48:51 +01:00
|
|
|
valuesZ; /* A 16-bit offset from the start of
|
|
|
|
* the table to the data. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (6);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat4
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-01-09 17:55:17 +01:00
|
|
|
inline const T* get_value (hb_codepoint_t glyph_id) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
const LookupSegmentArray<T> *v = segments.bsearch (glyph_id);
|
2018-01-09 17:55:17 +01:00
|
|
|
return v ? v->get_value (glyph_id, this) : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (segments.sanitize (c, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-10-11 22:41:01 +02:00
|
|
|
HBUINT16 format; /* Format identifier--format = 4 */
|
2018-10-08 04:27:00 +02:00
|
|
|
VarSizedBinSearchArrayOf<LookupSegmentArray<T> >
|
2018-01-09 15:48:51 +01:00
|
|
|
segments; /* The actual segments. These must already be sorted,
|
|
|
|
* according to the first word in each one (the last
|
|
|
|
* glyph in each segment). */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (8, segments);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupSingle
|
|
|
|
{
|
|
|
|
inline int cmp (hb_codepoint_t g) const { return glyph.cmp (g); }
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && value.sanitize (c));
|
|
|
|
}
|
|
|
|
|
|
|
|
GlyphID glyph; /* Last GlyphID */
|
|
|
|
T value; /* The lookup value (only one) */
|
|
|
|
public:
|
2018-10-11 22:41:01 +02:00
|
|
|
DEFINE_SIZE_STATIC (2 + T::static_size);
|
2018-01-09 15:48:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat6
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-01-09 17:55:17 +01:00
|
|
|
inline const T* get_value (hb_codepoint_t glyph_id) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
const LookupSingle<T> *v = entries.bsearch (glyph_id);
|
2018-01-09 17:55:17 +01:00
|
|
|
return v ? &v->value : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (entries.sanitize (c));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format identifier--format = 6 */
|
2018-10-08 04:27:00 +02:00
|
|
|
VarSizedBinSearchArrayOf<LookupSingle<T> >
|
2018-01-09 15:48:51 +01:00
|
|
|
entries; /* The actual entries, sorted by glyph index. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (8, entries);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat8
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
2018-01-09 17:55:17 +01:00
|
|
|
inline const T* get_value (hb_codepoint_t glyph_id) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
2018-10-14 23:52:17 +02:00
|
|
|
return firstGlyph <= glyph_id && glyph_id - firstGlyph < glyphCount ?
|
|
|
|
&valueArrayZ[glyph_id - firstGlyph] : nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && valueArrayZ.sanitize (c, glyphCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-10-14 23:52:17 +02:00
|
|
|
HBUINT16 format; /* Format identifier--format = 8 */
|
2018-01-09 15:48:51 +01:00
|
|
|
GlyphID firstGlyph; /* First glyph index included in the trimmed array. */
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 glyphCount; /* Total number of glyphs (equivalent to the last
|
2018-01-09 15:48:51 +01:00
|
|
|
* glyph minus the value of firstGlyph plus 1). */
|
|
|
|
UnsizedArrayOf<T>
|
|
|
|
valueArrayZ; /* The lookup values (indexed by the glyph index
|
|
|
|
* minus the value of firstGlyph). */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (6, valueArrayZ);
|
|
|
|
};
|
|
|
|
|
2018-10-20 00:23:49 +02:00
|
|
|
template <typename T>
|
|
|
|
struct LookupFormat10
|
|
|
|
{
|
|
|
|
friend struct Lookup<T>;
|
|
|
|
|
|
|
|
private:
|
|
|
|
inline const typename T::type get_value_or_null (hb_codepoint_t glyph_id) const
|
|
|
|
{
|
|
|
|
if (!(firstGlyph <= glyph_id && glyph_id - firstGlyph < glyphCount))
|
|
|
|
return Null(T);
|
|
|
|
|
|
|
|
const HBUINT8 *p = &valueArrayZ[(glyph_id - firstGlyph) * valueSize];
|
|
|
|
|
|
|
|
unsigned int v = 0;
|
|
|
|
unsigned int count = valueSize;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
v = (v << 8) | *p++;
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
valueSize <= 4 &&
|
|
|
|
valueArrayZ.sanitize (c, glyphCount * valueSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
HBUINT16 format; /* Format identifier--format = 8 */
|
|
|
|
HBUINT16 valueSize; /* Byte size of each value. */
|
|
|
|
GlyphID firstGlyph; /* First glyph index included in the trimmed array. */
|
|
|
|
HBUINT16 glyphCount; /* Total number of glyphs (equivalent to the last
|
|
|
|
* glyph minus the value of firstGlyph plus 1). */
|
|
|
|
UnsizedArrayOf<HBUINT8>
|
|
|
|
valueArrayZ; /* The lookup values (indexed by the glyph index
|
|
|
|
* minus the value of firstGlyph). */
|
|
|
|
public:
|
2018-10-20 21:04:51 +02:00
|
|
|
DEFINE_SIZE_ARRAY (8, valueArrayZ);
|
2018-10-20 00:23:49 +02:00
|
|
|
};
|
|
|
|
|
2018-01-09 15:48:51 +01:00
|
|
|
template <typename T>
|
|
|
|
struct Lookup
|
|
|
|
{
|
2018-01-09 17:55:17 +01:00
|
|
|
inline const T* get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const
|
2018-01-09 15:48:51 +01:00
|
|
|
{
|
|
|
|
switch (u.format) {
|
|
|
|
case 0: return u.format0.get_value (glyph_id, num_glyphs);
|
|
|
|
case 2: return u.format2.get_value (glyph_id);
|
|
|
|
case 4: return u.format4.get_value (glyph_id);
|
|
|
|
case 6: return u.format6.get_value (glyph_id);
|
|
|
|
case 8: return u.format8.get_value (glyph_id);
|
2018-01-09 17:55:17 +01:00
|
|
|
default:return nullptr;
|
2018-01-09 15:48:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-20 00:23:49 +02:00
|
|
|
inline const typename T::type get_value_or_null (hb_codepoint_t glyph_id, unsigned int num_glyphs) const
|
2018-10-10 19:24:51 +02:00
|
|
|
{
|
2018-10-20 00:23:49 +02:00
|
|
|
switch (u.format) {
|
|
|
|
/* Format 10 cannot return a pointer. */
|
|
|
|
case 10: return u.format10.get_value_or_null (glyph_id);
|
|
|
|
default:
|
|
|
|
const T *v = get_value (glyph_id, num_glyphs);
|
|
|
|
return v ? *v : Null(T);
|
|
|
|
}
|
2018-10-10 19:24:51 +02:00
|
|
|
}
|
|
|
|
|
2018-01-09 15:48:51 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
if (!u.format.sanitize (c)) return_trace (false);
|
|
|
|
switch (u.format) {
|
|
|
|
case 0: return_trace (u.format0.sanitize (c));
|
|
|
|
case 2: return_trace (u.format2.sanitize (c));
|
|
|
|
case 4: return_trace (u.format4.sanitize (c));
|
|
|
|
case 6: return_trace (u.format6.sanitize (c));
|
|
|
|
case 8: return_trace (u.format8.sanitize (c));
|
2018-10-20 00:23:49 +02:00
|
|
|
case 10: return_trace (u.format10.sanitize (c));
|
2018-01-09 15:48:51 +01:00
|
|
|
default:return_trace (true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
union {
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format identifier */
|
2018-01-09 15:48:51 +01:00
|
|
|
LookupFormat0<T> format0;
|
|
|
|
LookupFormat2<T> format2;
|
|
|
|
LookupFormat4<T> format4;
|
|
|
|
LookupFormat6<T> format6;
|
|
|
|
LookupFormat8<T> format8;
|
2018-10-20 00:23:49 +02:00
|
|
|
LookupFormat10<T> format10;
|
2018-01-09 15:48:51 +01:00
|
|
|
} u;
|
|
|
|
public:
|
2018-10-18 06:41:25 +02:00
|
|
|
DEFINE_SIZE_UNION (2, format);
|
2018-01-09 15:48:51 +01:00
|
|
|
};
|
2018-10-18 06:41:25 +02:00
|
|
|
/* Lookup 0 has unbounded size (dependant on num_glyphs). So we need to defined
|
|
|
|
* special NULL objects for Lookup<> objects, but since it's template our macros
|
|
|
|
* don't work. So we have to hand-code them here. UGLY. */
|
|
|
|
} /* Close namespace. */
|
|
|
|
/* Ugly hand-coded null objects for template Lookup<> :(. */
|
|
|
|
extern HB_INTERNAL const unsigned char _hb_Null_AAT_Lookup[2];
|
|
|
|
template <>
|
|
|
|
/*static*/ inline const AAT::Lookup<OT::HBUINT16>& Null<AAT::Lookup<OT::HBUINT16> > (void) {
|
|
|
|
return *reinterpret_cast<const AAT::Lookup<OT::HBUINT16> *> (_hb_Null_AAT_Lookup);
|
|
|
|
}
|
|
|
|
template <>
|
|
|
|
/*static*/ inline const AAT::Lookup<OT::HBUINT32>& Null<AAT::Lookup<OT::HBUINT32> > (void) {
|
|
|
|
return *reinterpret_cast<const AAT::Lookup<OT::HBUINT32> *> (_hb_Null_AAT_Lookup);
|
|
|
|
}
|
|
|
|
template <>
|
2018-10-18 07:42:47 +02:00
|
|
|
/*static*/ inline const AAT::Lookup<OT::Offset<OT::HBUINT16, false> >& Null<AAT::Lookup<OT::Offset<OT::HBUINT16, false> > > (void) {
|
|
|
|
return *reinterpret_cast<const AAT::Lookup<OT::Offset<OT::HBUINT16, false> > *> (_hb_Null_AAT_Lookup);
|
2018-10-18 06:41:25 +02:00
|
|
|
}
|
|
|
|
namespace AAT {
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2018-10-26 02:29:32 +02:00
|
|
|
enum { DELETED_GLYPH = 0xFFFF };
|
2018-01-09 15:48:51 +01:00
|
|
|
|
2018-01-11 09:15:34 +01:00
|
|
|
/*
|
2018-11-06 21:07:19 +01:00
|
|
|
* (Extended) State Table
|
2018-01-11 09:15:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Entry
|
|
|
|
{
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-01-11 18:54:49 +01:00
|
|
|
/* Note, we don't recurse-sanitize data because we don't access it.
|
|
|
|
* That said, in our DEFINE_SIZE_STATIC we access T::static_size,
|
|
|
|
* which ensures that data has a simple sanitize(). To be determined
|
2018-10-27 06:01:11 +02:00
|
|
|
* if I need to remove that as well.
|
|
|
|
*
|
|
|
|
* XXX Because we are a template, our DEFINE_SIZE_STATIC assertion
|
|
|
|
* wouldn't be checked. */
|
2018-01-11 18:54:49 +01:00
|
|
|
return_trace (c->check_struct (this));
|
2018-01-11 09:15:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2018-01-11 18:54:49 +01:00
|
|
|
HBUINT16 newState; /* Byte offset from beginning of state table
|
|
|
|
* to the new state. Really?!?! Or just state
|
|
|
|
* number? The latter in morx for sure. */
|
2018-01-11 09:15:34 +01:00
|
|
|
HBUINT16 flags; /* Table specific. */
|
|
|
|
T data; /* Optional offsets to per-glyph tables. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4 + T::static_size);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct Entry<void>
|
|
|
|
{
|
2018-10-27 06:01:11 +02:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count /*XXX Unused?*/) const
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this));
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
HBUINT16 newState; /* Byte offset from beginning of state table to the new state. */
|
|
|
|
HBUINT16 flags; /* Table specific. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename Types, typename Extra>
|
2018-01-11 09:15:34 +01:00
|
|
|
struct StateTable
|
|
|
|
{
|
2018-10-30 16:11:34 +01:00
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
typedef typename Types::HBUSHORT HBUSHORT;
|
|
|
|
typedef typename Types::ClassType ClassType;
|
|
|
|
|
2018-09-14 11:31:33 +02:00
|
|
|
enum State
|
|
|
|
{
|
|
|
|
STATE_START_OF_TEXT = 0,
|
|
|
|
STATE_START_OF_LINE = 1,
|
|
|
|
};
|
|
|
|
enum Class
|
|
|
|
{
|
|
|
|
CLASS_END_OF_TEXT = 0,
|
|
|
|
CLASS_OUT_OF_BOUNDS = 1,
|
|
|
|
CLASS_DELETED_GLYPH = 2,
|
|
|
|
CLASS_END_OF_LINE = 3,
|
|
|
|
};
|
|
|
|
|
2018-10-31 04:51:44 +01:00
|
|
|
inline unsigned int new_state (unsigned int newState) const
|
2018-10-31 05:49:59 +01:00
|
|
|
{ return Types::extended ? newState : (newState - stateArrayTable) / nClasses; }
|
2018-10-31 04:51:44 +01:00
|
|
|
|
2018-01-11 09:15:34 +01:00
|
|
|
inline unsigned int get_class (hb_codepoint_t glyph_id, unsigned int num_glyphs) const
|
2018-01-11 22:43:57 +01:00
|
|
|
{
|
2018-10-26 02:29:32 +02:00
|
|
|
if (unlikely (glyph_id == DELETED_GLYPH)) return CLASS_DELETED_GLYPH;
|
2018-11-07 18:08:44 +01:00
|
|
|
return (this+classTable).get_class (glyph_id, num_glyphs, 1);
|
2018-01-11 22:43:57 +01:00
|
|
|
}
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-01-11 18:54:49 +01:00
|
|
|
inline const Entry<Extra> *get_entries () const
|
|
|
|
{
|
|
|
|
return (this+entryTable).arrayZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Entry<Extra> *get_entryZ (unsigned int state, unsigned int klass) const
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
2018-01-11 18:15:53 +01:00
|
|
|
if (unlikely (klass >= nClasses)) return nullptr;
|
|
|
|
|
2018-10-31 03:26:16 +01:00
|
|
|
const HBUSHORT *states = (this+stateArrayTable).arrayZ;
|
2018-01-11 09:15:34 +01:00
|
|
|
const Entry<Extra> *entries = (this+entryTable).arrayZ;
|
|
|
|
|
2018-01-11 18:15:53 +01:00
|
|
|
unsigned int entry = states[state * nClasses + klass];
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-01-11 18:15:53 +01:00
|
|
|
return &entries[entry];
|
2018-01-11 09:15:34 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 18:54:49 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c,
|
|
|
|
unsigned int *num_entries_out = nullptr) const
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-01-15 21:41:51 +01:00
|
|
|
if (unlikely (!(c->check_struct (this) &&
|
|
|
|
classTable.sanitize (c, this)))) return_trace (false);
|
2018-01-11 18:15:53 +01:00
|
|
|
|
2018-10-31 03:26:16 +01:00
|
|
|
const HBUSHORT *states = (this+stateArrayTable).arrayZ;
|
2018-01-11 18:15:53 +01:00
|
|
|
const Entry<Extra> *entries = (this+entryTable).arrayZ;
|
|
|
|
|
2018-10-11 21:56:17 +02:00
|
|
|
unsigned int num_classes = nClasses;
|
|
|
|
|
2018-01-11 18:15:53 +01:00
|
|
|
unsigned int num_states = 1;
|
|
|
|
unsigned int num_entries = 0;
|
|
|
|
|
|
|
|
unsigned int state = 0;
|
|
|
|
unsigned int entry = 0;
|
|
|
|
while (state < num_states)
|
|
|
|
{
|
2018-10-11 21:56:17 +02:00
|
|
|
if (unlikely (hb_unsigned_mul_overflows (num_classes, states[0].static_size)))
|
|
|
|
return_trace (false);
|
|
|
|
|
2018-02-08 22:11:28 +01:00
|
|
|
if (unlikely (!c->check_array (states,
|
2018-09-10 23:18:07 +02:00
|
|
|
num_states,
|
2018-10-11 21:56:17 +02:00
|
|
|
num_classes * states[0].static_size)))
|
2018-01-11 18:15:53 +01:00
|
|
|
return_trace (false);
|
2018-10-18 07:34:16 +02:00
|
|
|
if ((c->max_ops -= num_states - state) < 0)
|
|
|
|
return_trace (false);
|
2018-01-11 18:15:53 +01:00
|
|
|
{ /* Sweep new states. */
|
2018-10-31 03:26:16 +01:00
|
|
|
const HBUSHORT *stop = &states[num_states * num_classes];
|
|
|
|
for (const HBUSHORT *p = &states[state * num_classes]; p < stop; p++)
|
2018-01-11 18:15:53 +01:00
|
|
|
num_entries = MAX<unsigned int> (num_entries, *p + 1);
|
|
|
|
state = num_states;
|
|
|
|
}
|
|
|
|
|
2018-09-10 23:18:07 +02:00
|
|
|
if (unlikely (!c->check_array (entries, num_entries)))
|
2018-01-11 18:15:53 +01:00
|
|
|
return_trace (false);
|
2018-10-18 07:34:16 +02:00
|
|
|
if ((c->max_ops -= num_entries - entry) < 0)
|
|
|
|
return_trace (false);
|
2018-01-11 18:15:53 +01:00
|
|
|
{ /* Sweep new entries. */
|
|
|
|
const Entry<Extra> *stop = &entries[num_entries];
|
|
|
|
for (const Entry<Extra> *p = &entries[entry]; p < stop; p++)
|
2018-10-31 04:51:44 +01:00
|
|
|
{
|
|
|
|
unsigned int newState = new_state (p->newState);
|
|
|
|
num_states = MAX<unsigned int> (num_states, newState + 1);
|
|
|
|
}
|
2018-01-11 18:15:53 +01:00
|
|
|
entry = num_entries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 18:54:49 +01:00
|
|
|
if (num_entries_out)
|
|
|
|
*num_entries_out = num_entries;
|
|
|
|
|
2018-01-11 18:15:53 +01:00
|
|
|
return_trace (true);
|
2018-01-11 09:15:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-10-30 16:11:34 +01:00
|
|
|
HBUINT nClasses; /* Number of classes, which is the number of indices
|
2018-01-11 09:15:34 +01:00
|
|
|
* in a single line in the state array. */
|
2018-10-30 16:11:34 +01:00
|
|
|
OffsetTo<ClassType, HBUINT, false>
|
2018-01-11 09:15:34 +01:00
|
|
|
classTable; /* Offset to the class table. */
|
2018-10-30 16:11:34 +01:00
|
|
|
OffsetTo<UnsizedArrayOf<HBUSHORT>, HBUINT, false>
|
2018-01-11 09:15:34 +01:00
|
|
|
stateArrayTable;/* Offset to the state array. */
|
2018-10-30 16:11:34 +01:00
|
|
|
OffsetTo<UnsizedArrayOf<Entry<Extra> >, HBUINT, false>
|
2018-01-11 09:15:34 +01:00
|
|
|
entryTable; /* Offset to the entry array. */
|
|
|
|
|
|
|
|
public:
|
2018-10-31 05:49:59 +01:00
|
|
|
DEFINE_SIZE_STATIC (4 * sizeof (HBUINT));
|
2018-01-11 09:15:34 +01:00
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
struct ClassTable
|
|
|
|
{
|
2018-11-07 18:08:44 +01:00
|
|
|
inline unsigned int get_class (hb_codepoint_t glyph_id, unsigned int outOfRange) const
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
2018-11-06 21:23:18 +01:00
|
|
|
unsigned int i = glyph_id - firstGlyph;
|
|
|
|
return i >= classArray.len ? outOfRange : classArray.arrayZ[i];
|
2018-10-30 16:11:34 +01:00
|
|
|
}
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-11-06 21:23:18 +01:00
|
|
|
return_trace (c->check_struct (this) && classArray.sanitize (c));
|
2018-10-30 16:11:34 +01:00
|
|
|
}
|
|
|
|
protected:
|
2018-11-06 21:23:18 +01:00
|
|
|
GlyphID firstGlyph; /* First glyph index included in the trimmed array. */
|
|
|
|
ArrayOf<HBUINT8> classArray; /* The class codes (indexed by glyph index minus
|
|
|
|
* firstGlyph). */
|
2018-10-30 16:11:34 +01:00
|
|
|
public:
|
2018-11-06 21:23:18 +01:00
|
|
|
DEFINE_SIZE_ARRAY (4, classArray);
|
2018-10-30 16:11:34 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 17:51:40 +01:00
|
|
|
struct ObsoleteTypes
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
|
|
|
static const bool extended = false;
|
|
|
|
typedef HBUINT16 HBUINT;
|
|
|
|
typedef HBUINT8 HBUSHORT;
|
|
|
|
struct ClassType : ClassTable
|
|
|
|
{
|
2018-11-07 18:08:44 +01:00
|
|
|
inline unsigned int get_class (hb_codepoint_t glyph_id,
|
|
|
|
unsigned int num_glyphs HB_UNUSED,
|
|
|
|
unsigned int outOfRange) const
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
2018-11-07 18:08:44 +01:00
|
|
|
return ClassTable::get_class (glyph_id, outOfRange);
|
2018-10-30 16:11:34 +01:00
|
|
|
}
|
|
|
|
};
|
2018-10-31 23:09:09 +01:00
|
|
|
template <typename T>
|
|
|
|
static inline unsigned int offsetToIndex (unsigned int offset,
|
|
|
|
const void *base,
|
|
|
|
const T *array)
|
|
|
|
{
|
|
|
|
return (offset - ((const char *) array - (const char *) base)) / sizeof (T);
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
static inline unsigned int wordOffsetToIndex (unsigned int offset,
|
|
|
|
const void *base,
|
|
|
|
const T *array)
|
|
|
|
{
|
|
|
|
return offsetToIndex (2 * offset, base, array);
|
|
|
|
}
|
2018-10-30 16:11:34 +01:00
|
|
|
};
|
2018-11-07 17:51:40 +01:00
|
|
|
struct ExtendedTypes
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
|
|
|
static const bool extended = true;
|
|
|
|
typedef HBUINT32 HBUINT;
|
|
|
|
typedef HBUINT16 HBUSHORT;
|
|
|
|
struct ClassType : Lookup<HBUINT16>
|
|
|
|
{
|
2018-11-07 18:08:44 +01:00
|
|
|
inline unsigned int get_class (hb_codepoint_t glyph_id,
|
|
|
|
unsigned int num_glyphs,
|
|
|
|
unsigned int outOfRange) const
|
2018-10-30 16:11:34 +01:00
|
|
|
{
|
|
|
|
const HBUINT16 *v = get_value (glyph_id, num_glyphs);
|
2018-11-07 18:08:44 +01:00
|
|
|
return v ? *v : outOfRange;
|
2018-10-30 16:11:34 +01:00
|
|
|
}
|
|
|
|
};
|
2018-10-31 23:09:09 +01:00
|
|
|
template <typename T>
|
|
|
|
static inline unsigned int offsetToIndex (unsigned int offset,
|
|
|
|
const void *base,
|
|
|
|
const T *array)
|
|
|
|
{
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
static inline unsigned int wordOffsetToIndex (unsigned int offset,
|
|
|
|
const void *base,
|
|
|
|
const T *array)
|
|
|
|
{
|
|
|
|
return offset;
|
|
|
|
}
|
2018-10-30 16:11:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Types, typename EntryData>
|
2018-01-12 00:01:36 +01:00
|
|
|
struct StateTableDriver
|
|
|
|
{
|
2018-10-30 16:11:34 +01:00
|
|
|
inline StateTableDriver (const StateTable<Types, EntryData> &machine_,
|
2018-01-12 00:01:36 +01:00
|
|
|
hb_buffer_t *buffer_,
|
|
|
|
hb_face_t *face_) :
|
|
|
|
machine (machine_),
|
|
|
|
buffer (buffer_),
|
2018-02-04 20:58:02 +01:00
|
|
|
num_glyphs (face_->get_num_glyphs ()) {}
|
2018-01-12 00:01:36 +01:00
|
|
|
|
|
|
|
template <typename context_t>
|
|
|
|
inline void drive (context_t *c)
|
|
|
|
{
|
2018-01-20 03:08:56 +01:00
|
|
|
if (!c->in_place)
|
|
|
|
buffer->clear_output ();
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
unsigned int state = StateTable<Types, EntryData>::STATE_START_OF_TEXT;
|
2018-01-12 11:09:21 +01:00
|
|
|
bool last_was_dont_advance = false;
|
2018-10-26 02:33:48 +02:00
|
|
|
for (buffer->idx = 0; buffer->successful;)
|
2018-01-12 00:01:36 +01:00
|
|
|
{
|
2018-01-20 03:08:56 +01:00
|
|
|
unsigned int klass = buffer->idx < buffer->len ?
|
2018-10-05 18:14:13 +02:00
|
|
|
machine.get_class (buffer->info[buffer->idx].codepoint, num_glyphs) :
|
2018-10-30 16:11:34 +01:00
|
|
|
(unsigned) StateTable<Types, EntryData>::CLASS_END_OF_TEXT;
|
2018-01-12 00:01:36 +01:00
|
|
|
const Entry<EntryData> *entry = machine.get_entryZ (state, klass);
|
|
|
|
if (unlikely (!entry))
|
|
|
|
break;
|
|
|
|
|
2018-02-04 20:58:02 +01:00
|
|
|
/* Unsafe-to-break before this if not in state 0, as things might
|
2018-10-06 21:31:44 +02:00
|
|
|
* go differently if we start from state 0 here.
|
|
|
|
*
|
|
|
|
* Ugh. The indexing here is ugly... */
|
|
|
|
if (state && buffer->backtrack_len () && buffer->idx < buffer->len)
|
2018-02-04 20:58:02 +01:00
|
|
|
{
|
2018-02-06 17:48:04 +01:00
|
|
|
/* If there's no action and we're just epsilon-transitioning to state 0,
|
|
|
|
* safe to break. */
|
|
|
|
if (c->is_actionable (this, entry) ||
|
2018-10-30 16:11:34 +01:00
|
|
|
!(entry->newState == StateTable<Types, EntryData>::STATE_START_OF_TEXT &&
|
2018-09-19 23:32:21 +02:00
|
|
|
entry->flags == context_t::DontAdvance))
|
2018-10-06 21:31:44 +02:00
|
|
|
buffer->unsafe_to_break_from_outbuffer (buffer->backtrack_len () - 1, buffer->idx + 1);
|
2018-02-04 20:58:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unsafe-to-break if end-of-text would kick in here. */
|
|
|
|
if (buffer->idx + 2 <= buffer->len)
|
|
|
|
{
|
|
|
|
const Entry<EntryData> *end_entry = machine.get_entryZ (state, 0);
|
|
|
|
if (c->is_actionable (this, end_entry))
|
|
|
|
buffer->unsafe_to_break (buffer->idx, buffer->idx + 2);
|
|
|
|
}
|
|
|
|
|
2018-01-20 03:08:56 +01:00
|
|
|
if (unlikely (!c->transition (this, entry)))
|
2018-10-31 04:51:44 +01:00
|
|
|
break;
|
2018-01-12 11:09:21 +01:00
|
|
|
|
2018-02-19 02:12:04 +01:00
|
|
|
last_was_dont_advance = (entry->flags & context_t::DontAdvance) && buffer->max_ops-- > 0;
|
2018-01-12 00:01:36 +01:00
|
|
|
|
2018-10-31 04:51:44 +01:00
|
|
|
state = machine.new_state (entry->newState);
|
2018-01-20 03:08:56 +01:00
|
|
|
|
|
|
|
if (buffer->idx == buffer->len)
|
2018-10-31 04:51:44 +01:00
|
|
|
break;
|
2018-01-20 03:08:56 +01:00
|
|
|
|
2018-01-12 11:42:25 +01:00
|
|
|
if (!last_was_dont_advance)
|
2018-10-31 04:51:44 +01:00
|
|
|
buffer->next_glyph ();
|
2018-01-12 00:01:36 +01:00
|
|
|
}
|
|
|
|
|
2018-01-12 11:42:25 +01:00
|
|
|
if (!c->in_place)
|
|
|
|
{
|
2018-10-15 04:30:44 +02:00
|
|
|
for (; buffer->successful && buffer->idx < buffer->len;)
|
|
|
|
buffer->next_glyph ();
|
2018-11-04 08:25:07 +01:00
|
|
|
buffer->swap_buffers ();
|
2018-01-12 11:42:25 +01:00
|
|
|
}
|
2018-01-12 00:01:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2018-10-30 16:11:34 +01:00
|
|
|
const StateTable<Types, EntryData> &machine;
|
2018-01-12 00:01:36 +01:00
|
|
|
hb_buffer_t *buffer;
|
|
|
|
unsigned int num_glyphs;
|
|
|
|
};
|
|
|
|
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-10-11 06:52:07 +02:00
|
|
|
struct ankr;
|
2018-01-18 01:59:55 +01:00
|
|
|
|
|
|
|
struct hb_aat_apply_context_t :
|
|
|
|
hb_dispatch_context_t<hb_aat_apply_context_t, bool, HB_DEBUG_APPLY>
|
|
|
|
{
|
|
|
|
inline const char *get_name (void) { return "APPLY"; }
|
|
|
|
template <typename T>
|
|
|
|
inline return_t dispatch (const T &obj) { return obj.apply (this); }
|
|
|
|
static return_t default_return_value (void) { return false; }
|
|
|
|
bool stop_sublookup_iteration (return_t r) const { return r; }
|
|
|
|
|
2018-10-10 04:35:22 +02:00
|
|
|
hb_ot_shape_plan_t *plan;
|
2018-01-18 01:59:55 +01:00
|
|
|
hb_font_t *font;
|
|
|
|
hb_face_t *face;
|
|
|
|
hb_buffer_t *buffer;
|
2018-01-20 01:52:01 +01:00
|
|
|
hb_sanitize_context_t sanitizer;
|
2018-11-04 18:58:02 +01:00
|
|
|
const ankr *ankr_table;
|
2018-10-11 07:14:18 +02:00
|
|
|
const char *ankr_end;
|
2018-01-18 01:59:55 +01:00
|
|
|
|
2018-02-07 18:26:41 +01:00
|
|
|
/* Unused. For debug tracing only. */
|
|
|
|
unsigned int lookup_index;
|
|
|
|
unsigned int debug_depth;
|
|
|
|
|
2018-11-04 18:58:02 +01:00
|
|
|
HB_INTERNAL hb_aat_apply_context_t (hb_ot_shape_plan_t *plan_,
|
|
|
|
hb_font_t *font_,
|
|
|
|
hb_buffer_t *buffer_,
|
|
|
|
hb_blob_t *blob = const_cast<hb_blob_t *> (&Null(hb_blob_t)));
|
2018-01-20 01:52:01 +01:00
|
|
|
|
2018-11-04 18:58:02 +01:00
|
|
|
HB_INTERNAL ~hb_aat_apply_context_t (void);
|
2018-02-07 18:30:18 +01:00
|
|
|
|
2018-11-04 18:58:02 +01:00
|
|
|
HB_INTERNAL void set_ankr_table (const AAT::ankr *ankr_table_, const char *ankr_end_);
|
|
|
|
|
|
|
|
inline void set_lookup_index (unsigned int i) { lookup_index = i; }
|
2018-01-18 01:59:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-08-18 01:55:54 +02:00
|
|
|
} /* namespace AAT */
|
|
|
|
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#endif /* HB_AAT_LAYOUT_COMMON_HH */
|