From bd61bc13ea8ff350ada5449b2cfeb612e66ecafa Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Dec 2012 16:00:43 -0500 Subject: [PATCH] [OTLayout] Add UINT24 type --- src/hb-open-type-private.hh | 33 ++++++++++++++++++++++----------- src/hb-private.hh | 4 ++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index e57558e..347e299 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -534,32 +534,43 @@ struct BEInt inline bool operator != (const BEInt& o) const { return !(*this == o); } private: uint8_t v[4]; }; +template +struct BEInt +{ + public: + inline void set (Type i) { hb_be_uint24_put (v,i); } + inline operator Type (void) const { return hb_be_uint24_get (v); } + inline bool operator == (const BEInt& o) const { return hb_be_uint24_eq (v, o.v); } + inline bool operator != (const BEInt& o) const { return !(*this == o); } + private: uint8_t v[3]; +}; /* Integer types in big-endian order and no alignment requirement */ -template +template struct IntType { inline void set (Type i) { v.set (i); } inline operator Type(void) const { return v; } - inline bool operator == (const IntType &o) const { return v == o.v; } - inline bool operator != (const IntType &o) const { return v != o.v; } - static inline int cmp (const IntType *a, const IntType *b) { return b->cmp (*a); } - inline int cmp (IntType va) const { Type a = va; Type b = v; return a < b ? -1 : a == b ? 0 : +1; } + inline bool operator == (const IntType &o) const { return v == o.v; } + inline bool operator != (const IntType &o) const { return v != o.v; } + static inline int cmp (const IntType *a, const IntType *b) { return b->cmp (*a); } + inline int cmp (IntType va) const { Type a = va; Type b = v; return a < b ? -1 : a == b ? 0 : +1; } inline int cmp (Type a) const { Type b = v; return a < b ? -1 : a == b ? 0 : +1; } inline bool sanitize (hb_sanitize_context_t *c) { TRACE_SANITIZE (this); return TRACE_RETURN (likely (c->check_struct (this))); } protected: - BEInt v; + BEInt v; public: - DEFINE_SIZE_STATIC (sizeof (Type)); + DEFINE_SIZE_STATIC (Size); }; -typedef IntType USHORT; /* 16-bit unsigned integer. */ -typedef IntType SHORT; /* 16-bit signed integer. */ -typedef IntType ULONG; /* 32-bit unsigned integer. */ -typedef IntType LONG; /* 32-bit signed integer. */ +typedef IntType USHORT; /* 16-bit unsigned integer. */ +typedef IntType SHORT; /* 16-bit signed integer. */ +typedef IntType ULONG; /* 32-bit unsigned integer. */ +typedef IntType LONG; /* 32-bit signed integer. */ +typedef IntType UINT24; /* 24-bit unsigned integer. */ /* 16-bit signed integer (SHORT) that describes a quantity in FUnits. */ typedef SHORT FWORD; diff --git a/src/hb-private.hh b/src/hb-private.hh index 3a62c67..be0d505 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -509,6 +509,10 @@ static inline uint32_t hb_uint32_swap (const uint32_t v) #define hb_be_uint32_get(v) (uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2] << 8) + v[3]) #define hb_be_uint32_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3]) +#define hb_be_uint24_put(v,V) HB_STMT_START { v[0] = (V>>16); v[1] = (V>>8); v[2] (V); } HB_STMT_END +#define hb_be_uint24_get(v) (uint32_t) ((v[0] << 16) + (v[1] << 8) + v[2]) +#define hb_be_uint24_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) + /* ASCII tag/character handling */ -- 2.7.4