From 5f810363acc3ad3cba631a68620e3d37e54c95c4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 17 May 2009 00:54:25 -0400 Subject: [PATCH] [HB] Add ArrayOf<> --- src/hb-ot-layout-gdef-private.h | 62 ++++++-------------------- src/hb-ot-layout-open-private.h | 77 ++++++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 68 deletions(-) diff --git a/src/hb-ot-layout-gdef-private.h b/src/hb-ot-layout-gdef-private.h index f5de2b85..989c294d 100644 --- a/src/hb-ot-layout-gdef-private.h +++ b/src/hb-ot-layout-gdef-private.h @@ -32,9 +32,9 @@ #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)]; \ } @@ -50,42 +50,23 @@ struct GlyphClassDef : ClassDef { */ 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; /* 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; /* Array of AttachPoint tables + * in Coverage Index order */ }; ASSERT_SIZE (AttachList, 4); @@ -171,18 +152,9 @@ struct LigGlyph { 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 + caret; /* Array of CaretValue tables + * in increasing coordinate order */ }; ASSERT_SIZE (LigGlyph, 2); @@ -192,21 +164,15 @@ struct LigCaretList { 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; /* 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; /* Array of LigGlyph tables + * in Coverage Index order */ }; ASSERT_SIZE (LigCaretList, 4); diff --git a/src/hb-ot-layout-open-private.h b/src/hb-ot-layout-open-private.h index f68e59f1..e11bb905 100644 --- a/src/hb-ot-layout-open-private.h +++ b/src/hb-ot-layout-open-private.h @@ -40,26 +40,6 @@ #define MAX_NESTING_LEVEL 32 -/* - * 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 */ @@ -254,6 +234,26 @@ struct Null { \ /* "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. */ @@ -371,6 +371,43 @@ struct Fixed_Version : Fixed { }; ASSERT_SIZE (Fixed_Version, 4); +/* + * Array Types + */ + +/* An array with a USHORT number of elements. */ +template +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 Array; + +/* Array of Offset's */ +template +struct OffsetArrayOf : ArrayOf > { +}; + +/* 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 -- GitLab