提交 303fe628 编写于 作者: B Behdad Esfahbod

Misc cleanup

上级 4c2556cb
all: main all: main
CXXFLAGS = -Wall -Wextra `pkg-config --cflags --libs glib-2.0` CPPFLAGS = -Wall -Wextra `pkg-config --cflags glib-2.0`
LDFLAGS = `pkg-config --libs glib-2.0`
CXX = gcc $(GCCOPTS) -fno-rtti -fno-exceptions -Wabi -Wpadded -Wcast-align
main: *.h main: main.cc *.h
$(CXX) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $<
clean:
rm -f main main.o
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "harfbuzz-open-private.h" #include "harfbuzz-open-private.h"
struct GDEFHeader { struct GDEFHeader {
/* TODO */
private:
Fixed version; /* Version of the GDEF table--initially Fixed version; /* Version of the GDEF table--initially
* 0x00010000 */ * 0x00010000 */
Offset glyphClassDef; /* Offset to class definition table Offset glyphClassDef; /* Offset to class definition table
...@@ -19,6 +22,7 @@ struct GDEFHeader { ...@@ -19,6 +22,7 @@ struct GDEFHeader {
* mark attachment type--from beginning * mark attachment type--from beginning
* of GDEF header (may be NULL) */ * of GDEF header (may be NULL) */
}; };
ASSERT_SIZE (GDEFHeader, 12);
struct GlyphClassDef : ClassDef { struct GlyphClassDef : ClassDef {
static const uint16_t BaseGlyph = 0x0001u; static const uint16_t BaseGlyph = 0x0001u;
...@@ -27,10 +31,24 @@ struct GlyphClassDef : ClassDef { ...@@ -27,10 +31,24 @@ struct GlyphClassDef : ClassDef {
static const uint16_t ComponentGlyph = 0x0004u; static const uint16_t ComponentGlyph = 0x0004u;
}; };
struct AttachPoint;
struct AttachList { struct AttachList {
/* XXX */ /* AttachPoint tables, in Coverage Index order */
/* TODO get attach lists */
/* DEFINE_INDIRECT_OFFSET_ARRAY_TYPE (AttachPoint, attachPoint, glyphCount, get_coverage);
// get_coverage
inline Coverage* get_default_language_system (void) {
if (!defaultLangSys)
return NULL;
return (LangSys *)((char*)this + defaultLangSys);
}
*/
private:
Offset coverage; /* Offset to Coverage table -- from Offset coverage; /* Offset to Coverage table -- from
* beginning of AttachList table */ * beginning of AttachList table */
USHORT glyphCount; /* Number of glyphs with attachment USHORT glyphCount; /* Number of glyphs with attachment
...@@ -39,15 +57,18 @@ struct AttachList { ...@@ -39,15 +57,18 @@ struct AttachList {
* tables--from beginning of AttachList * tables--from beginning of AttachList
* table--in Coverage Index order */ * table--in Coverage Index order */
}; };
ASSERT_SIZE (AttachList, 4);
struct AttachPoint { struct AttachPoint {
/* XXX */ /* TODO */
private:
USHORT pointCount; /* Number of attachment points on USHORT pointCount; /* Number of attachment points on
* this glyph */ * this glyph */
USHORT pointIndex[]; /* Array of contour point indices--in USHORT pointIndex[]; /* Array of contour point indices--in
* increasing numerical order */ * increasing numerical order */
}; };
ASSERT_SIZE (AttachPoint, 2);
/* /*
* Ligature Caret Table * Ligature Caret Table
...@@ -56,8 +77,9 @@ struct AttachPoint { ...@@ -56,8 +77,9 @@ struct AttachPoint {
struct CaretValue; struct CaretValue;
struct LigCaretList { struct LigCaretList {
/* XXX */ /* TODO */
private:
Offset coverage; /* Offset to Coverage table--from Offset coverage; /* Offset to Coverage table--from
* beginning of LigCaretList table */ * beginning of LigCaretList table */
USHORT ligGlyphCount; /* Number of ligature glyphs */ USHORT ligGlyphCount; /* Number of ligature glyphs */
...@@ -66,12 +88,14 @@ struct LigCaretList { ...@@ -66,12 +88,14 @@ struct LigCaretList {
* LigCaretList table--in Coverage * LigCaretList table--in Coverage
* Index order */ * Index order */
}; };
ASSERT_SIZE (LigCaretList, 4);
struct LigGlyph { struct LigGlyph {
/* Caret value tables, in increasing coordinate order */ /* Caret value tables, in increasing coordinate order */
DEFINE_OFFSET_ARRAY_TYPE (CaretValue, caretValue, caretCount); DEFINE_OFFSET_ARRAY_TYPE (CaretValue, caretValue, caretCount);
/* XXX */ /* TODO */
private:
USHORT caretCount; /* Number of CaretValues for this USHORT caretCount; /* Number of CaretValues for this
* ligature (components - 1) */ * ligature (components - 1) */
Offset caretValue[]; /* Array of offsets to CaretValue Offset caretValue[]; /* Array of offsets to CaretValue
...@@ -79,40 +103,50 @@ struct LigGlyph { ...@@ -79,40 +103,50 @@ struct LigGlyph {
* table--in increasing coordinate * table--in increasing coordinate
* order */ * order */
}; };
ASSERT_SIZE (LigGlyph, 2);
struct CaretValueFormat1 { struct CaretValueFormat1 {
USHORT caretValueFormat; /* Format identifier--format = 1 */
SHORT coordinate; /* X or Y value, in design units */
inline int get_caret_value (int ppem) const { inline int get_caret_value (int ppem) const {
return /* XXX garbage */ coordinate / ppem; return /* TODO garbage */ coordinate / ppem;
} }
private:
USHORT caretValueFormat; /* Format identifier--format = 1 */
SHORT coordinate; /* X or Y value, in design units */
}; };
ASSERT_SIZE (CaretValueFormat1, 4);
struct CaretValueFormat2 { struct CaretValueFormat2 {
USHORT caretValueFormat; /* Format identifier--format = 2 */
USHORT caretValuePoint; /* Contour point index on glyph */
inline int get_caret_value (int ppem) const { inline int get_caret_value (int ppem) const {
return /* XXX garbage */ 0 / ppem; return /* TODO garbage */ 0 / ppem;
} }
private:
USHORT caretValueFormat; /* Format identifier--format = 2 */
USHORT caretValuePoint; /* Contour point index on glyph */
}; };
ASSERT_SIZE (CaretValueFormat2, 4);
struct CaretValueFormat3 { struct CaretValueFormat3 {
inline const Device* get_device (void) const { inline const Device* get_device (void) const {
return (const Device*)((const char*)this + deviceTable); return (const Device*)((const char*)this + deviceTable);
} }
inline int get_caret_value (int ppem) const {
return /* TODO garbage */ (coordinate + get_device()->get_delta (ppem)) / ppem;
}
private:
USHORT caretValueFormat; /* Format identifier--format = 3 */ USHORT caretValueFormat; /* Format identifier--format = 3 */
SHORT coordinate; /* X or Y value, in design units */ SHORT coordinate; /* X or Y value, in design units */
Offset deviceTable; /* Offset to Device table for X or Y Offset deviceTable; /* Offset to Device table for X or Y
* value--from beginning of CaretValue * value--from beginning of CaretValue
* table */ * table */
inline int get_caret_value (int ppem) const {
return /* XXX garbage */ (coordinate + get_device()->get_delta (ppem)) / ppem;
}
}; };
ASSERT_SIZE (CaretValueFormat3, 6);
struct CaretValue { struct CaretValue {
DEFINE_NON_INSTANTIABLE(CaretValue); DEFINE_NON_INSTANTIABLE(CaretValue);
...@@ -136,12 +170,13 @@ struct CaretValue { ...@@ -136,12 +170,13 @@ struct CaretValue {
} }
} }
private:
union { union {
USHORT caretValueFormat; /* Format identifier */ USHORT caretValueFormat; /* Format identifier */
CaretValueFormat1 format1; CaretValueFormat1 format1;
CaretValueFormat2 format2; CaretValueFormat2 format2;
CaretValueFormat3 format3; CaretValueFormat3 format3;
/* XXX old HarfBuzz code has a format 4 here! */ /* FIXME old HarfBuzz code has a format 4 here! */
} u; } u;
}; };
......
...@@ -115,23 +115,38 @@ ...@@ -115,23 +115,38 @@
* All OpenType fonts use Motorola-style byte ordering (Big Endian):" */ * All OpenType fonts use Motorola-style byte ordering (Big Endian):" */
DEFINE_INT_TYPE_STRUCT (BYTE, u, 8); /* 8-bit unsigned integer. */ DEFINE_INT_TYPE_STRUCT (BYTE, u, 8); /* 8-bit unsigned integer. */
DEFINE_INT_TYPE_STRUCT (CHAR, , 8); /* 8-bit signed integer. */ ASSERT_SIZE (BYTE, 1);
DEFINE_INT_TYPE_STRUCT (USHORT, u, 16); /* 16-bit unsigned integer. */ DEFINE_INT_TYPE_STRUCT (CHAR, , 8); /* 8-bit signed integer. */
ASSERT_SIZE (CHAR, 1);
DEFINE_INT_TYPE_STRUCT (USHORT, u, 16); /* 16-bit unsigned integer. */
ASSERT_SIZE (USHORT, 2);
DEFINE_INT_TYPE_STRUCT (SHORT, , 16); /* 16-bit signed integer. */ DEFINE_INT_TYPE_STRUCT (SHORT, , 16); /* 16-bit signed integer. */
ASSERT_SIZE (SHORT, 2);
DEFINE_INT_TYPE_STRUCT (ULONG, u, 32); /* 32-bit unsigned integer. */ DEFINE_INT_TYPE_STRUCT (ULONG, u, 32); /* 32-bit unsigned integer. */
ASSERT_SIZE (ULONG, 4);
DEFINE_INT_TYPE_STRUCT (LONG, , 32); /* 32-bit signed integer. */ DEFINE_INT_TYPE_STRUCT (LONG, , 32); /* 32-bit signed integer. */
ASSERT_SIZE (LONG, 4);
/* Date represented in number of seconds since 12:00 midnight, January 1, /* Date represented in number of seconds since 12:00 midnight, January 1,
* 1904. The value is represented as a signed 64-bit integer. */ * 1904. The value is represented as a signed 64-bit 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 : LONG { struct Fixed {
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 bool operator== (Fixed o) const { return i == o.i && f == o.f; } \
inline operator double(void) const { return (uint32_t) this / 65536.; } inline operator double(void) const { return (uint32_t) this / 65536.; }
inline int16_t int_part (void) const { return (uint32_t) this >> 16; } inline int16_t int_part (void) const { return i; }
inline int16_t frac_part (void) const { return (uint32_t) this & 0xffff; } inline uint16_t frac_part (void) const { return f; }
private:
SHORT i;
USHORT f;
}; };
ASSERT_SIZE (Fixed, 4);
/* Smallest measurable distance in the em space. */ /* Smallest measurable distance in the em space. */
struct FUNIT; struct FUNIT;
...@@ -139,15 +154,18 @@ struct FUNIT; ...@@ -139,15 +154,18 @@ 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);
/* 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);
/* 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);
/* 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 */
...@@ -162,14 +180,18 @@ struct Tag { ...@@ -162,14 +180,18 @@ struct Tag {
inline operator const char* (void) const { return (const char *)this; } inline operator const char* (void) const { return (const char *)this; }
inline operator char* (void) { return (char *)this; } inline operator char* (void) { return (char *)this; }
private: char v[4]; private:
char v[4];
}; };
ASSERT_SIZE (Tag, 4);
/* Glyph index number, same as uint16 (length = 16 bits) */ /* Glyph index number, same as uint16 (length = 16 bits) */
DEFINE_INT_TYPE_STRUCT (GlyphID, u, 16); DEFINE_INT_TYPE_STRUCT (GlyphID, u, 16);
ASSERT_SIZE (GlyphID, 2);
/* Offset to a table, same as uint16 (length = 16 bits), NULL offset = 0x0000 */ /* Offset to a table, same as uint16 (length = 16 bits), NULL offset = 0x0000 */
DEFINE_INT_TYPE_STRUCT (Offset, u, 16); DEFINE_INT_TYPE_STRUCT (Offset, u, 16);
ASSERT_SIZE (Offset, 2);
/* CheckSum */ /* CheckSum */
struct CheckSum : ULONG { struct CheckSum : ULONG {
...@@ -182,6 +204,7 @@ struct CheckSum : ULONG { ...@@ -182,6 +204,7 @@ struct CheckSum : ULONG {
return Sum; return Sum;
} }
}; };
ASSERT_SIZE (CheckSum, 4);
/* /*
...@@ -190,11 +213,13 @@ struct CheckSum : ULONG { ...@@ -190,11 +213,13 @@ struct CheckSum : ULONG {
struct USHORT_Version : USHORT { struct USHORT_Version : USHORT {
}; };
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(); }
}; };
ASSERT_SIZE (Fixed_Version, 4);
/* /*
...@@ -206,18 +231,29 @@ struct OffsetTable; ...@@ -206,18 +231,29 @@ struct OffsetTable;
struct TTCHeader; struct TTCHeader;
typedef struct TableDirectory { typedef struct TableDirectory {
friend struct OpenTypeFontFile;
inline const Tag& get_tag (void) const { return tag; }
inline unsigned long get_checksum (void) const { return checkSum; }
inline unsigned long get_offset (void) const { return offset; }
inline unsigned long get_length (void) const { return length; }
private:
Tag tag; /* 4-byte identifier. */ Tag tag; /* 4-byte identifier. */
CheckSum checkSum; /* CheckSum for this table. */ CheckSum checkSum; /* CheckSum for this table. */
ULONG offset; /* Offset from beginning of TrueType font ULONG offset; /* Offset from beginning of TrueType font
* file. */ * file. */
ULONG length; /* Length of this table. */ ULONG length; /* Length of this table. */
} OpenTypeTable; } OpenTypeTable;
ASSERT_SIZE (TableDirectory, 16);
typedef struct OffsetTable { typedef struct OffsetTable {
/* OpenTypeTables, in no particular order */ /* OpenTypeTables, in no particular order */
DEFINE_ARRAY_TYPE (TableDirectory, tableDir, numTables); DEFINE_ARRAY_TYPE (TableDirectory, tableDir, numTables);
// TODO: Implement find_table // TODO: Implement find_table
private:
Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */ Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
USHORT numTables; /* Number of tables. */ USHORT numTables; /* Number of tables. */
USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */ USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */
...@@ -225,6 +261,7 @@ typedef struct OffsetTable { ...@@ -225,6 +261,7 @@ typedef struct OffsetTable {
USHORT rangeShift; /* NumTables x 16-searchRange. */ USHORT rangeShift; /* NumTables x 16-searchRange. */
TableDirectory tableDir[]; /* TableDirectory entries. numTables items */ TableDirectory tableDir[]; /* TableDirectory entries. numTables items */
} OpenTypeFontFace; } OpenTypeFontFace;
ASSERT_SIZE (OffsetTable, 12);
/* /*
* TrueType Collections * TrueType Collections
...@@ -234,6 +271,7 @@ struct TTCHeader { ...@@ -234,6 +271,7 @@ struct TTCHeader {
/* OpenTypeFontFaces, in no particular order */ /* OpenTypeFontFaces, in no particular order */
DEFINE_OFFSET_ARRAY_TYPE (OffsetTable, offsetTable, numFonts); DEFINE_OFFSET_ARRAY_TYPE (OffsetTable, offsetTable, numFonts);
private:
Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */ Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
ULONG version; /* Version of the TTC Header (1.0 or 2.0), ULONG version; /* Version of the TTC Header (1.0 or 2.0),
* 0x00010000 or 0x00020000 */ * 0x00010000 or 0x00020000 */
...@@ -241,6 +279,7 @@ struct TTCHeader { ...@@ -241,6 +279,7 @@ struct TTCHeader {
ULONG offsetTable[]; /* Array of offsets to the OffsetTable for each font ULONG offsetTable[]; /* Array of offsets to the OffsetTable for each font
* from the beginning of the file */ * from the beginning of the file */
}; };
ASSERT_SIZE (TTCHeader, 12);
/* /*
...@@ -299,9 +338,12 @@ struct OpenTypeFontFile { ...@@ -299,9 +338,12 @@ struct OpenTypeFontFile {
case TTCTag: return ((TTCHeader&)*this)[i]; case TTCTag: return ((TTCHeader&)*this)[i];
} }
} }
inline const Tag& get_tag (void) const { return tag; }
private:
Tag tag; /* 4-byte identifier. */ Tag tag; /* 4-byte identifier. */
}; };
ASSERT_SIZE (OpenTypeFontFile, 4);
...@@ -328,15 +370,18 @@ typedef struct Record { ...@@ -328,15 +370,18 @@ typedef struct Record {
Offset offset; /* Offset from beginning of object holding Offset offset; /* Offset from beginning of object holding
* the Record */ * the Record */
} ScriptRecord, LangSysRecord, FeatureRecord; } ScriptRecord, LangSysRecord, FeatureRecord;
ASSERT_SIZE (Record, 6);
struct ScriptList { struct ScriptList {
/* Scripts, in sorted alphabetical tag order */ /* Scripts, in sorted alphabetical tag order */
DEFINE_RECORD_ARRAY_TYPE (Script, scriptRecord, scriptCount); DEFINE_RECORD_ARRAY_TYPE (Script, scriptRecord, scriptCount);
private:
USHORT scriptCount; /* Number of ScriptRecords */ USHORT scriptCount; /* Number of ScriptRecords */
ScriptRecord scriptRecord[]; /* Array of ScriptRecords--listed alphabetically ScriptRecord scriptRecord[]; /* Array of ScriptRecords--listed alphabetically
* by ScriptTag */ * by ScriptTag */
}; };
ASSERT_SIZE (ScriptList, 2);
struct Script { struct Script {
/* LangSys', in sorted alphabetical tag order */ /* LangSys', in sorted alphabetical tag order */
...@@ -354,6 +399,7 @@ struct Script { ...@@ -354,6 +399,7 @@ struct Script {
return (LangSys *)((char*)this + defaultLangSys); return (LangSys *)((char*)this + defaultLangSys);
} }
private:
Offset defaultLangSys; /* Offset to DefaultLangSys table--from Offset defaultLangSys; /* Offset to DefaultLangSys table--from
* beginning of Script table--may be NULL */ * beginning of Script table--may be NULL */
USHORT langSysCount; /* Number of LangSysRecords for this script-- USHORT langSysCount; /* Number of LangSysRecords for this script--
...@@ -361,6 +407,7 @@ struct Script { ...@@ -361,6 +407,7 @@ struct Script {
LangSysRecord langSysRecord[];/* Array of LangSysRecords--listed LangSysRecord langSysRecord[];/* Array of LangSysRecords--listed
* alphabetically by LangSysTag */ * alphabetically by LangSysTag */
}; };
ASSERT_SIZE (Script, 4);
struct LangSys { struct LangSys {
/* Feature indices, in no particular order */ /* Feature indices, in no particular order */
...@@ -373,6 +420,7 @@ struct LangSys { ...@@ -373,6 +420,7 @@ struct LangSys {
return reqFeatureIndex;; return reqFeatureIndex;;
} }
private:
Offset lookupOrder; /* = NULL (reserved for an offset to a Offset lookupOrder; /* = NULL (reserved for an offset to a
* reordering table) */ * reordering table) */
USHORT reqFeatureIndex;/* Index of a feature required for this USHORT reqFeatureIndex;/* Index of a feature required for this
...@@ -384,16 +432,19 @@ struct LangSys { ...@@ -384,16 +432,19 @@ struct LangSys {
USHORT featureIndex[]; /* Array of indices into the FeatureList--in USHORT featureIndex[]; /* Array of indices into the FeatureList--in
* arbitrary order. featureCount entires long */ * arbitrary order. featureCount entires long */
}; };
ASSERT_SIZE (LangSys, 6);
struct FeatureList { struct FeatureList {
/* Feature indices, in sorted alphabetical tag order */ /* Feature indices, in sorted alphabetical tag order */
DEFINE_RECORD_ARRAY_TYPE (Feature, featureRecord, featureCount); DEFINE_RECORD_ARRAY_TYPE (Feature, featureRecord, featureCount);
private:
USHORT featureCount; /* Number of FeatureRecords in this table */ USHORT featureCount; /* Number of FeatureRecords in this table */
FeatureRecord featureRecord[];/* Array of FeatureRecords--zero-based (first FeatureRecord featureRecord[];/* Array of FeatureRecords--zero-based (first
* feature has FeatureIndex = 0)--listed * feature has FeatureIndex = 0)--listed
* alphabetically by FeatureTag */ * alphabetically by FeatureTag */
}; };
ASSERT_SIZE (FeatureList, 2);
struct Feature { struct Feature {
/* LookupList indices, in no particular order */ /* LookupList indices, in no particular order */
...@@ -401,6 +452,7 @@ struct Feature { ...@@ -401,6 +452,7 @@ struct Feature {
// TODO: implement get_feature_params() // TODO: implement get_feature_params()
private:
Offset featureParams; /* Offset to Feature Parameters table (if one Offset featureParams; /* Offset to Feature Parameters table (if one
* has been defined for the feature), relative * has been defined for the feature), relative
* to the beginning of the Feature Table; = NULL * to the beginning of the Feature Table; = NULL
...@@ -411,16 +463,19 @@ struct Feature { ...@@ -411,16 +463,19 @@ struct Feature {
* feature--zero-based (first lookup is * feature--zero-based (first lookup is
* LookupListIndex = 0) */ * LookupListIndex = 0) */
}; };
ASSERT_SIZE (Feature, 4);
struct LookupList { struct LookupList {
/* Lookup indices, in sorted alphabetical tag order */ /* Lookup indices, in sorted alphabetical tag order */
DEFINE_OFFSET_ARRAY_TYPE (Lookup, lookupOffset, lookupCount); DEFINE_OFFSET_ARRAY_TYPE (Lookup, lookupOffset, lookupCount);
private:
USHORT lookupCount; /* Number of lookups in this table */ USHORT lookupCount; /* Number of lookups in this table */
Offset lookupOffset[]; /* Array of offsets to Lookup tables--from Offset lookupOffset[]; /* Array of offsets to Lookup tables--from
* beginning of LookupList--zero based (first * beginning of LookupList--zero based (first
* lookup is Lookup index = 0) */ * lookup is Lookup index = 0) */
}; };
ASSERT_SIZE (LookupList, 2);
struct LookupFlag : USHORT { struct LookupFlag : USHORT {
static const uint16_t RightToLeft = 0x0001u; static const uint16_t RightToLeft = 0x0001u;
...@@ -430,6 +485,7 @@ struct LookupFlag : USHORT { ...@@ -430,6 +485,7 @@ struct LookupFlag : USHORT {
static const uint16_t Reserved = 0x00F0u; static const uint16_t Reserved = 0x00F0u;
static const uint16_t MarkAttachmentType = 0xFF00u; static const uint16_t MarkAttachmentType = 0xFF00u;
}; };
ASSERT_SIZE (LookupFlag, 2);
struct Lookup { struct Lookup {
/* SubTables, in the desired order */ /* SubTables, in the desired order */
...@@ -441,12 +497,17 @@ struct Lookup { ...@@ -441,12 +497,17 @@ struct Lookup {
inline bool ignore_marks (void) const { return lookupFlag & LookupFlag::IgnoreMarks; } inline bool ignore_marks (void) const { return lookupFlag & LookupFlag::IgnoreMarks; }
inline bool get_mark_attachment_type (void) const { return lookupFlag & LookupFlag::MarkAttachmentType; } inline bool get_mark_attachment_type (void) const { return lookupFlag & LookupFlag::MarkAttachmentType; }
inline uint16_t get_type (void) const { return lookupType; }
inline uint16_t get_flag (void) const { return lookupFlag; }
private:
USHORT lookupType; /* Different enumerations for GSUB and GPOS */ USHORT lookupType; /* Different enumerations for GSUB and GPOS */
USHORT lookupFlag; /* Lookup qualifiers */ USHORT lookupFlag; /* Lookup qualifiers */
USHORT subTableCount; /* Number of SubTables for this lookup */ USHORT subTableCount; /* Number of SubTables for this lookup */
Offset subTableOffset[];/* Array of offsets to SubTables-from Offset subTableOffset[];/* Array of offsets to SubTables-from
* beginning of Lookup table */ * beginning of Lookup table */
}; };
ASSERT_SIZE (Lookup, 6);
/* /*
* Coverage Table * Coverage Table
...@@ -466,10 +527,12 @@ struct CoverageFormat1 { ...@@ -466,10 +527,12 @@ struct CoverageFormat1 {
return -1; return -1;
} }
private:
USHORT coverageFormat; /* Format identifier--format = 1 */ USHORT coverageFormat; /* Format identifier--format = 1 */
USHORT glyphCount; /* Number of glyphs in the GlyphArray */ USHORT glyphCount; /* Number of glyphs in the GlyphArray */
GlyphID glyphArray[]; /* Array of GlyphIDs--in numerical order */ GlyphID glyphArray[]; /* Array of GlyphIDs--in numerical order */
}; };
ASSERT_SIZE (CoverageFormat1, 4);
struct CoverageRangeRecord { struct CoverageRangeRecord {
...@@ -479,11 +542,13 @@ struct CoverageRangeRecord { ...@@ -479,11 +542,13 @@ struct CoverageRangeRecord {
return -1; return -1;
} }
private:
GlyphID start; /* First GlyphID in the range */ GlyphID start; /* First GlyphID in the range */
GlyphID end; /* Last GlyphID in the range */ GlyphID end; /* Last GlyphID in the range */
USHORT startCoverageIndex; /* Coverage Index of first GlyphID in USHORT startCoverageIndex; /* Coverage Index of first GlyphID in
* range */ * range */
}; };
ASSERT_SIZE (CoverageRangeRecord, 6);
struct CoverageFormat2 { struct CoverageFormat2 {
/* CoverageRangeRecords, in sorted numerical start order */ /* CoverageRangeRecords, in sorted numerical start order */
...@@ -499,12 +564,14 @@ struct CoverageFormat2 { ...@@ -499,12 +564,14 @@ struct CoverageFormat2 {
return -1; return -1;
} }
private:
USHORT coverageFormat; /* Format identifier--format = 2 */ USHORT coverageFormat; /* Format identifier--format = 2 */
USHORT rangeCount; /* Number of CoverageRangeRecords */ USHORT rangeCount; /* Number of CoverageRangeRecords */
CoverageRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by CoverageRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by
* Start GlyphID. rangeCount entries * Start GlyphID. rangeCount entries
* long */ * long */
}; };
ASSERT_SIZE (CoverageFormat2, 4);
struct Coverage { struct Coverage {
DEFINE_NON_INSTANTIABLE(Coverage); DEFINE_NON_INSTANTIABLE(Coverage);
...@@ -526,6 +593,7 @@ struct Coverage { ...@@ -526,6 +593,7 @@ struct Coverage {
} }
} }
private:
union { union {
USHORT coverageFormat; /* Format identifier */ USHORT coverageFormat; /* Format identifier */
CoverageFormat1 format1; CoverageFormat1 format1;
...@@ -547,11 +615,13 @@ struct ClassDefFormat1 { ...@@ -547,11 +615,13 @@ struct ClassDefFormat1 {
return 0; return 0;
} }
private:
USHORT classFormat; /* Format identifier--format = 1 */ USHORT classFormat; /* Format identifier--format = 1 */
GlyphID startGlyph; /* First GlyphID of the classValueArray */ GlyphID startGlyph; /* First GlyphID of the classValueArray */
USHORT glyphCount; /* Size of the classValueArray */ USHORT glyphCount; /* Size of the classValueArray */
USHORT classValueArray[]; /* Array of Class Values--one per GlyphID */ USHORT classValueArray[]; /* Array of Class Values--one per GlyphID */
}; };
ASSERT_SIZE (ClassDefFormat1, 6);
struct ClassRangeRecord { struct ClassRangeRecord {
...@@ -561,11 +631,12 @@ struct ClassRangeRecord { ...@@ -561,11 +631,12 @@ struct ClassRangeRecord {
return 0; return 0;
} }
private:
GlyphID start; /* First GlyphID in the range */ GlyphID start; /* First GlyphID in the range */
GlyphID end; /* Last GlyphID in the range */ GlyphID end; /* Last GlyphID in the range */
USHORT classValue; /* Applied to all glyphs in the range USHORT classValue; /* Applied to all glyphs in the range */
*/
}; };
ASSERT_SIZE (ClassRangeRecord, 6);
struct ClassDefFormat2 { struct ClassDefFormat2 {
/* ClassRangeRecords, in sorted numerical start order */ /* ClassRangeRecords, in sorted numerical start order */
...@@ -581,11 +652,13 @@ struct ClassDefFormat2 { ...@@ -581,11 +652,13 @@ struct ClassDefFormat2 {
return 0; return 0;
} }
private:
USHORT classFormat; /* Format identifier--format = 2 */ USHORT classFormat; /* Format identifier--format = 2 */
USHORT rangeCount; /* Number of Number of ClassRangeRecords */ USHORT rangeCount; /* Number of Number of ClassRangeRecords */
ClassRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by ClassRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by
* Start GlyphID */ * Start GlyphID */
}; };
ASSERT_SIZE (ClassDefFormat2, 4);
struct ClassDef { struct ClassDef {
DEFINE_NON_INSTANTIABLE(ClassDef); DEFINE_NON_INSTANTIABLE(ClassDef);
...@@ -607,6 +680,7 @@ struct ClassDef { ...@@ -607,6 +680,7 @@ struct ClassDef {
} }
} }
private:
union { union {
USHORT classFormat; /* Format identifier */ USHORT classFormat; /* Format identifier */
ClassDefFormat1 format1; ClassDefFormat1 format1;
...@@ -651,11 +725,13 @@ struct Device { ...@@ -651,11 +725,13 @@ struct Device {
return 0; return 0;
} }
private:
USHORT startSize; /* Smallest size to correct--in ppem */ USHORT startSize; /* Smallest size to correct--in ppem */
USHORT endSize; /* Largest 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 deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 */
USHORT deltaValue[]; /* Array of compressed data */ USHORT deltaValue[]; /* Array of compressed data */
}; };
ASSERT_SIZE (Device, 6);
...@@ -673,10 +749,17 @@ struct Device { ...@@ -673,10 +749,17 @@ struct Device {
struct GSUBGPOSHeader { struct GSUBGPOSHeader {
/*
inline unsigned int get_size (void) const {
return offsetof (GSUBGPOSHeader, padding);
}
*/
DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list and script(i) */ DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list and script(i) */
DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list and feature(i) */ DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list and feature(i) */
DEFINE_LIST_ACCESSOR(Lookup, lookup); /* get_lookup_list and lookup(i) */ DEFINE_LIST_ACCESSOR(Lookup, lookup); /* get_lookup_list and lookup(i) */
private:
Fixed_Version version; /* Version of the GSUB/GPOS table--initially set Fixed_Version version; /* Version of the GSUB/GPOS table--initially set
* to 0x00010000 */ * to 0x00010000 */
Offset scriptList; /* Offset to ScriptList table--from beginning of Offset scriptList; /* Offset to ScriptList table--from beginning of
...@@ -686,5 +769,6 @@ struct GSUBGPOSHeader { ...@@ -686,5 +769,6 @@ struct GSUBGPOSHeader {
Offset lookupList; /* Offset to LookupList table--from beginning of Offset lookupList; /* Offset to LookupList table--from beginning of
* GSUB/GPOS table */ * GSUB/GPOS table */
}; };
ASSERT_SIZE (GSUBGPOSHeader, 10);
#endif /* HARFBUZZ_OPEN_PRIVATE_H */ #endif /* HARFBUZZ_OPEN_PRIVATE_H */
...@@ -3,4 +3,10 @@ ...@@ -3,4 +3,10 @@
#include <assert.h> #include <assert.h>
#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond))
#define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond))
#define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size))
#endif /* HARFBUZZ_PRIVATE_H */ #endif /* HARFBUZZ_PRIVATE_H */
...@@ -20,7 +20,7 @@ main (int argc, char **argv) ...@@ -20,7 +20,7 @@ main (int argc, char **argv)
const OpenTypeFontFile &ot = OpenTypeFontFile::get (font_data); const OpenTypeFontFile &ot = OpenTypeFontFile::get (font_data);
switch (ot.tag) { switch (ot.get_tag()) {
case OpenTypeFontFile::TrueTypeTag: case OpenTypeFontFile::TrueTypeTag:
printf ("OpenType font with TrueType outlines\n"); printf ("OpenType font with TrueType outlines\n");
break; break;
...@@ -45,10 +45,10 @@ main (int argc, char **argv) ...@@ -45,10 +45,10 @@ main (int argc, char **argv)
printf (" %d table(s) found in font\n", num_tables); printf (" %d table(s) found in font\n", num_tables);
for (int n_table = 0; n_table < num_tables; n_table++) { for (int n_table = 0; n_table < num_tables; n_table++) {
const OpenTypeTable &table = font[n_table]; const OpenTypeTable &table = font[n_table];
printf (" Table %2d of %2d: %.4s (0x%06x+0x%06x)\n", n_table+1, num_tables, printf (" Table %2d of %2d: %.4s (0x%08lx+0x%08lx)\n", n_table+1, num_tables,
(const char *)table.tag, (int)table.offset, (int)table.length); (const char *)table.get_tag(), table.get_offset(), table.get_length());
if (table.tag == "GSUB" || table.tag == "GPOS") { if (table.get_tag() == "GSUB" || table.get_tag() == "GPOS") {
const GSUBGPOSHeader &g = (const GSUBGPOSHeader&)*ot[table]; const GSUBGPOSHeader &g = (const GSUBGPOSHeader&)*ot[table];
const ScriptList &scripts = *g.get_script_list(); const ScriptList &scripts = *g.get_script_list();
...@@ -80,7 +80,7 @@ main (int argc, char **argv) ...@@ -80,7 +80,7 @@ main (int argc, char **argv)
const Feature &feature = features[n_feature]; const Feature &feature = features[n_feature];
printf (" Feature %2d of %2d: %.4s; %d lookup(s)\n", n_feature+1, num_features, printf (" Feature %2d of %2d: %.4s; %d lookup(s)\n", n_feature+1, num_features,
(const char *)features.get_tag(n_feature), (const char *)features.get_tag(n_feature),
(int)feature.lookupCount); feature.get_len());
} }
const LookupList &lookups = *g.get_lookup_list(); const LookupList &lookups = *g.get_lookup_list();
...@@ -89,7 +89,7 @@ main (int argc, char **argv) ...@@ -89,7 +89,7 @@ main (int argc, char **argv)
for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) { for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) {
const Lookup &lookup = lookups[n_lookup]; const Lookup &lookup = lookups[n_lookup];
printf (" Lookup %2d of %2d: type %d, flags %04x\n", n_lookup+1, num_lookups, printf (" Lookup %2d of %2d: type %d, flags %04x\n", n_lookup+1, num_lookups,
(int)lookup.lookupType, (unsigned int)lookup.lookupFlag); lookup.get_type(), lookup.get_flag());
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册