#include "hb-ot-layout-private.h"
-#include "hb-open-types-private.hh"
+#include "hb-open-type-private.hh"
+
+
+#define NO_CONTEXT ((unsigned int) 0x110000)
+#define NOT_COVERED ((unsigned int) 0x110000)
+#define MAX_NESTING_LEVEL 8
/*
struct Record
{
inline bool sanitize (SANITIZE_ARG_DEF, const void *base) {
- return SANITIZE (tag) == 0 && SANITIZE_BASE (offset, base);
+ TRACE_SANITIZE ();
+ return SANITIZE (tag) && SANITIZE_BASE (offset, base);
}
Tag tag; /* 4-byte Tag identifier */
};
template <typename Type>
-struct RecordArrayOf : ArrayOf<Record<Type> > {};
+struct RecordArrayOf : ArrayOf<Record<Type> > {
+ inline const Tag& get_tag (unsigned int i) const
+ {
+ if (HB_UNLIKELY (i >= this->len)) return Null(Tag);
+ return (*this)[i].tag;
+ }
+ inline bool get_tags (unsigned int *record_count /* IN/OUT */,
+ hb_tag_t *record_tags /* OUT */) const
+ {
+ const Record<Type> *a = this->const_array();
+ unsigned int count = MIN (this->len, *record_count);
+ for (unsigned int i = 0; i < count; i++)
+ record_tags[i] = a[i].tag;
+
+ *record_count = this->len;
+ return !!this->len;
+ }
+ inline bool find_index (hb_tag_t tag, unsigned int *index) const
+ {
+ const Tag t = tag;
+ // TODO bsearch
+ const Record<Type> *a = this->const_array();
+ unsigned int count = this->len;
+ for (unsigned int i = 0; i < count; i++)
+ {
+ if (t == a[i].tag)
+ {
+ if (index) *index = i;
+ return true;
+ }
+ }
+ if (index) *index = NO_INDEX;
+ return false;
+ }
+};
template <typename Type>
struct RecordListOf : RecordArrayOf<Type>
{
inline const Type& operator [] (unsigned int i) const
- {
- if (HB_UNLIKELY (i >= this->len)) return Null(Type);
- return this+this->array[i].offset;
+ { return this+RecordArrayOf<Type>::operator [](i).offset; }
+
+ inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
+ return RecordArrayOf<Type>::sanitize (SANITIZE_ARG, CONST_CHARP(this));
}
- inline const Tag& get_tag (unsigned int i) const
+};
+
+
+struct IndexArray : ArrayOf<USHORT>
+{
+ inline unsigned int operator [] (unsigned int i) const
{
- if (HB_UNLIKELY (i >= this->len)) return Null(Tag);
- return this->array[i].tag;
+ if (HB_UNLIKELY (i >= this->len))
+ return NO_INDEX;
+ return this->const_array()[i];
}
+ inline bool get_indexes (unsigned int *_count /* IN/OUT */,
+ unsigned int *_indexes /* OUT */) const
+ {
+ unsigned int count = MIN (this->len, *_count);
+ const USHORT *a = this->const_array();
+ for (unsigned int i = 0; i < count; i++)
+ _indexes[i] = a[i];
- inline bool sanitize (SANITIZE_ARG_DEF) {
- return RecordArrayOf<Type>::sanitize (SANITIZE_ARG, CONST_CHARP(this));
+ *_count = this->len;
+ return !!this->len;
}
};
struct LangSys
{
- inline unsigned int get_feature_index (unsigned int i) const { return featureIndex[i]; }
- inline unsigned int get_feature_count (void) const { return featureIndex.len; }
+ inline unsigned int get_feature_count (void) const
+ { return featureIndex.len; }
+ inline hb_tag_t get_feature_index (unsigned int i) const
+ { return featureIndex[i]; }
+ inline bool get_feature_indexes (unsigned int *feature_count /* IN/OUT */,
+ unsigned int *feature_indexes /* OUT */) const
+ { return featureIndex.get_indexes (feature_count, feature_indexes); }
inline bool has_required_feature (void) const { return reqFeatureIndex != 0xffff; }
inline int get_required_feature_index (void) const
}
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE_SELF () && SANITIZE (featureIndex);
}
USHORT reqFeatureIndex;/* Index of a feature required for this
* language system--if no required features
* = 0xFFFF */
- ArrayOf<USHORT>
- featureIndex; /* Array of indices into the FeatureList */
+ IndexArray featureIndex; /* Array of indices into the FeatureList */
};
ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF");
struct Script
{
+ inline unsigned int get_lang_sys_count (void) const
+ { return langSys.len; }
+ inline const Tag& get_lang_sys_tag (unsigned int i) const
+ { return langSys.get_tag (i); }
+ inline bool get_lang_sys_tags (unsigned int *lang_sys_count /* IN/OUT */,
+ hb_tag_t *lang_sys_tags /* OUT */) const
+ { return langSys.get_tags (lang_sys_count, lang_sys_tags); }
inline const LangSys& get_lang_sys (unsigned int i) const
{
if (i == NO_INDEX) return get_default_lang_sys ();
return this+langSys[i].offset;
}
- inline unsigned int get_lang_sys_count (void) const { return langSys.len; }
- inline const Tag& get_lang_sys_tag (unsigned int i) const { return langSys[i].tag; }
-
- // LONGTERMTODO bsearch
- DEFINE_TAG_FIND_INTERFACE (LangSys, lang_sys); /* find_lang_sys_index (), get_lang_sys_by_tag (tag) */
+ inline bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const
+ { return langSys.find_index (tag, index); }
inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; }
inline const LangSys& get_default_lang_sys (void) const { return this+defaultLangSys; }
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE_THIS (defaultLangSys) && SANITIZE_THIS (langSys);
}
struct Feature
{
- inline unsigned int get_lookup_index (unsigned int i) const { return lookupIndex[i]; }
- inline unsigned int get_lookup_count (void) const { return lookupIndex.len; }
+ inline unsigned int get_lookup_count (void) const
+ { return lookupIndex.len; }
+ inline hb_tag_t get_lookup_index (unsigned int i) const
+ { return lookupIndex[i]; }
+ inline bool get_lookup_indexes (unsigned int *lookup_count /* IN/OUT */,
+ unsigned int *lookup_tags /* OUT */) const
+ { return lookupIndex.get_indexes (lookup_count, lookup_tags); }
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE_SELF () && SANITIZE (lookupIndex);
}
* has been defined for the feature), relative
* to the beginning of the Feature Table; = Null
* if not required */
- ArrayOf<USHORT>
- lookupIndex; /* Array of LookupList indices */
+ IndexArray lookupIndex; /* Array of LookupList indices */
};
ASSERT_SIZE (Feature, 4);
IgnoreBaseGlyphs = 0x0002u,
IgnoreLigatures = 0x0004u,
IgnoreMarks = 0x0008u,
+ IgnoreFlags = 0x000Eu,
UseMarkFilteringSet = 0x0010u,
Reserved = 0x00E0u,
- MarkAttachmentType = 0xFF00u,
+ MarkAttachmentType = 0xFF00u
};
};
ASSERT_SIZE (LookupFlag, 2);
struct LookupSubTable
{
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE_SELF ();
}
unsigned int flag = lookupFlag;
if (HB_UNLIKELY (flag & LookupFlag::UseMarkFilteringSet))
{
- const USHORT &markFilteringSet = CONST_CAST (USHORT, subTable, subTable.get_size ());
+ const USHORT &markFilteringSet = CONST_NEXT (USHORT, subTable);
flag += (markFilteringSet << 16);
}
return flag;
}
inline bool sanitize (SANITIZE_ARG_DEF) {
- if (!(SANITIZE_SELF () && SANITIZE_THIS (subTable))) return false;
+ TRACE_SANITIZE ();
+ if (!(SANITIZE_SELF/*XXXXXXXXXXXXXX*/ () && SANITIZE_THIS (subTable))) return false;
if (HB_UNLIKELY (lookupFlag & LookupFlag::UseMarkFilteringSet))
{
- USHORT &markFilteringSet = CAST (USHORT, subTable, subTable.get_size ());
+ USHORT &markFilteringSet = NEXT (USHORT, subTable);
if (!SANITIZE (markFilteringSet)) return false;
}
return true;
USHORT lookupFlag; /* Lookup qualifiers */
OffsetArrayOf<LookupSubTable>
subTable; /* Array of SubTables */
- USHORT markFilteringSetX[0]; /* Index (base 0) into GDEF mark glyph sets
+ USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph sets
* structure. This field is only present if bit
* UseMarkFilteringSet of lookup flags is set. */
};
-ASSERT_SIZE (Lookup, 6);
-
-template <typename Type>
-struct OffsetListOf : OffsetArrayOf<Type>
-{
- inline const Type& operator [] (unsigned int i) const
- {
- if (HB_UNLIKELY (i >= this->len)) return Null(Type);
- return this+this->array[i];
- }
-
- inline bool sanitize (SANITIZE_ARG_DEF) {
- return OffsetArrayOf<Type>::sanitize (SANITIZE_ARG, CONST_CHARP(this));
- }
-};
+ASSERT_SIZE_VAR (Lookup, 6, USHORT);
typedef OffsetListOf<Lookup> LookupList;
ASSERT_SIZE (LookupList, 2);
}
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE (glyphArray);
}
public:
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE_SELF ();
}
}
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE (rangeRecord);
}
{
inline unsigned int operator() (hb_codepoint_t glyph_id) const { return get_coverage (glyph_id); }
- unsigned int get_coverage (hb_codepoint_t glyph_id) const
+ inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
switch (u.format) {
case 1: return u.format1->get_coverage(glyph_id);
}
}
- bool sanitize (SANITIZE_ARG_DEF) {
+ inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
if (!SANITIZE (u.format)) return false;
switch (u.format) {
case 1: return u.format1->sanitize (SANITIZE_ARG);
private:
union {
USHORT format; /* Format identifier */
- CoverageFormat1 format1[];
- CoverageFormat2 format2[];
+ CoverageFormat1 format1[VAR];
+ CoverageFormat2 format2[VAR];
} u;
};
-ASSERT_SIZE (Coverage, 2);
/*
}
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE_SELF () && SANITIZE (classValue);
}
public:
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE_SELF ();
}
}
inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE (rangeRecord);
}
{
inline unsigned int operator() (hb_codepoint_t glyph_id) const { return get_class (glyph_id); }
- hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
+ inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
{
switch (u.format) {
case 1: return u.format1->get_class(glyph_id);
}
}
- bool sanitize (SANITIZE_ARG_DEF) {
+ inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
if (!SANITIZE (u.format)) return false;
switch (u.format) {
case 1: return u.format1->sanitize (SANITIZE_ARG);
private:
union {
USHORT format; /* Format identifier */
- ClassDefFormat1 format1[];
- ClassDefFormat2 format2[];
+ ClassDefFormat1 format1[VAR];
+ ClassDefFormat2 format2[VAR];
} u;
};
-ASSERT_SIZE (ClassDef, 2);
/*
{
inline int operator() (unsigned int ppem_size) const { return get_delta (ppem_size); }
- int get_delta (unsigned int ppem_size) const
+ inline int get_delta (unsigned int ppem_size) const
{
unsigned int f = deltaFormat;
if (HB_UNLIKELY (f < 1 || f > 3))
return sizeof (*this) + ((endSize - startSize + (1 << (4 - f)) - 1) >> (4 - f));
}
- bool sanitize (SANITIZE_ARG_DEF) {
+ inline bool sanitize (SANITIZE_ARG_DEF) {
+ TRACE_SANITIZE ();
return SANITIZE_GET_SIZE ();
}
USHORT startSize; /* Smallest size to correct--in ppem */
USHORT endSize; /* Largest size to correct--in ppem */
USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 */
- USHORT deltaValue[]; /* Array of compressed data */
+ USHORT deltaValue[VAR]; /* Array of compressed data */
};
-ASSERT_SIZE (Device, 6);
+ASSERT_SIZE_VAR (Device, 6, USHORT);
#endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */