[HB] Add OffsetTo template.

This commit is contained in:
Behdad Esfahbod 2009-05-17 00:09:20 -04:00
parent e07f89295b
commit 9e4d9d7b27
3 changed files with 35 additions and 24 deletions

View File

@ -228,34 +228,36 @@ struct GDEF {
STATIC_DEFINE_GET_FOR_DATA (GDEF);
/* XXX check version here? */
DEFINE_GET_HAS_ACCESSOR (ClassDef, glyph_classes, glyphClassDef);
DEFINE_GET_HAS_ACCESSOR (AttachList, attach_list, attachList);
DEFINE_GET_HAS_ACCESSOR (LigCaretList, lig_caret_list, ligCaretList);
DEFINE_GET_HAS_ACCESSOR (ClassDef, mark_attachment_types, markAttachClassDef);
inline bool has_glyph_classes () const { return glyphClassDef != 0; }
inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const {
return get_glyph_classes ().get_class (glyph);
return glyphClassDef(this).get_class (glyph);
}
inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const {
return get_mark_attachment_types ().get_class (glyph);
return markAttachClassDef(this).get_class (glyph);
}
/* TODO get_attach and get_lig_caret */
inline bool has_attach_list () const { return attachList != 0; }
inline bool has_lig_caret_list () const { return ligCaretList != 0; }
private:
Fixed version; /* Version of the GDEF table--initially
* 0x00010000 */
Offset glyphClassDef; /* Offset to class definition table
OffsetTo<ClassDef>
glyphClassDef; /* Offset to class definition table
* for glyph type--from beginning of
* GDEF header (may be Null) */
Offset attachList; /* Offset to list of glyphs with
OffsetTo<AttachList>
attachList; /* Offset to list of glyphs with
* attachment points--from beginning
* of GDEF header (may be Null) */
Offset ligCaretList; /* Offset to list of positioning points
OffsetTo<LigCaretList>
ligCaretList; /* Offset to list of positioning points
* for ligature carets--from beginning
* of GDEF header (may be Null) */
Offset markAttachClassDef; /* Offset to class definition table for
OffsetTo<ClassDef>
markAttachClassDef; /* Offset to class definition table for
* mark attachment type--from beginning
* of GDEF header (may be Null) */
};

View File

@ -793,7 +793,6 @@ struct ContextSubstFormat2 {
/* SubClassSet tables, in Coverage Index order */
DEFINE_OFFSET_ARRAY_TYPE (SubClassSet, subClassSet, subClassSetCnt);
DEFINE_GET_ACCESSOR (Coverage, coverage, coverage);
DEFINE_GET_ACCESSOR (ClassDef, class_def, classDef);
DEFINE_GET_GLYPH_COVERAGE (glyph_coverage);
inline bool substitute (SUBTABLE_SUBSTITUTE_ARGS_DEF) const {
@ -807,14 +806,15 @@ struct ContextSubstFormat2 {
unsigned int index = get_glyph_coverage (glyph_id);
const SubClassSet &class_set = (*this)[index];
return class_set.substitute_class (SUBTABLE_SUBSTITUTE_ARGS, get_class_def ());
return class_set.substitute_class (SUBTABLE_SUBSTITUTE_ARGS, this+classDef);
}
private:
USHORT substFormat; /* Format identifier--format = 2 */
Offset coverage; /* Offset to Coverage table--from
* beginning of Substitution table */
Offset classDef; /* Offset to glyph ClassDef table--from
OffsetTo<ClassDef>
classDef; /* Offset to glyph ClassDef table--from
* beginning of Substitution table */
USHORT subClassSetCnt; /* Number of SubClassSet tables */
Offset subClassSet[]; /* Array of offsets to SubClassSet

View File

@ -242,11 +242,6 @@ struct Null <Type> { \
if (HB_UNLIKELY (!Name)) return Null(Type); \
return *(const Type*)((const char*)this + Name); \
}
#define DEFINE_GET_HAS_ACCESSOR(Type, name, Name) \
DEFINE_GET_ACCESSOR (Type, name, Name); \
inline bool has_##name (void) const { \
return Name != 0; \
}
@ -340,6 +335,21 @@ DEFINE_INT_TYPE_STRUCT (GlyphID, u, 16);
/* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */
DEFINE_INT_TYPE_STRUCT (Offset, u, 16);
/* Template subclass of Offset that does the dereferencing. Use: (this+memberName) */
template <typename Type>
struct OffsetTo : Offset {
inline const Type& operator() (const void *base) const {
unsigned int offset = *this;
if (HB_UNLIKELY (!offset)) return Null(Type);
return * (const Type *) ((const char *) base + offset);
}
};
template <typename Base, typename Type>
inline const Type& operator + (const Base &base, OffsetTo<Type> offset) {
return offset(base);
}
/* CheckSum */
struct CheckSum : ULONG {
@ -572,9 +582,7 @@ struct Script {
return defaultLangSys != 0;
}
inline const LangSys& get_default_lang_sys (void) const {
if (HB_UNLIKELY (!defaultLangSys))
return Null(LangSys);
return *(LangSys*)((const char*)this + defaultLangSys);
return this+defaultLangSys;
}
private:
@ -582,7 +590,8 @@ struct Script {
DEFINE_RECORD_ARRAY_TYPE (LangSys, langSysRecord, langSysCount);
private:
Offset defaultLangSys; /* Offset to DefaultLangSys table--from
OffsetTo<LangSys>
defaultLangSys; /* Offset to DefaultLangSys table--from
* beginning of Script table--may be Null */
USHORT langSysCount; /* Number of LangSysRecords for this script--
* excluding the DefaultLangSys */