USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */
USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */
USHORT rangeShift; /* NumTables x 16-searchRange. */
- TableDirectory tableDir[]; /* TableDirectory entries. numTables items */
+ TableDirectory tableDir[VAR]; /* TableDirectory entries. numTables items */
} OpenTypeFontFace;
-ASSERT_SIZE (OffsetTable, 12);
+ASSERT_SIZE_VAR (OffsetTable, 12, TableDirectory);
/*
* TrueType Collections
#define CONST_NEXT(T,X) (*(reinterpret_cast<const T *>(CONST_CHARP(&(X)) + (X).get_size ())))
#define NEXT(T,X) (*(reinterpret_cast<T *>(CHARP(&(X)) + (X).get_size ())))
+#define CONST_ARRAY_AFTER(T,X) ((reinterpret_cast<const T *>(CONST_CHARP(&(X)) + sizeof (X))))
+#define ARRAY_AFTER(T,X) ((reinterpret_cast<T *>(CHARP(&(X)) + sizeof (X))))
+
/*
* Class features
*/
/* Null objects */
/* Global nul-content Null pool. Enlarge as necessary. */
-static const char NullPool[16] = "";
+static const char NullPool[32] = "";
/* Generic template for nul-content sizeof-sized Null objects. */
template <typename Type>
template <typename LenType, typename Type>
struct GenericArrayOf
{
+ const Type *const_array(void) const { return CONST_ARRAY_AFTER (Type, len); }
+ Type *array(void) { return ARRAY_AFTER (Type, len); }
+
inline const Type& operator [] (unsigned int i) const
{
if (HB_UNLIKELY (i >= len)) return Null(Type);
- return array[i];
+ return const_array()[i];
}
inline unsigned int get_size () const
- { return sizeof (len) + len * sizeof (array[0]); }
+ { return sizeof (len) + len * sizeof (Type); }
inline bool sanitize (SANITIZE_ARG_DEF) {
TRACE_SANITIZE ();
return true;
unsigned int count = len;
for (unsigned int i = 0; i < count; i++)
- if (!SANITIZE (array[i]))
+ if (!SANITIZE (array()[i]))
return false;
return true;
}
if (!SANITIZE_GET_SIZE()) return false;
unsigned int count = len;
for (unsigned int i = 0; i < count; i++)
- if (!array[i].sanitize (SANITIZE_ARG, base))
+ if (!array()[i].sanitize (SANITIZE_ARG, base))
return false;
return true;
}
if (!SANITIZE_GET_SIZE()) return false;
unsigned int count = len;
for (unsigned int i = 0; i < count; i++)
- if (!array[i].sanitize (SANITIZE_ARG, base, base2))
+ if (!array()[i].sanitize (SANITIZE_ARG, base, base2))
return false;
return true;
}
if (!SANITIZE_GET_SIZE()) return false;
unsigned int count = len;
for (unsigned int i = 0; i < count; i++)
- if (!array[i].sanitize (SANITIZE_ARG, base, user_data))
+ if (!array()[i].sanitize (SANITIZE_ARG, base, user_data))
return false;
return true;
}
LenType len;
- Type array[];
+/*Type array[VAR];*/
};
/* An array with a USHORT number of elements. */
inline const Type& operator [] (unsigned int i) const
{
if (HB_UNLIKELY (i >= this->len)) return Null(Type);
- return this+this->array[i];
+ return this+this->const_array()[i];
}
inline bool sanitize (SANITIZE_ARG_DEF) {
template <typename Type>
struct HeadlessArrayOf
{
+ const Type *const_array(void) const { return CONST_ARRAY_AFTER (Type, len); }
+ Type *array(void) { return ARRAY_AFTER (Type, len); }
+
inline const Type& operator [] (unsigned int i) const
{
if (HB_UNLIKELY (i >= len || !i)) return Null(Type);
- return array[i-1];
+ return const_array()[i-1];
}
inline unsigned int get_size () const
- { return sizeof (len) + (len ? len - 1 : 0) * sizeof (array[0]); }
+ { return sizeof (len) + (len ? len - 1 : 0) * sizeof (Type); }
inline bool sanitize (SANITIZE_ARG_DEF) {
TRACE_SANITIZE ();
* do have a simple sanitize(). */
return true;
unsigned int count = len ? len - 1 : 0;
+ Type *a = array();
for (unsigned int i = 0; i < count; i++)
- if (!SANITIZE (array[i]))
+ if (!SANITIZE (a[i]))
return false;
return true;
}
USHORT len;
- Type array[];
+/*Type array[VAR];*/
};
inline const Tag& get_tag (unsigned int i) const
{
if (HB_UNLIKELY (i >= this->len)) return Null(Tag);
- return this->array[i].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] = this->array[i].tag;
+ record_tags[i] = a[i].tag;
*record_count = this->len;
return !!this->len;
{
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 == this->array[i].tag)
+ if (t == a[i].tag)
{
if (index) *index = i;
return true;
{
if (HB_UNLIKELY (i >= this->len))
return NO_INDEX;
- return this->array[i];
+ 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] = this->array[i];
+ _indexes[i] = a[i];
*_count = this->len;
return !!this->len;
inline bool sanitize (SANITIZE_ARG_DEF) {
TRACE_SANITIZE ();
- if (!(SANITIZE_SELF () && SANITIZE_THIS (subTable))) return false;
+ if (!(SANITIZE_SELF/*XXXXXXXXXXXXXX*/ () && SANITIZE_THIS (subTable))) return false;
if (HB_UNLIKELY (lookupFlag & LookupFlag::UseMarkFilteringSet))
{
USHORT &markFilteringSet = NEXT (USHORT, subTable);
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);
+ASSERT_SIZE_VAR (Lookup, 6, USHORT);
typedef OffsetListOf<Lookup> LookupList;
ASSERT_SIZE (LookupList, 2);
private:
union {
USHORT format; /* Format identifier */
- CoverageFormat1 format1[];
- CoverageFormat2 format2[];
+ CoverageFormat1 format1[VAR];
+ CoverageFormat2 format2[VAR];
} u;
};
-ASSERT_SIZE (Coverage, 2);
/*
private:
union {
USHORT format; /* Format identifier */
- ClassDefFormat1 format1[];
- ClassDefFormat2 format2[];
+ ClassDefFormat1 format1[VAR];
+ ClassDefFormat2 format2[VAR];
} u;
};
-ASSERT_SIZE (ClassDef, 2);
/*
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 */
private:
union {
USHORT format; /* Format identifier */
- CaretValueFormat1 format1[];
- CaretValueFormat2 format2[];
- CaretValueFormat3 format3[];
+ CaretValueFormat1 format1[VAR];
+ CaretValueFormat2 format2[VAR];
+ CaretValueFormat3 format3[VAR];
} u;
};
-ASSERT_SIZE (CaretValue, 2);
struct LigGlyph
{
private:
union {
USHORT format; /* Format identifier */
- MarkGlyphSetsFormat1 format1[];
+ MarkGlyphSetsFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (MarkGlyphSets, 2);
/*
* mark attachment type--from beginning
* of GDEF header (may be Null) */
OffsetTo<MarkGlyphSets>
- markGlyphSetsDef[0]; /* Offset to the table of mark set
+ markGlyphSetsDef[VAR]; /* Offset to the table of mark set
* definitions--from beginning of GDEF
* header (may be NULL). Introduced
* in version 00010002. */
};
-ASSERT_SIZE (GDEF, 12);
+ASSERT_SIZE_VAR (GDEF, 12, OffsetTo<MarkGlyphSets>);
#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */
typedef SHORT Value;
-typedef Value ValueRecord[0];
-ASSERT_SIZE (ValueRecord, 0);
+typedef Value ValueRecord[VAR];
+ASSERT_SIZE_VAR (Value, 0, ValueRecord);
struct ValueFormat : USHORT
{
private:
union {
USHORT format; /* Format identifier */
- AnchorFormat1 format1[];
- AnchorFormat2 format2[];
- AnchorFormat3 format3[];
+ AnchorFormat1 format1[VAR];
+ AnchorFormat2 format2[VAR];
+ AnchorFormat3 format3[VAR];
} u;
};
-ASSERT_SIZE (Anchor, 2);
struct AnchorMatrix
USHORT rows; /* Number of rows */
private:
OffsetTo<Anchor>
- matrix[]; /* Matrix of offsets to Anchor tables--
+ matrix[VAR]; /* Matrix of offsets to Anchor tables--
* from beginning of AnchorMatrix table */
};
-ASSERT_SIZE (AnchorMatrix, 2);
+ASSERT_SIZE_VAR (AnchorMatrix, 2, OffsetTo<Anchor>);
struct MarkRecord
* value(s)--applied to all glyphs in
* the Coverage table */
};
-ASSERT_SIZE (SinglePosFormat1, 6);
+ASSERT_SIZE_VAR (SinglePosFormat1, 6, ValueRecord);
struct SinglePosFormat2
{
ValueRecord values; /* Array of ValueRecords--positioning
* values applied to glyphs */
};
-ASSERT_SIZE (SinglePosFormat2, 8);
+ASSERT_SIZE_VAR (SinglePosFormat2, 8, ValueRecord);
struct SinglePos
{
private:
union {
USHORT format; /* Format identifier */
- SinglePosFormat1 format1[];
- SinglePosFormat2 format2[];
+ SinglePosFormat1 format1[VAR];
+ SinglePosFormat2 format2[VAR];
} u;
};
-ASSERT_SIZE (SinglePos, 2);
struct PairValueRecord
ValueRecord values; /* Positioning data for the first glyph
* followed by for second glyph */
};
-ASSERT_SIZE (PairValueRecord, 2);
+ASSERT_SIZE_VAR (PairValueRecord, 2, ValueRecord);
struct PairSet
{
private:
USHORT len; /* Number of PairValueRecords */
PairValueRecord
- array[]; /* Array of PairValueRecords--ordered
+ array[VAR]; /* Array of PairValueRecords--ordered
* by GlyphID of the second glyph */
};
-ASSERT_SIZE (PairSet, 2);
+ASSERT_SIZE_VAR (PairSet, 2, PairValueRecord);
struct PairPosFormat1
{
* class1-major, class2-minor,
* Each entry has value1 and value2 */
};
-ASSERT_SIZE (PairPosFormat2, 16);
+ASSERT_SIZE_VAR (PairPosFormat2, 16, ValueRecord);
struct PairPos
{
private:
union {
USHORT format; /* Format identifier */
- PairPosFormat1 format1[];
- PairPosFormat2 format2[];
+ PairPosFormat1 format1[VAR];
+ PairPosFormat2 format2[VAR];
} u;
};
-ASSERT_SIZE (PairPos, 2);
struct EntryExitRecord
private:
union {
USHORT format; /* Format identifier */
- CursivePosFormat1 format1[];
+ CursivePosFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (CursivePos, 2);
typedef AnchorMatrix BaseArray; /* base-major--
* in order of BaseCoverage Index--,
* mark-minor--
* ordered by class--zero-based. */
-ASSERT_SIZE (BaseArray, 2);
struct MarkBasePosFormat1
{
private:
union {
USHORT format; /* Format identifier */
- MarkBasePosFormat1 format1[];
+ MarkBasePosFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (MarkBasePos, 2);
typedef AnchorMatrix LigatureAttach; /* component-major--
* in order of writing direction--,
* mark-minor--
* ordered by class--zero-based. */
-ASSERT_SIZE (LigatureAttach, 2);
typedef OffsetListOf<LigatureAttach> LigatureArray;
/* Array of LigatureAttach
* tables ordered by
* LigatureCoverage Index */
-ASSERT_SIZE (LigatureArray, 2);
struct MarkLigPosFormat1
{
private:
union {
USHORT format; /* Format identifier */
- MarkLigPosFormat1 format1[];
+ MarkLigPosFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (MarkLigPos, 2);
typedef AnchorMatrix Mark2Array; /* mark2-major--
* in order of Mark2Coverage Index--,
* mark1-minor--
* ordered by class--zero-based. */
-ASSERT_SIZE (Mark2Array, 2);
struct MarkMarkPosFormat1
{
private:
union {
USHORT format; /* Format identifier */
- MarkMarkPosFormat1 format1[];
+ MarkMarkPosFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (MarkMarkPos, 2);
static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index);
return Context::apply (APPLY_ARG, position_lookup);
}
};
-ASSERT_SIZE (ContextPos, 2);
struct ChainContextPos : ChainContext
{
return ChainContext::apply (APPLY_ARG, position_lookup);
}
};
-ASSERT_SIZE (ChainContextPos, 2);
struct ExtensionPos : Extension
inline bool sanitize (SANITIZE_ARG_DEF);
};
-ASSERT_SIZE (ExtensionPos, 2);
private:
union {
USHORT format;
- SinglePos single[];
- PairPos pair[];
- CursivePos cursive[];
- MarkBasePos markBase[];
- MarkLigPos markLig[];
- MarkMarkPos markMark[];
- ContextPos context[];
- ChainContextPos chainContext[];
- ExtensionPos extension[];
+ SinglePos single[VAR];
+ PairPos pair[VAR];
+ CursivePos cursive[VAR];
+ MarkBasePos markBase[VAR];
+ MarkLigPos markLig[VAR];
+ MarkMarkPos markMark[VAR];
+ ContextPos context[VAR];
+ ChainContextPos chainContext[VAR];
+ ExtensionPos extension[VAR];
} u;
};
-ASSERT_SIZE (PosLookupSubTable, 2);
struct PosLookup : Lookup
return SANITIZE_THIS (list);
}
};
-ASSERT_SIZE (PosLookup, 6);
typedef OffsetListOf<PosLookup> PosLookupList;
ASSERT_SIZE (PosLookupList, 2);
private:
union {
USHORT format; /* Format identifier */
- SingleSubstFormat1 format1[];
- SingleSubstFormat2 format2[];
+ SingleSubstFormat1 format1[VAR];
+ SingleSubstFormat2 format2[VAR];
} u;
};
-ASSERT_SIZE (SingleSubst, 2);
struct Sequence
return false;
_hb_buffer_add_output_glyphs (buffer, 1,
- substitute.len, (const uint16_t *) substitute.array,
+ substitute.len, (const uint16_t *) substitute.const_array(),
0xFFFF, 0xFFFF);
/* This is a guess only ... */
private:
union {
USHORT format; /* Format identifier */
- MultipleSubstFormat1 format1[];
+ MultipleSubstFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (MultipleSubst, 2);
typedef ArrayOf<GlyphID> AlternateSet; /* Array of alternate GlyphIDs--in
private:
union {
USHORT format; /* Format identifier */
- AlternateSubstFormat1 format1[];
+ AlternateSubstFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (AlternateSubst, 2);
struct Ligature
private:
union {
USHORT format; /* Format identifier */
- LigatureSubstFormat1 format1[];
+ LigatureSubstFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (LigatureSubst, 2);
return Context::apply (APPLY_ARG, substitute_lookup);
}
};
-ASSERT_SIZE (ContextSubst, 2);
struct ChainContextSubst : ChainContext
{
return ChainContext::apply (APPLY_ARG, substitute_lookup);
}
};
-ASSERT_SIZE (ChainContextSubst, 2);
struct ExtensionSubst : Extension
inline bool sanitize (SANITIZE_ARG_DEF);
};
-ASSERT_SIZE (ExtensionSubst, 2);
struct ReverseChainSingleSubstFormat1
const ArrayOf<GlyphID> &substitute = CONST_NEXT (ArrayOf<GlyphID>, lookahead);
if (match_backtrack (APPLY_ARG,
- backtrack.len, (USHORT *) backtrack.array,
+ backtrack.len, (USHORT *) backtrack.const_array(),
match_coverage, DECONST_CHARP(this)) &&
match_lookahead (APPLY_ARG,
- lookahead.len, (USHORT *) lookahead.array,
+ lookahead.len, (USHORT *) lookahead.const_array(),
match_coverage, DECONST_CHARP(this),
1))
{
private:
union {
USHORT format; /* Format identifier */
- ReverseChainSingleSubstFormat1 format1[];
+ ReverseChainSingleSubstFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (ReverseChainSingleSubst, 2);
private:
union {
USHORT format;
- SingleSubst single[];
- MultipleSubst multiple[];
- AlternateSubst alternate[];
- LigatureSubst ligature[];
- ContextSubst context[];
- ChainContextSubst chainContext[];
- ExtensionSubst extension[];
- ReverseChainSingleSubst reverseChainContextSingle[];
+ SingleSubst single[VAR];
+ MultipleSubst multiple[VAR];
+ AlternateSubst alternate[VAR];
+ LigatureSubst ligature[VAR];
+ ContextSubst context[VAR];
+ ChainContextSubst chainContext[VAR];
+ ExtensionSubst extension[VAR];
+ ReverseChainSingleSubst reverseChainContextSingle[VAR];
} u;
};
-ASSERT_SIZE (SubstLookupSubTable, 2);
struct SubstLookup : Lookup
return SANITIZE_THIS (list);
}
};
-ASSERT_SIZE (SubstLookup, 6);
typedef OffsetListOf<SubstLookup> SubstLookupList;
ASSERT_SIZE (SubstLookupList, 2);
public:
inline bool sanitize (SANITIZE_ARG_DEF) {
TRACE_SANITIZE ();
- if (!SANITIZE_SELF ()) return false;
+ if (!(SANITIZE (inputCount) && SANITIZE (lookupCount))) return false;
return SANITIZE_MEM (input,
sizeof (input[0]) * inputCount +
sizeof (lookupRecordX[0]) * lookupCount);
* glyph sequence--includes the first
* glyph */
USHORT lookupCount; /* Number of LookupRecords */
- USHORT input[]; /* Array of match inputs--start with
+ USHORT input[VAR]; /* Array of match inputs--start with
* second glyph */
- LookupRecord lookupRecordX[]; /* Array of LookupRecords--in
+ LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
* design order */
};
-ASSERT_SIZE (Rule, 4);
+ASSERT_SIZE_VAR2 (Rule, 4, USHORT, LookupRecord);
struct RuleSet
{
* sequence */
USHORT lookupCount; /* Number of LookupRecords */
OffsetTo<Coverage>
- coverage[]; /* Array of offsets to Coverage
+ coverage[VAR]; /* Array of offsets to Coverage
* table in glyph sequence order */
- LookupRecord lookupRecordX[]; /* Array of LookupRecords--in
+ LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
* design order */
};
-ASSERT_SIZE (ContextFormat3, 6);
+ASSERT_SIZE_VAR2 (ContextFormat3, 6, OffsetTo<Coverage>, LookupRecord);
struct Context
{
private:
union {
USHORT format; /* Format identifier */
- ContextFormat1 format1[];
- ContextFormat2 format2[];
- ContextFormat3 format3[];
+ ContextFormat1 format1[VAR];
+ ContextFormat2 format2[VAR];
+ ContextFormat3 format3[VAR];
} u;
};
-ASSERT_SIZE (Context, 2);
/* Chaining Contextual lookups */
const ArrayOf<USHORT> &lookahead = CONST_NEXT (ArrayOf<USHORT>, input);
const ArrayOf<LookupRecord> &lookup = CONST_NEXT (ArrayOf<LookupRecord>, lookahead);
return chain_context_lookup (APPLY_ARG,
- backtrack.len, backtrack.array,
- input.len, input.array,
- lookahead.len, lookahead.array,
- lookup.len, lookup.array,
+ backtrack.len, backtrack.const_array(),
+ input.len, input.const_array(),
+ lookahead.len, lookahead.const_array(),
+ lookup.len, lookup.const_array(),
lookup_context);
return false;
}
{DECONST_CHARP(this), DECONST_CHARP(this), DECONST_CHARP(this)}
};
return chain_context_lookup (APPLY_ARG,
- backtrack.len, (USHORT *) backtrack.array,
- input.len, (USHORT *) input.array + 1,
- lookahead.len, (USHORT *) lookahead.array,
- lookup.len, lookup.array,
+ backtrack.len, (const USHORT *) backtrack.const_array(),
+ input.len, (const USHORT *) input.const_array() + 1,
+ lookahead.len, (const USHORT *) lookahead.const_array(),
+ lookup.len, lookup.const_array(),
lookup_context);
return false;
}
private:
union {
USHORT format; /* Format identifier */
- ChainContextFormat1 format1[];
- ChainContextFormat2 format2[];
- ChainContextFormat3 format3[];
+ ChainContextFormat1 format1[VAR];
+ ChainContextFormat2 format2[VAR];
+ ChainContextFormat3 format3[VAR];
} u;
};
-ASSERT_SIZE (ChainContext, 2);
struct ExtensionFormat1
private:
union {
USHORT format; /* Format identifier */
- ExtensionFormat1 format1[];
+ ExtensionFormat1 format1[VAR];
} u;
};
-ASSERT_SIZE (Extension, 2);
/*
#define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size))
+#define VAR 1 /* Size signifying variable-sized array */
+#define ASSERT_SIZE_VAR(_type, _size, _var_type) \
+ ASSERT_STATIC (sizeof (_type) == (_size) + VAR * sizeof (_var_type))
+#define ASSERT_SIZE_VAR2(_type, _size, _var_type1, _var_type2) \
+ ASSERT_STATIC (sizeof (_type) == (_size) + VAR * sizeof (_var_type1) + VAR * sizeof (_var_type2))
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define _HB_BOOLEAN_EXPR(expr) \