#include "hb-ot-layout-open-private.h"
-#define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, name) \
+#define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, array, name) \
inline const Type& name (hb_codepoint_t glyph) { \
- return (*this)[(this+coverage)(glyph)]; \
+ return this+array[(this+coverage)(glyph)]; \
}
*/
struct AttachPoint {
-
- friend struct AttachList;
-
- private:
- /* countour point indices, in increasing numerical order */
- DEFINE_ARRAY_TYPE (USHORT, pointIndex, pointCount);
-
- private:
- USHORT pointCount; /* Number of attachment points on
- * this glyph */
- USHORT pointIndex[]; /* Array of contour point indices--in
+ Array pointIndex; /* Array of contour point indices--in
* increasing numerical order */
};
ASSERT_SIZE (AttachPoint, 2);
struct AttachList {
- friend struct GDEF;
-
- private:
/* const AttachPoint& get_attach_points (hb_codepoint_t glyph); */
- DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, get_attach_points);
-
- private:
- /* AttachPoint tables, in Coverage Index order */
- DEFINE_OFFSET_ARRAY_TYPE (AttachPoint, attachPoint, glyphCount);
+ DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, attachPoint, get_attach_points);
private:
OffsetTo<Coverage>
coverage; /* Offset to Coverage table -- from
* beginning of AttachList table */
- USHORT glyphCount; /* Number of glyphs with attachment
- * points */
- Offset attachPoint[]; /* Array of offsets to AttachPoint
- * tables--from beginning of AttachList
- * table--in Coverage Index order */
+ OffsetArrayOf<AttachPoint>
+ attachPoint; /* Array of AttachPoint tables
+ * in Coverage Index order */
};
ASSERT_SIZE (AttachList, 4);
friend struct LigCaretList;
- private:
- /* Caret value tables, in increasing coordinate order */
- DEFINE_OFFSET_ARRAY_TYPE (CaretValue, caretValue, caretCount);
- /* TODO */
-
- private:
- USHORT caretCount; /* Number of CaretValues for this
- * ligature (components - 1) */
- Offset caretValue[]; /* Array of offsets to CaretValue
- * tables--from beginning of LigGlyph
- * table--in increasing coordinate
- * order */
+ OffsetArrayOf<CaretValue>
+ caret; /* Array of CaretValue tables
+ * in increasing coordinate order */
};
ASSERT_SIZE (LigGlyph, 2);
private:
/* const LigGlyph& get_lig_glyph (hb_codepoint_t glyph); */
- DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (LigGlyph, get_lig_glyph);
-
- private:
- /* LigGlyph tables, in Coverage Index order */
- DEFINE_OFFSET_ARRAY_TYPE (LigGlyph, ligGlyph, ligGlyphCount);
+ DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (LigGlyph, ligGlyph, get_lig_glyph);
private:
OffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of LigCaretList table */
- USHORT ligGlyphCount; /* Number of ligature glyphs */
- Offset ligGlyph[]; /* Array of offsets to LigGlyph
- * tables--from beginning of
- * LigCaretList table--in Coverage
- * Index order */
+ OffsetArrayOf<LigGlyph>
+ ligGlyph; /* Array of LigGlyph tables
+ * in Coverage Index order */
};
ASSERT_SIZE (LigCaretList, 4);
/*
- * Int types
- */
-
-/* XXX define these as structs of chars on machines that do not allow
- * unaligned access (using templates?). */
-#define DEFINE_INT_TYPE1(NAME, TYPE, BIG_ENDIAN) \
- inline NAME& operator = (TYPE i) { v = BIG_ENDIAN(i); return *this; } \
- inline operator TYPE(void) const { return BIG_ENDIAN(v); } \
- inline bool operator== (NAME o) const { return v == o.v; } \
- private: TYPE v; \
- public:
-#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_STRUCT(NAME, u, w) \
- struct NAME { \
- DEFINE_INT_TYPE(NAME, u, w) \
- }; \
- ASSERT_SIZE (NAME, w / 8)
-
-/*
* Array types
*/
/* "The following data types are used in the OpenType font file.
* All OpenType fonts use Motorola-style byte ordering (Big Endian):" */
+/*
+ * Int types
+ */
+
+/* XXX define these as structs of chars on machines that do not allow
+ * unaligned access (using templates?). */
+#define DEFINE_INT_TYPE1(NAME, TYPE, BIG_ENDIAN) \
+ inline NAME& operator = (TYPE i) { v = BIG_ENDIAN(i); return *this; } \
+ inline operator TYPE(void) const { return BIG_ENDIAN(v); } \
+ inline bool operator== (NAME o) const { return v == o.v; } \
+ private: TYPE v; \
+ public:
+#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_STRUCT(NAME, u, w) \
+ struct NAME { \
+ DEFINE_INT_TYPE(NAME, u, w) \
+ }; \
+ ASSERT_SIZE (NAME, w / 8)
+
DEFINE_INT_TYPE_STRUCT (BYTE, u, 8); /* 8-bit unsigned integer. */
DEFINE_INT_TYPE_STRUCT (CHAR, , 8); /* 8-bit signed integer. */
};
ASSERT_SIZE (Fixed_Version, 4);
+/*
+ * Array Types
+ */
+
+/* An array with a USHORT number of elements. */
+template <typename Type>
+struct ArrayOf {
+ inline const Type& operator [] (unsigned int i) const {
+ if (HB_UNLIKELY (i >= len)) return Null(Type);
+ return array[i];
+ }
+
+ USHORT len;
+ private:
+ Type array[];
+};
+
+/* Array of USHORT's */
+typedef ArrayOf<USHORT> Array;
+
+/* Array of Offset's */
+template <typename Type>
+struct OffsetArrayOf : ArrayOf<OffsetTo<Type> > {
+};
+
+/* An array type is one that contains a variable number of objects
+ * as its last item. An array object is extended with get_len()
+ * methods, as well as overloaded [] operator. */
+#define DEFINE_ARRAY_TYPE(Type, array, num) \
+ DEFINE_INDEX_OPERATOR(Type, array, num) \
+ DEFINE_LEN(Type, array, num)
+#define DEFINE_INDEX_OPERATOR(Type, array, num) \
+ inline const Type& operator[] (unsigned int i) const { \
+ if (HB_UNLIKELY (i >= num)) return Null(Type); \
+ return array[i]; \
+ }
+
/*
* Organization of an OpenType Font