提交 60d77cf0 编写于 作者: B Behdad Esfahbod

[HB] Indentation

上级 90de3dff
...@@ -42,7 +42,8 @@ ...@@ -42,7 +42,8 @@
*/ */
template <typename Type> template <typename Type>
struct Record { struct Record
{
Tag tag; /* 4-byte Tag identifier */ Tag tag; /* 4-byte Tag identifier */
OffsetTo<Type> OffsetTo<Type>
offset; /* Offset from beginning of object holding offset; /* Offset from beginning of object holding
...@@ -50,12 +51,15 @@ struct Record { ...@@ -50,12 +51,15 @@ struct Record {
}; };
template <typename Type> template <typename Type>
struct RecordListOf : ArrayOf<Record<Type> > { struct RecordListOf : ArrayOf<Record<Type> >
inline const Type& operator [] (unsigned int i) const { {
inline const Type& operator [] (unsigned int i) const
{
if (HB_UNLIKELY (i >= this->len)) return Null(Type); if (HB_UNLIKELY (i >= this->len)) return Null(Type);
return this+this->array[i].offset; return this+this->array[i].offset;
} }
inline const Tag& get_tag (unsigned int i) const { inline const Tag& get_tag (unsigned int i) const
{
if (HB_UNLIKELY (i >= this->len)) return Null(Tag); if (HB_UNLIKELY (i >= this->len)) return Null(Tag);
return this->array[i].tag; return this->array[i].tag;
} }
...@@ -73,20 +77,14 @@ typedef Record<Feature> FeatureRecord; ...@@ -73,20 +77,14 @@ typedef Record<Feature> FeatureRecord;
ASSERT_SIZE (FeatureRecord, 6); ASSERT_SIZE (FeatureRecord, 6);
struct LangSys { struct LangSys
{
inline const unsigned int get_feature_index (unsigned int i) const { return featureIndex[i]; }
inline unsigned int get_feature_count (void) const { return featureIndex.len; }
inline const unsigned int get_feature_index (unsigned int i) const { inline const bool has_required_feature (void) const { return reqFeatureIndex != 0xffff; }
return featureIndex[i]; inline int get_required_feature_index (void) const
} {
inline unsigned int get_feature_count (void) const {
return featureIndex.len;
}
inline const bool has_required_feature (void) const {
return reqFeatureIndex != 0xffff;
}
/* Returns NO_INDEX if none */
inline int get_required_feature_index (void) const {
if (reqFeatureIndex == 0xffff) if (reqFeatureIndex == 0xffff)
return NO_INDEX; return NO_INDEX;
return reqFeatureIndex;; return reqFeatureIndex;;
...@@ -103,28 +101,21 @@ struct LangSys { ...@@ -103,28 +101,21 @@ struct LangSys {
ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF"); ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF");
struct Script { struct Script
{
inline const LangSys& get_lang_sys (unsigned int i) const { inline const LangSys& get_lang_sys (unsigned int i) const
{
if (i == NO_INDEX) return get_default_lang_sys (); if (i == NO_INDEX) return get_default_lang_sys ();
return this+langSys[i].offset; return this+langSys[i].offset;
} }
inline unsigned int get_lang_sys_count (void) const { inline unsigned int get_lang_sys_count (void) const { return langSys.len; }
return langSys.len; inline const Tag& get_lang_sys_tag (unsigned int i) const { return langSys[i].tag; }
}
inline const Tag& get_lang_sys_tag (unsigned int i) const {
return langSys[i].tag;
}
// LONGTERMTODO bsearch // LONGTERMTODO bsearch
DEFINE_TAG_FIND_INTERFACE (LangSys, lang_sys); /* find_lang_sys_index (), get_lang_sys_by_tag (tag) */ DEFINE_TAG_FIND_INTERFACE (LangSys, lang_sys); /* find_lang_sys_index (), get_lang_sys_by_tag (tag) */
inline const bool has_default_lang_sys (void) const { inline const bool has_default_lang_sys (void) const { return defaultLangSys != 0; }
return defaultLangSys != 0; inline const LangSys& get_default_lang_sys (void) const { return this+defaultLangSys; }
}
inline const LangSys& get_default_lang_sys (void) const {
return this+defaultLangSys;
}
private: private:
OffsetTo<LangSys> OffsetTo<LangSys>
...@@ -140,14 +131,10 @@ typedef RecordListOf<Script> ScriptList; ...@@ -140,14 +131,10 @@ typedef RecordListOf<Script> ScriptList;
ASSERT_SIZE (ScriptList, 2); ASSERT_SIZE (ScriptList, 2);
struct Feature { struct Feature
{
inline const unsigned int get_lookup_index (unsigned int i) const { inline const unsigned int get_lookup_index (unsigned int i) const { return lookupIndex[i]; }
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;
}
/* TODO: implement get_feature_parameters() */ /* TODO: implement get_feature_parameters() */
/* TODO: implement FeatureSize and other special features? */ /* TODO: implement FeatureSize and other special features? */
...@@ -164,7 +151,8 @@ typedef RecordListOf<Feature> FeatureList; ...@@ -164,7 +151,8 @@ typedef RecordListOf<Feature> FeatureList;
ASSERT_SIZE (FeatureList, 2); ASSERT_SIZE (FeatureList, 2);
struct LookupFlag : USHORT { struct LookupFlag : USHORT
{
enum { enum {
RightToLeft = 0x0001u, RightToLeft = 0x0001u,
IgnoreBaseGlyphs = 0x0002u, IgnoreBaseGlyphs = 0x0002u,
...@@ -176,20 +164,17 @@ struct LookupFlag : USHORT { ...@@ -176,20 +164,17 @@ struct LookupFlag : USHORT {
}; };
ASSERT_SIZE (LookupFlag, 2); ASSERT_SIZE (LookupFlag, 2);
struct LookupSubTable { struct LookupSubTable
{
private: private:
USHORT format; /* Subtable format. Different for GSUB and GPOS */ USHORT format; /* Subtable format. Different for GSUB and GPOS */
}; };
ASSERT_SIZE (LookupSubTable, 2); ASSERT_SIZE (LookupSubTable, 2);
struct Lookup { struct Lookup
{
inline const LookupSubTable& get_subtable (unsigned int i) const { inline const LookupSubTable& get_subtable (unsigned int i) const { return this+subTable[i]; }
return this+subTable[i]; inline unsigned int get_subtable_count (void) const { return subTable.len; }
}
inline unsigned int get_subtable_count (void) const {
return subTable.len;
}
inline unsigned int get_type (void) const { return lookupType; } inline unsigned int get_type (void) const { return lookupType; }
inline unsigned int get_flag (void) const { return lookupFlag; } inline unsigned int get_flag (void) const { return lookupFlag; }
...@@ -202,8 +187,10 @@ struct Lookup { ...@@ -202,8 +187,10 @@ struct Lookup {
ASSERT_SIZE (Lookup, 6); ASSERT_SIZE (Lookup, 6);
template <typename Type> template <typename Type>
struct OffsetListOf : OffsetArrayOf<Type> { struct OffsetListOf : OffsetArrayOf<Type>
inline const Type& operator [] (unsigned int i) const { {
inline const Type& operator [] (unsigned int i) const
{
if (HB_UNLIKELY (i >= this->len)) return Null(Type); if (HB_UNLIKELY (i >= this->len)) return Null(Type);
return this+this->array[i]; return this+this->array[i];
} }
...@@ -217,12 +204,13 @@ ASSERT_SIZE (LookupList, 2); ...@@ -217,12 +204,13 @@ ASSERT_SIZE (LookupList, 2);
* Coverage Table * Coverage Table
*/ */
struct CoverageFormat1 { struct CoverageFormat1
{
friend struct Coverage; friend struct Coverage;
private: private:
inline unsigned int get_coverage (hb_codepoint_t glyph_id) const { inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
if (HB_UNLIKELY (glyph_id > 0xFFFF)) if (HB_UNLIKELY (glyph_id > 0xFFFF))
return NOT_COVERED; return NOT_COVERED;
GlyphID gid; GlyphID gid;
...@@ -241,12 +229,13 @@ struct CoverageFormat1 { ...@@ -241,12 +229,13 @@ struct CoverageFormat1 {
}; };
ASSERT_SIZE (CoverageFormat1, 4); ASSERT_SIZE (CoverageFormat1, 4);
struct CoverageRangeRecord { struct CoverageRangeRecord
{
friend struct CoverageFormat2; friend struct CoverageFormat2;
private: private:
inline unsigned int get_coverage (hb_codepoint_t glyph_id) const { inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
if (glyph_id >= start && glyph_id <= end) if (glyph_id >= start && glyph_id <= end)
return (unsigned int) startCoverageIndex + (glyph_id - start); return (unsigned int) startCoverageIndex + (glyph_id - start);
return NOT_COVERED; return NOT_COVERED;
...@@ -260,15 +249,17 @@ struct CoverageRangeRecord { ...@@ -260,15 +249,17 @@ struct CoverageRangeRecord {
}; };
ASSERT_SIZE_DATA (CoverageRangeRecord, 6, "\000\001"); ASSERT_SIZE_DATA (CoverageRangeRecord, 6, "\000\001");
struct CoverageFormat2 { struct CoverageFormat2
{
friend struct Coverage; friend struct Coverage;
private: private:
inline unsigned int get_coverage (hb_codepoint_t glyph_id) const { inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
// TODO: bsearch // TODO: bsearch
unsigned int count = rangeRecord.len; unsigned int count = rangeRecord.len;
for (unsigned int i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++)
{
unsigned int coverage = rangeRecord[i].get_coverage (glyph_id); unsigned int coverage = rangeRecord[i].get_coverage (glyph_id);
if (coverage != NOT_COVERED) if (coverage != NOT_COVERED)
return coverage; return coverage;
...@@ -284,8 +275,10 @@ struct CoverageFormat2 { ...@@ -284,8 +275,10 @@ struct CoverageFormat2 {
}; };
ASSERT_SIZE (CoverageFormat2, 4); ASSERT_SIZE (CoverageFormat2, 4);
struct Coverage { struct Coverage
unsigned int get_coverage (hb_codepoint_t glyph_id) const { {
unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
switch (u.format) { switch (u.format) {
case 1: return u.format1->get_coverage(glyph_id); case 1: return u.format1->get_coverage(glyph_id);
case 2: return u.format2->get_coverage(glyph_id); case 2: return u.format2->get_coverage(glyph_id);
...@@ -293,9 +286,7 @@ struct Coverage { ...@@ -293,9 +286,7 @@ struct Coverage {
} }
} }
inline unsigned int operator() (hb_codepoint_t glyph_id) const { inline unsigned int operator() (hb_codepoint_t glyph_id) const { return get_coverage (glyph_id); }
return get_coverage (glyph_id);
}
private: private:
union { union {
...@@ -311,12 +302,13 @@ ASSERT_SIZE (Coverage, 2); ...@@ -311,12 +302,13 @@ ASSERT_SIZE (Coverage, 2);
* Class Definition Table * Class Definition Table
*/ */
struct ClassDefFormat1 { struct ClassDefFormat1
{
friend struct ClassDef; friend struct ClassDef;
private: private:
inline 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
{
if ((unsigned int) (glyph_id - startGlyph) < classValue.len) if ((unsigned int) (glyph_id - startGlyph) < classValue.len)
return classValue[glyph_id - startGlyph]; return classValue[glyph_id - startGlyph];
return 0; return 0;
...@@ -329,12 +321,13 @@ struct ClassDefFormat1 { ...@@ -329,12 +321,13 @@ struct ClassDefFormat1 {
}; };
ASSERT_SIZE (ClassDefFormat1, 6); ASSERT_SIZE (ClassDefFormat1, 6);
struct ClassRangeRecord { struct ClassRangeRecord
{
friend struct ClassDefFormat2; friend struct ClassDefFormat2;
private: private:
inline 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
{
if (glyph_id >= start && glyph_id <= end) if (glyph_id >= start && glyph_id <= end)
return classValue; return classValue;
return 0; return 0;
...@@ -347,15 +340,17 @@ struct ClassRangeRecord { ...@@ -347,15 +340,17 @@ struct ClassRangeRecord {
}; };
ASSERT_SIZE_DATA (ClassRangeRecord, 6, "\000\001"); ASSERT_SIZE_DATA (ClassRangeRecord, 6, "\000\001");
struct ClassDefFormat2 { struct ClassDefFormat2
{
friend struct ClassDef; friend struct ClassDef;
private: private:
inline 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
{
// TODO: bsearch // TODO: bsearch
unsigned int count = rangeRecord.len; unsigned int count = rangeRecord.len;
for (unsigned int i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++)
{
int classValue = rangeRecord[i].get_class (glyph_id); int classValue = rangeRecord[i].get_class (glyph_id);
if (classValue > 0) if (classValue > 0)
return classValue; return classValue;
...@@ -370,8 +365,10 @@ struct ClassDefFormat2 { ...@@ -370,8 +365,10 @@ struct ClassDefFormat2 {
}; };
ASSERT_SIZE (ClassDefFormat2, 4); ASSERT_SIZE (ClassDefFormat2, 4);
struct ClassDef { struct ClassDef
hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const { {
hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
{
switch (u.format) { switch (u.format) {
case 1: return u.format1->get_class(glyph_id); case 1: return u.format1->get_class(glyph_id);
case 2: return u.format2->get_class(glyph_id); case 2: return u.format2->get_class(glyph_id);
...@@ -379,9 +376,7 @@ struct ClassDef { ...@@ -379,9 +376,7 @@ struct ClassDef {
} }
} }
inline unsigned int operator() (hb_codepoint_t glyph_id) const { inline unsigned int operator() (hb_codepoint_t glyph_id) const { return get_class (glyph_id); }
return get_class (glyph_id);
}
private: private:
union { union {
...@@ -397,9 +392,10 @@ ASSERT_SIZE (ClassDef, 2); ...@@ -397,9 +392,10 @@ ASSERT_SIZE (ClassDef, 2);
* Device Tables * Device Tables
*/ */
struct Device { struct Device
int get_delta (unsigned int ppem_size) const { {
int get_delta (unsigned int ppem_size) const
{
unsigned int f = deltaFormat; unsigned int f = deltaFormat;
if (HB_UNLIKELY (f < 1 || f > 3)) if (HB_UNLIKELY (f < 1 || f > 3))
return 0; return 0;
...@@ -421,9 +417,7 @@ struct Device { ...@@ -421,9 +417,7 @@ struct Device {
return delta; return delta;
} }
inline int operator() (unsigned int ppem_size) const { inline int operator() (unsigned int ppem_size) const { return get_delta (ppem_size); }
return get_delta (ppem_size);
}
private: private:
USHORT startSize; /* Smallest size to correct--in ppem */ USHORT startSize; /* Smallest size to correct--in ppem */
......
...@@ -31,12 +31,11 @@ ...@@ -31,12 +31,11 @@
#define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, array, name) \ #define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, array, name) \
inline const Type& name (hb_codepoint_t glyph) { \ inline const Type& name (hb_codepoint_t glyph) { return this+array[(this+coverage)(glyph)]; }
return this+array[(this+coverage)(glyph)]; \
}
struct GlyphClassDef : ClassDef { struct GlyphClassDef : ClassDef
{
enum { enum {
BaseGlyph = 0x0001u, BaseGlyph = 0x0001u,
LigatureGlyph = 0x0002u, LigatureGlyph = 0x0002u,
...@@ -49,15 +48,16 @@ struct GlyphClassDef : ClassDef { ...@@ -49,15 +48,16 @@ struct GlyphClassDef : ClassDef {
* Attachment List Table * Attachment List Table
*/ */
struct AttachPoint { struct AttachPoint
{
ArrayOf<USHORT> ArrayOf<USHORT>
pointIndex; /* Array of contour point indices--in pointIndex; /* Array of contour point indices--in
* increasing numerical order */ * increasing numerical order */
}; };
ASSERT_SIZE (AttachPoint, 2); ASSERT_SIZE (AttachPoint, 2);
struct AttachList { struct AttachList
{
/* const AttachPoint& get_attach_points (hb_codepoint_t glyph); */ /* const AttachPoint& get_attach_points (hb_codepoint_t glyph); */
DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, attachPoint, get_attach_points); DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, attachPoint, get_attach_points);
...@@ -75,12 +75,14 @@ ASSERT_SIZE (AttachList, 4); ...@@ -75,12 +75,14 @@ ASSERT_SIZE (AttachList, 4);
* Ligature Caret Table * Ligature Caret Table
*/ */
struct CaretValueFormat1 { struct CaretValueFormat1
{
friend struct CaretValue; friend struct CaretValue;
private: private:
inline int get_caret_value (int ppem) const { inline int get_caret_value (int ppem) const
{
/* XXX unsigned int */
return /* TODO garbage */ coordinate / ppem; return /* TODO garbage */ coordinate / ppem;
} }
...@@ -90,12 +92,13 @@ struct CaretValueFormat1 { ...@@ -90,12 +92,13 @@ struct CaretValueFormat1 {
}; };
ASSERT_SIZE (CaretValueFormat1, 4); ASSERT_SIZE (CaretValueFormat1, 4);
struct CaretValueFormat2 { struct CaretValueFormat2
{
friend struct CaretValue; friend struct CaretValue;
private: private:
inline int get_caret_value (int ppem) const { inline int get_caret_value (int ppem) const
{
return /* TODO garbage */ 0 / ppem; return /* TODO garbage */ 0 / ppem;
} }
...@@ -105,17 +108,19 @@ struct CaretValueFormat2 { ...@@ -105,17 +108,19 @@ struct CaretValueFormat2 {
}; };
ASSERT_SIZE (CaretValueFormat2, 4); ASSERT_SIZE (CaretValueFormat2, 4);
struct CaretValueFormat3 { struct CaretValueFormat3
{
friend struct CaretValue; friend struct CaretValue;
private: private:
inline const Device& get_device (void) const { inline const Device& get_device (void) const
{
if (HB_UNLIKELY (!deviceTable)) return Null(Device); if (HB_UNLIKELY (!deviceTable)) return Null(Device);
return (const Device&)*((const char*)this + deviceTable); return (const Device&)*((const char*)this + deviceTable);
} }
inline int get_caret_value (int ppem) const { inline int get_caret_value (int ppem) const
{
return /* TODO garbage */ (coordinate + get_device().get_delta (ppem)) / ppem; return /* TODO garbage */ (coordinate + get_device().get_delta (ppem)) / ppem;
} }
...@@ -128,9 +133,11 @@ struct CaretValueFormat3 { ...@@ -128,9 +133,11 @@ struct CaretValueFormat3 {
}; };
ASSERT_SIZE (CaretValueFormat3, 6); ASSERT_SIZE (CaretValueFormat3, 6);
struct CaretValue { struct CaretValue
{
/* XXX we need access to a load-contour-point vfunc here */ /* XXX we need access to a load-contour-point vfunc here */
int get_caret_value (int ppem) const { int get_caret_value (int ppem) const
{
switch (u.format) { switch (u.format) {
case 1: return u.format1->get_caret_value(ppem); case 1: return u.format1->get_caret_value(ppem);
case 2: return u.format2->get_caret_value(ppem); case 2: return u.format2->get_caret_value(ppem);
...@@ -149,18 +156,19 @@ struct CaretValue { ...@@ -149,18 +156,19 @@ struct CaretValue {
}; };
ASSERT_SIZE (CaretValue, 2); ASSERT_SIZE (CaretValue, 2);
struct LigGlyph { struct LigGlyph
{
friend struct LigCaretList; friend struct LigCaretList;
private:
OffsetArrayOf<CaretValue> OffsetArrayOf<CaretValue>
caret; /* Array of CaretValue tables caret; /* Array of CaretValue tables
* in increasing coordinate order */ * in increasing coordinate order */
}; };
ASSERT_SIZE (LigGlyph, 2); ASSERT_SIZE (LigGlyph, 2);
struct LigCaretList { struct LigCaretList
{
friend struct GDEF; friend struct GDEF;
private: private:
...@@ -181,7 +189,8 @@ ASSERT_SIZE (LigCaretList, 4); ...@@ -181,7 +189,8 @@ ASSERT_SIZE (LigCaretList, 4);
* GDEF * GDEF
*/ */
struct GDEF { struct GDEF
{
static const hb_tag_t Tag = HB_TAG ('G','D','E','F'); static const hb_tag_t Tag = HB_TAG ('G','D','E','F');
enum { enum {
...@@ -196,14 +205,10 @@ struct GDEF { ...@@ -196,14 +205,10 @@ struct GDEF {
/* XXX check version here? */ /* XXX check version here? */
inline bool has_glyph_classes () const { return glyphClassDef != 0; } inline bool has_glyph_classes () const { return glyphClassDef != 0; }
inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const { inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const { return glyphClassDef(this).get_class (glyph); }
return glyphClassDef(this).get_class (glyph);
}
inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; } 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 { inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const { return markAttachClassDef(this).get_class (glyph); }
return markAttachClassDef(this).get_class (glyph);
}
/* TODO get_attach and get_lig_caret */ /* TODO get_attach and get_lig_caret */
inline bool has_attach_list () const { return attachList != 0; } inline bool has_attach_list () const { return attachList != 0; }
......
...@@ -50,22 +50,26 @@ ...@@ -50,22 +50,26 @@
typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data); typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data);
typedef bool (*apply_lookup_func_t) (APPLY_ARG_DEF, unsigned int lookup_index); typedef bool (*apply_lookup_func_t) (APPLY_ARG_DEF, unsigned int lookup_index);
struct ContextFuncs { struct ContextFuncs
{
match_func_t match; match_func_t match;
apply_lookup_func_t apply; apply_lookup_func_t apply;
}; };
static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data) { static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data)
{
return glyph_id == value; return glyph_id == value;
} }
static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, char *data) { static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, char *data)
{
const ClassDef &class_def = (const ClassDef &)*data; const ClassDef &class_def = (const ClassDef &)*data;
return class_def.get_class (glyph_id) == value; return class_def.get_class (glyph_id) == value;
} }
static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, char *data) { static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, char *data)
{
const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
return (data+coverage) (glyph_id) != NOT_COVERED; return (data+coverage) (glyph_id) != NOT_COVERED;
} }
...@@ -83,8 +87,10 @@ static inline bool match_input (APPLY_ARG_DEF, ...@@ -83,8 +87,10 @@ static inline bool match_input (APPLY_ARG_DEF,
if (HB_UNLIKELY (buffer->in_pos + count > end)) if (HB_UNLIKELY (buffer->in_pos + count > end))
return false; return false;
for (i = 1, j = buffer->in_pos + 1; i < count; i++, j++) { for (i = 1, j = buffer->in_pos + 1; i < count; i++, j++)
while (!_hb_ot_layout_check_glyph_property (layout, IN_ITEM (j), lookup_flag, &property)) { {
while (!_hb_ot_layout_check_glyph_property (layout, IN_ITEM (j), lookup_flag, &property))
{
if (HB_UNLIKELY (j + count - i == end)) if (HB_UNLIKELY (j + count - i == end))
return false; return false;
j++; j++;
...@@ -108,8 +114,10 @@ static inline bool match_backtrack (APPLY_ARG_DEF, ...@@ -108,8 +114,10 @@ static inline bool match_backtrack (APPLY_ARG_DEF,
if (HB_UNLIKELY (buffer->out_pos < count)) if (HB_UNLIKELY (buffer->out_pos < count))
return false; return false;
for (unsigned int i = 0, j = buffer->out_pos - 1; i < count; i++, j--) { for (unsigned int i = 0, j = buffer->out_pos - 1; i < count; i++, j--)
while (!_hb_ot_layout_check_glyph_property (layout, OUT_ITEM (j), lookup_flag, &property)) { {
while (!_hb_ot_layout_check_glyph_property (layout, OUT_ITEM (j), lookup_flag, &property))
{
if (HB_UNLIKELY (j + 1 == count - i)) if (HB_UNLIKELY (j + 1 == count - i))
return false; return false;
j--; j--;
...@@ -134,8 +142,10 @@ static inline bool match_lookahead (APPLY_ARG_DEF, ...@@ -134,8 +142,10 @@ static inline bool match_lookahead (APPLY_ARG_DEF,
if (HB_UNLIKELY (buffer->in_pos + offset + count > end)) if (HB_UNLIKELY (buffer->in_pos + offset + count > end))
return false; return false;
for (i = 0, j = buffer->in_pos + offset; i < count; i++, j++) { for (i = 0, j = buffer->in_pos + offset; i < count; i++, j++)
while (!_hb_ot_layout_check_glyph_property (layout, OUT_ITEM (j), lookup_flag, &property)) { {
while (!_hb_ot_layout_check_glyph_property (layout, OUT_ITEM (j), lookup_flag, &property))
{
if (HB_UNLIKELY (j + count - i == end)) if (HB_UNLIKELY (j + count - i == end))
return false; return false;
j++; j++;
...@@ -149,8 +159,8 @@ static inline bool match_lookahead (APPLY_ARG_DEF, ...@@ -149,8 +159,8 @@ static inline bool match_lookahead (APPLY_ARG_DEF,
} }
struct LookupRecord { struct LookupRecord
{
USHORT sequenceIndex; /* Index into current glyph USHORT sequenceIndex; /* Index into current glyph
* sequence--first glyph = 0 */ * sequence--first glyph = 0 */
USHORT lookupListIndex; /* Lookup to apply to that USHORT lookupListIndex; /* Lookup to apply to that
...@@ -170,8 +180,10 @@ static inline bool apply_lookup (APPLY_ARG_DEF, ...@@ -170,8 +180,10 @@ static inline bool apply_lookup (APPLY_ARG_DEF,
/* TODO We don't support lookupRecord arrays that are not increasing: /* TODO We don't support lookupRecord arrays that are not increasing:
* Should be easy for in_place ones at least. */ * Should be easy for in_place ones at least. */
for (unsigned int i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++)
while (!_hb_ot_layout_check_glyph_property (layout, IN_CURITEM (), lookup_flag, &property)) { {
while (!_hb_ot_layout_check_glyph_property (layout, IN_CURITEM (), lookup_flag, &property))
{
if (HB_UNLIKELY (buffer->in_pos == end)) if (HB_UNLIKELY (buffer->in_pos == end))
return true; return true;
/* No lookup applied for this index */ /* No lookup applied for this index */
...@@ -209,7 +221,8 @@ static inline bool apply_lookup (APPLY_ARG_DEF, ...@@ -209,7 +221,8 @@ static inline bool apply_lookup (APPLY_ARG_DEF,
/* Contextual lookups */ /* Contextual lookups */
struct ContextLookupContext { struct ContextLookupContext
{
ContextFuncs funcs; ContextFuncs funcs;
char *match_data; char *match_data;
}; };
...@@ -231,12 +244,13 @@ static inline bool context_lookup (APPLY_ARG_DEF, ...@@ -231,12 +244,13 @@ static inline bool context_lookup (APPLY_ARG_DEF,
context.funcs.apply); context.funcs.apply);
} }
struct Rule { struct Rule
{
friend struct RuleSet; friend struct RuleSet;
private: private:
inline bool apply (APPLY_ARG_DEF, ContextLookupContext &context) const { inline bool apply (APPLY_ARG_DEF, ContextLookupContext &context) const
{
const LookupRecord *lookupRecord = (const LookupRecord *) const LookupRecord *lookupRecord = (const LookupRecord *)
((const char *) input + ((const char *) input +
sizeof (input[0]) * (inputCount ? inputCount - 1 : 0)); sizeof (input[0]) * (inputCount ? inputCount - 1 : 0));
...@@ -258,12 +272,13 @@ struct Rule { ...@@ -258,12 +272,13 @@ struct Rule {
}; };
ASSERT_SIZE (Rule, 4); ASSERT_SIZE (Rule, 4);
struct RuleSet { struct RuleSet
{
inline bool apply (APPLY_ARG_DEF, ContextLookupContext &context) const { inline bool apply (APPLY_ARG_DEF, ContextLookupContext &context) const
{
unsigned int num_rules = rule.len; unsigned int num_rules = rule.len;
for (unsigned int i = 0; i < num_rules; i++) { for (unsigned int i = 0; i < num_rules; i++)
{
if ((this+rule[i]).apply (APPLY_ARG, context)) if ((this+rule[i]).apply (APPLY_ARG, context))
return true; return true;
} }
...@@ -278,13 +293,13 @@ struct RuleSet { ...@@ -278,13 +293,13 @@ struct RuleSet {
}; };
struct ContextFormat1 { struct ContextFormat1
{
friend struct Context; friend struct Context;
private: private:
inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
{
unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
if (HB_LIKELY (index == NOT_COVERED)) if (HB_LIKELY (index == NOT_COVERED))
return false; return false;
...@@ -309,13 +324,13 @@ struct ContextFormat1 { ...@@ -309,13 +324,13 @@ struct ContextFormat1 {
ASSERT_SIZE (ContextFormat1, 6); ASSERT_SIZE (ContextFormat1, 6);
struct ContextFormat2 { struct ContextFormat2
{
friend struct Context; friend struct Context;
private: private:
inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
{
unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
if (HB_LIKELY (index == NOT_COVERED)) if (HB_LIKELY (index == NOT_COVERED))
return false; return false;
...@@ -348,13 +363,13 @@ struct ContextFormat2 { ...@@ -348,13 +363,13 @@ struct ContextFormat2 {
ASSERT_SIZE (ContextFormat2, 8); ASSERT_SIZE (ContextFormat2, 8);
struct ContextFormat3 { struct ContextFormat3
{
friend struct Context; friend struct Context;
private: private:
inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
{
unsigned int index = (this+coverage[0]) (IN_CURGLYPH ()); unsigned int index = (this+coverage[0]) (IN_CURGLYPH ());
if (HB_LIKELY (index == NOT_COVERED)) if (HB_LIKELY (index == NOT_COVERED))
return false; return false;
...@@ -385,10 +400,11 @@ struct ContextFormat3 { ...@@ -385,10 +400,11 @@ struct ContextFormat3 {
}; };
ASSERT_SIZE (ContextFormat3, 6); ASSERT_SIZE (ContextFormat3, 6);
struct Context { struct Context
{
protected: protected:
bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
{
switch (u.format) { switch (u.format) {
case 1: return u.format1->apply (APPLY_ARG, apply_func); case 1: return u.format1->apply (APPLY_ARG, apply_func);
case 2: return u.format2->apply (APPLY_ARG, apply_func); case 2: return u.format2->apply (APPLY_ARG, apply_func);
...@@ -410,7 +426,8 @@ ASSERT_SIZE (Context, 2); ...@@ -410,7 +426,8 @@ ASSERT_SIZE (Context, 2);
/* Chaining Contextual lookups */ /* Chaining Contextual lookups */
struct ChainContextLookupContext { struct ChainContextLookupContext
{
ContextFuncs funcs; ContextFuncs funcs;
char *match_data[3]; char *match_data[3];
}; };
...@@ -451,12 +468,13 @@ static inline bool chain_context_lookup (APPLY_ARG_DEF, ...@@ -451,12 +468,13 @@ static inline bool chain_context_lookup (APPLY_ARG_DEF,
context.funcs.apply); context.funcs.apply);
} }
struct ChainRule { struct ChainRule
{
friend struct ChainRuleSet; friend struct ChainRuleSet;
private: private:
inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &context) const { inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &context) const
{
const HeadlessArrayOf<USHORT> &input = (const HeadlessArrayOf<USHORT>&) const HeadlessArrayOf<USHORT> &input = (const HeadlessArrayOf<USHORT>&)
*((const char *) &backtrack + backtrack.get_size ()); *((const char *) &backtrack + backtrack.get_size ());
const ArrayOf<USHORT> &lookahead = (const ArrayOf<USHORT>&) const ArrayOf<USHORT> &lookahead = (const ArrayOf<USHORT>&)
...@@ -490,12 +508,13 @@ struct ChainRule { ...@@ -490,12 +508,13 @@ struct ChainRule {
}; };
ASSERT_SIZE (ChainRule, 8); ASSERT_SIZE (ChainRule, 8);
struct ChainRuleSet { struct ChainRuleSet
{
inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &context) const { inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &context) const
{
unsigned int num_rules = rule.len; unsigned int num_rules = rule.len;
for (unsigned int i = 0; i < num_rules; i++) { for (unsigned int i = 0; i < num_rules; i++)
{
if ((this+rule[i]).apply (APPLY_ARG, context)) if ((this+rule[i]).apply (APPLY_ARG, context))
return true; return true;
} }
...@@ -510,13 +529,13 @@ struct ChainRuleSet { ...@@ -510,13 +529,13 @@ struct ChainRuleSet {
}; };
ASSERT_SIZE (ChainRuleSet, 2); ASSERT_SIZE (ChainRuleSet, 2);
struct ChainContextFormat1 { struct ChainContextFormat1
{
friend struct ChainContext; friend struct ChainContext;
private: private:
inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
{
unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
if (HB_LIKELY (index == NOT_COVERED)) if (HB_LIKELY (index == NOT_COVERED))
return false; return false;
...@@ -539,13 +558,13 @@ struct ChainContextFormat1 { ...@@ -539,13 +558,13 @@ struct ChainContextFormat1 {
}; };
ASSERT_SIZE (ChainContextFormat1, 6); ASSERT_SIZE (ChainContextFormat1, 6);
struct ChainContextFormat2 { struct ChainContextFormat2
{
friend struct ChainContext; friend struct ChainContext;
private: private:
inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
{
unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
if (HB_LIKELY (index == NOT_COVERED)) if (HB_LIKELY (index == NOT_COVERED))
return false; return false;
...@@ -591,17 +610,14 @@ struct ChainContextFormat2 { ...@@ -591,17 +610,14 @@ struct ChainContextFormat2 {
}; };
ASSERT_SIZE (ChainContextFormat2, 12); ASSERT_SIZE (ChainContextFormat2, 12);
struct ChainContextFormat3 { struct ChainContextFormat3
{
friend struct ChainContext; friend struct ChainContext;
private: private:
inline bool apply_coverage (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
} {
inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const {
const OffsetArrayOf<Coverage> &input = (const OffsetArrayOf<Coverage>&) const OffsetArrayOf<Coverage> &input = (const OffsetArrayOf<Coverage>&)
*((const char *) &backtrack + backtrack.get_size ()); *((const char *) &backtrack + backtrack.get_size ());
...@@ -646,10 +662,11 @@ struct ChainContextFormat3 { ...@@ -646,10 +662,11 @@ struct ChainContextFormat3 {
}; };
ASSERT_SIZE (ChainContextFormat3, 10); ASSERT_SIZE (ChainContextFormat3, 10);
struct ChainContext { struct ChainContext
{
protected: protected:
bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
{
switch (u.format) { switch (u.format) {
case 1: return u.format1->apply (APPLY_ARG, apply_func); case 1: return u.format1->apply (APPLY_ARG, apply_func);
case 2: return u.format2->apply (APPLY_ARG, apply_func); case 2: return u.format2->apply (APPLY_ARG, apply_func);
...@@ -673,7 +690,8 @@ ASSERT_SIZE (ChainContext, 2); ...@@ -673,7 +690,8 @@ ASSERT_SIZE (ChainContext, 2);
* GSUB/GPOS Common * GSUB/GPOS Common
*/ */
struct GSUBGPOS { struct GSUBGPOS
{
static const hb_tag_t GSUBTag = HB_TAG ('G','S','U','B'); static const hb_tag_t GSUBTag = HB_TAG ('G','S','U','B');
static const hb_tag_t GPOSTag = HB_TAG ('G','P','O','S'); static const hb_tag_t GPOSTag = HB_TAG ('G','P','O','S');
......
...@@ -55,7 +55,8 @@ ...@@ -55,7 +55,8 @@
DEFINE_INDEX_OPERATOR(Type, array, num) \ DEFINE_INDEX_OPERATOR(Type, array, num) \
DEFINE_LEN(Type, array, num) DEFINE_LEN(Type, array, num)
#define DEFINE_INDEX_OPERATOR(Type, array, num) \ #define DEFINE_INDEX_OPERATOR(Type, array, num) \
inline const Type& operator[] (unsigned int i) const { \ inline const Type& operator[] (unsigned int i) const \
{ \
if (HB_UNLIKELY (i >= num)) return Null(Type); \ if (HB_UNLIKELY (i >= num)) return Null(Type); \
return array[i]; \ return array[i]; \
} }
...@@ -67,7 +68,8 @@ ...@@ -67,7 +68,8 @@
DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \ DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
DEFINE_LEN(Offset, array, num) DEFINE_LEN(Offset, array, num)
#define DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \ #define DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
inline const Type& operator[] (unsigned int i) const { \ inline const Type& operator[] (unsigned int i) const \
{ \
if (HB_UNLIKELY (i >= num)) return Null(Type); \ if (HB_UNLIKELY (i >= num)) return Null(Type); \
if (HB_UNLIKELY (!array[i])) return Null(Type); \ if (HB_UNLIKELY (!array[i])) return Null(Type); \
return (const Type&)*((const char*)this + array[i]); \ return (const Type&)*((const char*)this + array[i]); \
...@@ -75,20 +77,15 @@ ...@@ -75,20 +77,15 @@
#define DEFINE_ARRAY_INTERFACE(Type, name) \ #define DEFINE_ARRAY_INTERFACE(Type, name) \
inline const Type& get_##name (unsigned int i) const { \ inline const Type& get_##name (unsigned int i) const { return (*this)[i]; } \
return (*this)[i]; \ inline unsigned int get_##name##_count (void) const { return this->get_len (); }
} \
inline unsigned int get_##name##_count (void) const { \
return this->get_len (); \
}
#define DEFINE_INDEX_ARRAY_INTERFACE(name) \ #define DEFINE_INDEX_ARRAY_INTERFACE(name) \
inline unsigned int get_##name##_index (unsigned int i) const { \ inline unsigned int get_##name##_index (unsigned int i) const \
{ \
if (HB_UNLIKELY (i >= get_len ())) return NO_INDEX; \ if (HB_UNLIKELY (i >= get_len ())) return NO_INDEX; \
return (*this)[i]; \ return (*this)[i]; \
} \ } \
inline unsigned int get_##name##_count (void) const { \ inline unsigned int get_##name##_count (void) const { return get_len (); }
return get_len (); \
}
/* /*
...@@ -96,12 +93,8 @@ ...@@ -96,12 +93,8 @@
*/ */
#define DEFINE_LIST_INTERFACE(Type, name) \ #define DEFINE_LIST_INTERFACE(Type, name) \
inline const Type& get_##name (unsigned int i) const { \ inline const Type& get_##name (unsigned int i) const { return (this+name##List)[i]; } \
return (this+name##List)[i]; \ inline unsigned int get_##name##_count (void) const { return (this+name##List).len; }
} \
inline unsigned int get_##name##_count (void) const { \
return (this+name##List).len; \
}
/* /*
* Tag types * Tag types
...@@ -109,20 +102,18 @@ ...@@ -109,20 +102,18 @@
#define DEFINE_TAG_ARRAY_INTERFACE(Type, name) \ #define DEFINE_TAG_ARRAY_INTERFACE(Type, name) \
DEFINE_ARRAY_INTERFACE (Type, name); \ DEFINE_ARRAY_INTERFACE (Type, name); \
inline const Tag& get_##name##_tag (unsigned int i) const { \ inline const Tag& get_##name##_tag (unsigned int i) const { return (*this)[i].tag; }
return (*this)[i].tag; \
}
#define DEFINE_TAG_LIST_INTERFACE(Type, name) \ #define DEFINE_TAG_LIST_INTERFACE(Type, name) \
DEFINE_LIST_INTERFACE (Type, name); \ DEFINE_LIST_INTERFACE (Type, name); \
inline const Tag& get_##name##_tag (unsigned int i) const { \ inline const Tag& get_##name##_tag (unsigned int i) const { return (this+name##List).get_tag (i); }
return (this+name##List).get_tag (i); \
}
#define DEFINE_TAG_FIND_INTERFACE(Type, name) \ #define DEFINE_TAG_FIND_INTERFACE(Type, name) \
inline bool find_##name##_index (hb_tag_t tag, unsigned int *name##_index) const { \ inline bool find_##name##_index (hb_tag_t tag, unsigned int *name##_index) const { \
const Tag t = tag; \ const Tag t = tag; \
for (unsigned int i = 0; i < get_##name##_count (); i++) { \ for (unsigned int i = 0; i < get_##name##_count (); i++) \
if (t == get_##name##_tag (i)) { \ { \
if (t == get_##name##_tag (i)) \
{ \
if (name##_index) *name##_index = i; \ if (name##_index) *name##_index = i; \
return true; \ return true; \
} \ } \
...@@ -130,7 +121,8 @@ ...@@ -130,7 +121,8 @@
if (name##_index) *name##_index = NO_INDEX; \ if (name##_index) *name##_index = NO_INDEX; \
return false; \ return false; \
} \ } \
inline const Type& get_##name##_by_tag (hb_tag_t tag) const { \ inline const Type& get_##name##_by_tag (hb_tag_t tag) const \
{ \
unsigned int i; \ unsigned int i; \
if (find_##name##_index (tag, &i)) \ if (find_##name##_index (tag, &i)) \
return get_##name (i); \ return get_##name (i); \
...@@ -150,7 +142,8 @@ static const char NullPool[16] = ""; ...@@ -150,7 +142,8 @@ static const char NullPool[16] = "";
/* Generic template for nul-content sizeof-sized Null objects. */ /* Generic template for nul-content sizeof-sized Null objects. */
template <typename Type> template <typename Type>
struct Null { struct Null
{
ASSERT_STATIC (sizeof (Type) <= sizeof (NullPool)); ASSERT_STATIC (sizeof (Type) <= sizeof (NullPool));
static inline const Type &get () { return (const Type&) *NullPool; } static inline const Type &get () { return (const Type&) *NullPool; }
}; };
...@@ -158,7 +151,8 @@ struct Null { ...@@ -158,7 +151,8 @@ struct Null {
/* Specializaiton for arbitrary-content arbitrary-sized Null objects. */ /* Specializaiton for arbitrary-content arbitrary-sized Null objects. */
#define DEFINE_NULL_DATA(Type, size, data) \ #define DEFINE_NULL_DATA(Type, size, data) \
template <> \ template <> \
struct Null <Type> { \ struct Null <Type> \
{ \
static inline const Type &get () { static const char bytes[size] = data; return (const Type&) *bytes; /* XXX */ } \ static inline const Type &get () { static const char bytes[size] = data; return (const Type&) *bytes; /* XXX */ } \
} }
...@@ -174,13 +168,12 @@ struct Null <Type> { \ ...@@ -174,13 +168,12 @@ struct Null <Type> { \
* instance of Type located at the input data location. It's just a * instance of Type located at the input data location. It's just a
* fancy, NULL-safe, cast! */ * fancy, NULL-safe, cast! */
#define STATIC_DEFINE_GET_FOR_DATA(Type) \ #define STATIC_DEFINE_GET_FOR_DATA(Type) \
static inline const Type& get_for_data (const char *data) { \ static inline const Type& get_for_data (const char *data) \
{ \
if (HB_UNLIKELY (data == NULL)) return Null(Type); \ if (HB_UNLIKELY (data == NULL)) return Null(Type); \
return (const Type&)*data; \ return (const Type&)*data; \
} \ } \
static inline Type& get_for_data (char *data) { \ static inline Type& get_for_data (char *data) { return (Type&)*data; }
return (Type&)*data; \
}
...@@ -214,7 +207,8 @@ struct Null <Type> { \ ...@@ -214,7 +207,8 @@ struct Null <Type> { \
#define DEFINE_INT_TYPE0(NAME, type) DEFINE_INT_TYPE1 (NAME, type, hb_be_##type) #define DEFINE_INT_TYPE0(NAME, type) DEFINE_INT_TYPE1 (NAME, type, hb_be_##type)
#define DEFINE_INT_TYPE(NAME, u, w) DEFINE_INT_TYPE0 (NAME, u##int##w##_t) #define DEFINE_INT_TYPE(NAME, u, w) DEFINE_INT_TYPE0 (NAME, u##int##w##_t)
#define DEFINE_INT_TYPE_STRUCT(NAME, u, w) \ #define DEFINE_INT_TYPE_STRUCT(NAME, u, w) \
struct NAME { \ struct NAME \
{ \
DEFINE_INT_TYPE(NAME, u, w) \ DEFINE_INT_TYPE(NAME, u, w) \
}; \ }; \
ASSERT_SIZE (NAME, w / 8) ASSERT_SIZE (NAME, w / 8)
...@@ -232,7 +226,8 @@ DEFINE_INT_TYPE_STRUCT (LONG, , 32); /* 32-bit signed integer. */ ...@@ -232,7 +226,8 @@ DEFINE_INT_TYPE_STRUCT (LONG, , 32); /* 32-bit signed integer. */
DEFINE_INT_TYPE_STRUCT (LONGDATETIME, , 64); DEFINE_INT_TYPE_STRUCT (LONGDATETIME, , 64);
/* 32-bit signed fixed-point number (16.16) */ /* 32-bit signed fixed-point number (16.16) */
struct Fixed { struct Fixed
{
inline Fixed& operator = (int32_t v) { i = (int16_t) (v >> 16); f = (uint16_t) v; return *this; } \ inline Fixed& operator = (int32_t v) { i = (int16_t) (v >> 16); f = (uint16_t) v; return *this; } \
inline operator int32_t(void) const { return (((int32_t) i) << 16) + (uint16_t) f; } \ inline operator int32_t(void) const { return (((int32_t) i) << 16) + (uint16_t) f; } \
inline bool operator== (Fixed o) const { return i == o.i && f == o.f; } \ inline bool operator== (Fixed o) const { return i == o.i && f == o.f; } \
...@@ -251,24 +246,24 @@ ASSERT_SIZE (Fixed, 4); ...@@ -251,24 +246,24 @@ ASSERT_SIZE (Fixed, 4);
struct FUNIT; struct FUNIT;
/* 16-bit signed integer (SHORT) that describes a quantity in FUnits. */ /* 16-bit signed integer (SHORT) that describes a quantity in FUnits. */
struct FWORD : SHORT { struct FWORD : SHORT {};
};
ASSERT_SIZE (FWORD, 2); ASSERT_SIZE (FWORD, 2);
/* 16-bit unsigned integer (USHORT) that describes a quantity in FUnits. */ /* 16-bit unsigned integer (USHORT) that describes a quantity in FUnits. */
struct UFWORD : USHORT { struct UFWORD : USHORT {};
};
ASSERT_SIZE (UFWORD, 2); ASSERT_SIZE (UFWORD, 2);
/* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */ /* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */
struct F2DOT14 : SHORT { struct F2DOT14 : SHORT
{
inline operator double() const { return (uint32_t) this / 16384.; } inline operator double() const { return (uint32_t) this / 16384.; }
}; };
ASSERT_SIZE (F2DOT14, 2); ASSERT_SIZE (F2DOT14, 2);
/* Array of four uint8s (length = 32 bits) used to identify a script, language /* Array of four uint8s (length = 32 bits) used to identify a script, language
* system, feature, or baseline */ * system, feature, or baseline */
struct Tag { struct Tag
{
inline Tag (void) { v[0] = v[1] = v[2] = v[3] = 0; } inline Tag (void) { v[0] = v[1] = v[2] = v[3] = 0; }
inline Tag (uint32_t v) { (ULONG&)(*this) = v; } inline Tag (uint32_t v) { (ULONG&)(*this) = v; }
inline Tag (const char *c) { v[0] = c[0]; v[1] = c[1]; v[2] = c[2]; v[3] = c[3]; } inline Tag (const char *c) { v[0] = c[0]; v[1] = c[1]; v[2] = c[2]; v[3] = c[3]; }
...@@ -296,22 +291,24 @@ DEFINE_INT_TYPE_STRUCT (Offset, u, 16); ...@@ -296,22 +291,24 @@ DEFINE_INT_TYPE_STRUCT (Offset, u, 16);
/* Template subclass of Offset that does the dereferencing. Use: (this+memberName) */ /* Template subclass of Offset that does the dereferencing. Use: (this+memberName) */
template <typename Type> template <typename Type>
struct OffsetTo : Offset { struct OffsetTo : Offset
inline const Type& operator() (const void *base) const { {
inline const Type& operator() (const void *base) const
{
unsigned int offset = *this; unsigned int offset = *this;
if (HB_UNLIKELY (!offset)) return Null(Type); if (HB_UNLIKELY (!offset)) return Null(Type);
return (const Type&)*((const char *) base + offset); return (const Type&)*((const char *) base + offset);
} }
}; };
template <typename Base, typename Type> template <typename Base, typename Type>
inline const Type& operator + (const Base &base, OffsetTo<Type> offset) { inline const Type& operator + (const Base &base, OffsetTo<Type> offset) { return offset (base); }
return offset(base);
}
/* CheckSum */ /* CheckSum */
struct CheckSum : ULONG { struct CheckSum : ULONG
static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length) { {
static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length)
{
uint32_t Sum = 0L; uint32_t Sum = 0L;
ULONG *EndPtr = Table+((Length+3) & ~3) / sizeof(ULONG); ULONG *EndPtr = Table+((Length+3) & ~3) / sizeof(ULONG);
...@@ -327,11 +324,11 @@ ASSERT_SIZE (CheckSum, 4); ...@@ -327,11 +324,11 @@ ASSERT_SIZE (CheckSum, 4);
* Version Numbers * Version Numbers
*/ */
struct USHORT_Version : USHORT { struct USHORT_Version : USHORT {};
};
ASSERT_SIZE (USHORT_Version, 2); ASSERT_SIZE (USHORT_Version, 2);
struct Fixed_Version : Fixed { struct Fixed_Version : Fixed
{
inline int16_t major (void) const { return this->int_part(); } inline int16_t major (void) const { return this->int_part(); }
inline int16_t minor (void) const { return this->frac_part(); } inline int16_t minor (void) const { return this->frac_part(); }
}; };
...@@ -343,12 +340,15 @@ ASSERT_SIZE (Fixed_Version, 4); ...@@ -343,12 +340,15 @@ ASSERT_SIZE (Fixed_Version, 4);
/* An array with a USHORT number of elements. */ /* An array with a USHORT number of elements. */
template <typename Type> template <typename Type>
struct ArrayOf { struct ArrayOf
inline const Type& operator [] (unsigned int i) const { {
inline const Type& operator [] (unsigned int i) const
{
if (HB_UNLIKELY (i >= len)) return Null(Type); if (HB_UNLIKELY (i >= len)) return Null(Type);
return array[i]; return array[i];
} }
inline unsigned int get_size () const { inline unsigned int get_size () const
{
return sizeof (len) + len * sizeof (array[0]); return sizeof (len) + len * sizeof (array[0]);
} }
...@@ -359,12 +359,15 @@ struct ArrayOf { ...@@ -359,12 +359,15 @@ struct ArrayOf {
/* An array with a USHORT number of elements, /* An array with a USHORT number of elements,
* starting at second element. */ * starting at second element. */
template <typename Type> template <typename Type>
struct HeadlessArrayOf { struct HeadlessArrayOf
inline const Type& operator [] (unsigned int i) const { {
inline const Type& operator [] (unsigned int i) const
{
if (HB_UNLIKELY (i >= len || !i)) return Null(Type); if (HB_UNLIKELY (i >= len || !i)) return Null(Type);
return array[i-1]; return array[i-1];
} }
inline unsigned int get_size () const { inline unsigned int get_size () const
{
return sizeof (len) + (len ? len - 1 : 0) * sizeof (array[0]); return sizeof (len) + (len ? len - 1 : 0) * sizeof (array[0]);
} }
...@@ -374,8 +377,7 @@ struct HeadlessArrayOf { ...@@ -374,8 +377,7 @@ struct HeadlessArrayOf {
/* Array of Offset's */ /* Array of Offset's */
template <typename Type> template <typename Type>
struct OffsetArrayOf : ArrayOf<OffsetTo<Type> > { struct OffsetArrayOf : ArrayOf<OffsetTo<Type> > {};
};
/* An array type is one that contains a variable number of objects /* An array type is one that contains a variable number of objects
* as its last item. An array object is extended with get_len() * as its last item. An array object is extended with get_len()
...@@ -384,7 +386,8 @@ struct OffsetArrayOf : ArrayOf<OffsetTo<Type> > { ...@@ -384,7 +386,8 @@ struct OffsetArrayOf : ArrayOf<OffsetTo<Type> > {
DEFINE_INDEX_OPERATOR(Type, array, num) \ DEFINE_INDEX_OPERATOR(Type, array, num) \
DEFINE_LEN(Type, array, num) DEFINE_LEN(Type, array, num)
#define DEFINE_INDEX_OPERATOR(Type, array, num) \ #define DEFINE_INDEX_OPERATOR(Type, array, num) \
inline const Type& operator[] (unsigned int i) const { \ inline const Type& operator[] (unsigned int i) const \
{ \
if (HB_UNLIKELY (i >= num)) return Null(Type); \ if (HB_UNLIKELY (i >= num)) return Null(Type); \
return array[i]; \ return array[i]; \
} }
...@@ -398,8 +401,8 @@ struct OpenTypeFontFile; ...@@ -398,8 +401,8 @@ struct OpenTypeFontFile;
struct OffsetTable; struct OffsetTable;
struct TTCHeader; struct TTCHeader;
typedef struct TableDirectory { typedef struct TableDirectory
{
friend struct OpenTypeFontFile; friend struct OpenTypeFontFile;
friend struct OffsetTable; friend struct OffsetTable;
...@@ -418,8 +421,8 @@ typedef struct TableDirectory { ...@@ -418,8 +421,8 @@ typedef struct TableDirectory {
} OpenTypeTable; } OpenTypeTable;
ASSERT_SIZE (TableDirectory, 16); ASSERT_SIZE (TableDirectory, 16);
typedef struct OffsetTable { typedef struct OffsetTable
{
friend struct OpenTypeFontFile; friend struct OpenTypeFontFile;
friend struct TTCHeader; friend struct TTCHeader;
...@@ -444,8 +447,8 @@ ASSERT_SIZE (OffsetTable, 12); ...@@ -444,8 +447,8 @@ ASSERT_SIZE (OffsetTable, 12);
* TrueType Collections * TrueType Collections
*/ */
struct TTCHeader { struct TTCHeader
{
friend struct OpenTypeFontFile; friend struct OpenTypeFontFile;
private: private:
...@@ -468,8 +471,8 @@ ASSERT_SIZE (TTCHeader, 12); ...@@ -468,8 +471,8 @@ ASSERT_SIZE (TTCHeader, 12);
* OpenType Font File * OpenType Font File
*/ */
struct OpenTypeFontFile { struct OpenTypeFontFile
{
static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ); static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 );
static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O'); static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O');
static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f'); static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f');
...@@ -481,31 +484,31 @@ struct OpenTypeFontFile { ...@@ -481,31 +484,31 @@ struct OpenTypeFontFile {
inline const Tag& get_tag (void) const { return tag; } inline const Tag& get_tag (void) const { return tag; }
/* This is how you get a table */ /* This is how you get a table */
inline const char* get_table_data (const OpenTypeTable& table) const { inline const char* get_table_data (const OpenTypeTable& table) const { return (*this)[table]; }
return (*this)[table]; inline char* get_table_data (const OpenTypeTable& table) { return (*this)[table]; }
}
inline char* get_table_data (const OpenTypeTable& table) {
return (*this)[table];
}
private: private:
inline const char* operator[] (const OpenTypeTable& table) const { inline const char* operator[] (const OpenTypeTable& table) const
{
if (HB_UNLIKELY (table.offset == 0)) return NULL; if (HB_UNLIKELY (table.offset == 0)) return NULL;
return ((const char*)this) + table.offset; return ((const char*)this) + table.offset;
} }
inline char* operator[] (const OpenTypeTable& table) { inline char* operator[] (const OpenTypeTable& table)
{
if (HB_UNLIKELY (table.offset == 0)) return NULL; if (HB_UNLIKELY (table.offset == 0)) return NULL;
return ((char*)this) + table.offset; return ((char*)this) + table.offset;
} }
unsigned int get_len (void) const { unsigned int get_len (void) const
{
switch (tag) { switch (tag) {
default: return 0; default: return 0;
case TrueTypeTag: case CFFTag: return 1; case TrueTypeTag: case CFFTag: return 1;
case TTCTag: return ((const TTCHeader&)*this).get_len(); case TTCTag: return ((const TTCHeader&)*this).get_len();
} }
} }
const OpenTypeFontFace& operator[] (unsigned int i) const { const OpenTypeFontFace& operator[] (unsigned int i) const
{
if (HB_UNLIKELY (i >= get_len ())) return Null(OpenTypeFontFace); if (HB_UNLIKELY (i >= get_len ())) return Null(OpenTypeFontFace);
switch (tag) { switch (tag) {
default: case TrueTypeTag: case CFFTag: return (const OffsetTable&)*this; default: case TrueTypeTag: case CFFTag: return (const OffsetTable&)*this;
......
...@@ -36,18 +36,21 @@ ...@@ -36,18 +36,21 @@
typedef unsigned int hb_ot_layout_class_t; typedef unsigned int hb_ot_layout_class_t;
struct _hb_ot_layout_t { struct _hb_ot_layout_t
{
const struct GDEF *gdef; const struct GDEF *gdef;
const struct GSUB *gsub; const struct GSUB *gsub;
const struct GPOS *gpos; const struct GPOS *gpos;
struct { struct
{
unsigned char *klasses; unsigned char *klasses;
unsigned int len; unsigned int len;
} new_gdef; } new_gdef;
/* TODO full-matrix transformation? */ /* TODO full-matrix transformation? */
struct gpos_info_t { struct gpos_info_t
{
unsigned int x_ppem, y_ppem; unsigned int x_ppem, y_ppem;
hb_16dot16_t x_scale, y_scale; hb_16dot16_t x_scale, y_scale;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册