/*
- * Copyright (C) 2007,2008,2009 Red Hat, Inc.
+ * Copyright © 2007,2008,2009 Red Hat, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
#include "hb-open-type-private.hh"
+HB_BEGIN_DECLS
+
/*
*
struct OffsetTable;
struct TTCHeader;
-typedef struct TableDirectory
-{
- static inline unsigned int get_size () { return sizeof (TableDirectory); }
- inline bool sanitize (SANITIZE_ARG_DEF) {
+typedef struct TableRecord
+{
+ inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
- return SANITIZE_SELF ();
+ return c->check_struct (this);
}
Tag tag; /* 4-byte identifier. */
ULONG offset; /* Offset from beginning of TrueType font
* file. */
ULONG length; /* Length of this table. */
+ public:
+ DEFINE_SIZE_STATIC (16);
} OpenTypeTable;
-ASSERT_SIZE (TableDirectory, 16);
typedef struct OffsetTable
{
inline unsigned int get_table_count (void) const
{ return numTables; }
- inline const TableDirectory& get_table (unsigned int i) const
+ inline const TableRecord& get_table (unsigned int i) const
{
- if (unlikely (i >= numTables)) return Null(TableDirectory);
- return tableDir[i];
+ if (unlikely (i >= numTables)) return Null(TableRecord);
+ return tables[i];
}
inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
{
Tag t;
t.set (tag);
- /* TODO: bsearch (need to sort in sanitize) */
unsigned int count = numTables;
for (unsigned int i = 0; i < count; i++)
{
- if (t == tableDir[i].tag)
+ if (t == tables[i].tag)
{
if (table_index) *table_index = i;
return true;
}
}
- if (table_index) *table_index = NO_INDEX;
+ if (table_index) *table_index = Index::NOT_FOUND_INDEX;
return false;
}
- inline const TableDirectory& get_table_by_tag (hb_tag_t tag) const
+ inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
{
unsigned int table_index;
find_table_index (tag, &table_index);
}
public:
- inline bool sanitize (SANITIZE_ARG_DEF) {
+ inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
- return SANITIZE_SELF () && SANITIZE_ARRAY (tableDir, TableDirectory::get_size (), numTables);
+ return c->check_struct (this)
+ && c->check_array (tables, TableRecord::static_size, numTables);
}
private:
USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */
USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */
USHORT rangeShift; /* NumTables x 16-searchRange. */
- TableDirectory tableDir[VAR]; /* TableDirectory entries. numTables items */
+ TableRecord tables[VAR]; /* TableRecord entries. numTables items */
+ public:
+ DEFINE_SIZE_ARRAY (12, tables);
} OpenTypeFontFace;
-ASSERT_SIZE_VAR (OffsetTable, 12, TableDirectory);
+
/*
* TrueType Collections
inline unsigned int get_face_count (void) const { return table.len; }
inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
- inline bool sanitize (SANITIZE_ARG_DEF) {
+ inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
- return SANITIZE_THIS (table);
+ return table.sanitize (c, this);
}
private:
LongOffsetLongArrayOf<OffsetTable>
table; /* Array of offsets to the OffsetTable for each font
* from the beginning of the file */
+ public:
+ DEFINE_SIZE_ARRAY (12, table);
};
-ASSERT_SIZE (TTCHeaderVersion1, 12);
struct TTCHeader
{
inline unsigned int get_face_count (void) const
{
- switch (u.header.version) {
+ switch (u.header.version.major) {
case 2: /* version 2 is compatible with version 1 */
- case 1: return u.version1->get_face_count ();
+ case 1: return u.version1.get_face_count ();
default:return 0;
}
}
inline const OpenTypeFontFace& get_face (unsigned int i) const
{
- switch (u.header.version) {
+ switch (u.header.version.major) {
case 2: /* version 2 is compatible with version 1 */
- case 1: return u.version1->get_face (i);
+ case 1: return u.version1.get_face (i);
default:return Null(OpenTypeFontFace);
}
}
- inline bool sanitize (SANITIZE_ARG_DEF) {
+ inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
- if (!SANITIZE (u.header.version)) return false;
- switch (u.header.version) {
+ if (unlikely (!u.header.version.sanitize (c))) return false;
+ switch (u.header.version.major) {
case 2: /* version 2 is compatible with version 1 */
- case 1: return u.version1->sanitize (SANITIZE_ARG);
+ case 1: return u.version1.sanitize (c);
default:return true;
}
}
FixedVersion version; /* Version of the TTC Header (1.0 or 2.0),
* 0x00010000 or 0x00020000 */
} header;
- TTCHeaderVersion1 version1[VAR];
+ TTCHeaderVersion1 version1;
} u;
};
static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O'); /* OpenType with Postscript outlines */
static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ); /* OpenType with TrueType outlines */
static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f'); /* TrueType Collection */
- static const hb_tag_t TrueTag = HB_TAG ('t','r','u','e'); /* Apple obsolete tag */
- static const hb_tag_t Typ1Tag = HB_TAG ('t','y','p','1'); /* Apple obsolete tag */
+ static const hb_tag_t TrueTag = HB_TAG ('t','r','u','e'); /* Obsolete Apple TrueType */
+ static const hb_tag_t Typ1Tag = HB_TAG ('t','y','p','1'); /* Obsolete Apple Type1 font in SFNT container */
inline hb_tag_t get_tag (void) const { return u.tag; }
case TrueTag:
case Typ1Tag:
case TrueTypeTag: return 1;
- case TTCTag: return u.ttcHeader->get_face_count ();
+ case TTCTag: return u.ttcHeader.get_face_count ();
default: return 0;
}
}
case CFFTag: /* All the non-collection tags */
case TrueTag:
case Typ1Tag:
- case TrueTypeTag: return u.fontFace[0];
- case TTCTag: return u.ttcHeader->get_face (i);
+ case TrueTypeTag: return u.fontFace;
+ case TTCTag: return u.ttcHeader.get_face (i);
default: return Null(OpenTypeFontFace);
}
}
- inline bool sanitize (SANITIZE_ARG_DEF) {
+ inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
- if (!SANITIZE (u.tag)) return false;
+ if (unlikely (!u.tag.sanitize (c))) return false;
switch (u.tag) {
case CFFTag: /* All the non-collection tags */
case TrueTag:
case Typ1Tag:
- case TrueTypeTag: return u.fontFace->sanitize (SANITIZE_ARG);
- case TTCTag: return u.ttcHeader->sanitize (SANITIZE_ARG);
+ case TrueTypeTag: return u.fontFace.sanitize (c);
+ case TTCTag: return u.ttcHeader.sanitize (c);
default: return true;
}
}
private:
union {
Tag tag; /* 4-byte identifier. */
- OpenTypeFontFace fontFace[VAR];
- TTCHeader ttcHeader[VAR];
+ OpenTypeFontFace fontFace;
+ TTCHeader ttcHeader;
} u;
+ public:
+ DEFINE_SIZE_UNION (4, tag);
};
+HB_END_DECLS
+
#endif /* HB_OPEN_FILE_PRIVATE_HH */