From 9e4d9d7b2721859172bc9c59c1aea27b01eb9c07 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 17 May 2009 00:09:20 -0400 Subject: [PATCH] [HB] Add OffsetTo template. --- src/hb-ot-layout-gdef-private.h | 26 ++++++++++++++------------ src/hb-ot-layout-gsub-private.h | 6 +++--- src/hb-ot-layout-open-private.h | 27 ++++++++++++++++++--------- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/hb-ot-layout-gdef-private.h b/src/hb-ot-layout-gdef-private.h index c15e1f3..33cda08 100644 --- a/src/hb-ot-layout-gdef-private.h +++ b/src/hb-ot-layout-gdef-private.h @@ -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 + 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; /* 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; /* 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 + markAttachClassDef; /* Offset to class definition table for * mark attachment type--from beginning * of GDEF header (may be Null) */ }; diff --git a/src/hb-ot-layout-gsub-private.h b/src/hb-ot-layout-gsub-private.h index c642476..7e497f1 100644 --- a/src/hb-ot-layout-gsub-private.h +++ b/src/hb-ot-layout-gsub-private.h @@ -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; /* Offset to glyph ClassDef table--from * beginning of Substitution table */ USHORT subClassSetCnt; /* Number of SubClassSet tables */ Offset subClassSet[]; /* Array of offsets to SubClassSet diff --git a/src/hb-ot-layout-open-private.h b/src/hb-ot-layout-open-private.h index 7f0f54d..0c648ef 100644 --- a/src/hb-ot-layout-open-private.h +++ b/src/hb-ot-layout-open-private.h @@ -242,11 +242,6 @@ struct Null { \ 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 +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 +inline const Type& operator + (const Base &base, OffsetTo 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 + defaultLangSys; /* Offset to DefaultLangSys table--from * beginning of Script table--may be Null */ USHORT langSysCount; /* Number of LangSysRecords for this script-- * excluding the DefaultLangSys */ -- 2.7.4