bungeman@google.com | f8d1aee | 2012-02-02 19:15:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkOTTableTypes_DEFINED |
| 9 | #define SkOTTableTypes_DEFINED |
| 10 | |
| 11 | #include "SkTypes.h" |
| 12 | #include "SkEndian.h" |
| 13 | |
| 14 | //All SK_OT_ prefixed types should be considered as big endian. |
| 15 | typedef uint8_t SK_OT_BYTE; |
| 16 | #if CHAR_BIT == 8 |
| 17 | typedef signed char SK_OT_CHAR; //easier to debug |
| 18 | #else |
| 19 | typedef int8_t SK_OT_CHAR; |
| 20 | #endif |
bungeman@google.com | a544f29 | 2012-11-20 18:52:23 +0000 | [diff] [blame] | 21 | typedef uint16_t SK_OT_SHORT; |
bungeman@google.com | f8d1aee | 2012-02-02 19:15:21 +0000 | [diff] [blame] | 22 | typedef uint16_t SK_OT_USHORT; |
| 23 | typedef uint32_t SK_OT_ULONG; |
bungeman@google.com | a544f29 | 2012-11-20 18:52:23 +0000 | [diff] [blame] | 24 | typedef uint32_t SK_OT_LONG; |
| 25 | //16.16 Signed fixed point representation. |
bungeman@google.com | f8d1aee | 2012-02-02 19:15:21 +0000 | [diff] [blame] | 26 | typedef int32_t SK_OT_Fixed; |
bungeman@google.com | a544f29 | 2012-11-20 18:52:23 +0000 | [diff] [blame] | 27 | //2.14 Signed fixed point representation. |
| 28 | typedef uint16_t SK_OT_F2DOT14; |
bungeman@google.com | f8d1aee | 2012-02-02 19:15:21 +0000 | [diff] [blame] | 29 | //F units are the units of measurement in em space. |
bungeman@google.com | a544f29 | 2012-11-20 18:52:23 +0000 | [diff] [blame] | 30 | typedef uint16_t SK_OT_FWORD; |
bungeman@google.com | f8d1aee | 2012-02-02 19:15:21 +0000 | [diff] [blame] | 31 | typedef uint16_t SK_OT_UFWORD; |
| 32 | //Number of seconds since 12:00 midnight, January 1, 1904. |
| 33 | typedef uint64_t SK_OT_LONGDATETIME; |
| 34 | |
| 35 | #define SK_OT_BYTE_BITFIELD SK_UINT8_BITFIELD |
| 36 | |
bungeman@google.com | ec95a4a | 2012-06-25 14:26:48 +0000 | [diff] [blame] | 37 | template<typename T> class SkOTTableTAG { |
| 38 | public: |
| 39 | /** |
| 40 | * SkOTTableTAG<T>::value is the big endian value of an OpenType table tag. |
| 41 | * It may be directly compared with raw big endian table data. |
| 42 | */ |
| 43 | static const SK_OT_ULONG value = SkTEndian_SwapBE32( |
| 44 | SkSetFourByteTag(T::TAG0, T::TAG1, T::TAG2, T::TAG3) |
| 45 | ); |
| 46 | }; |
| 47 | |
bungeman@google.com | 562b2e6 | 2014-03-12 21:41:06 +0000 | [diff] [blame] | 48 | /** SkOTSetUSHORTBit<N>::value is an SK_OT_USHORT with the Nth BE bit set. */ |
| 49 | template <unsigned N> struct SkOTSetUSHORTBit { |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 50 | static_assert(N < 16, "NTooBig"); |
commit-bot@chromium.org | d48ad8e | 2014-04-01 16:11:53 +0000 | [diff] [blame] | 51 | static const uint16_t bit = 1u << N; |
bungeman@google.com | 562b2e6 | 2014-03-12 21:41:06 +0000 | [diff] [blame] | 52 | static const SK_OT_USHORT value = SkTEndian_SwapBE16(bit); |
| 53 | }; |
| 54 | |
commit-bot@chromium.org | d48ad8e | 2014-04-01 16:11:53 +0000 | [diff] [blame] | 55 | /** SkOTSetULONGBit<N>::value is an SK_OT_ULONG with the Nth BE bit set. */ |
bungeman@google.com | 562b2e6 | 2014-03-12 21:41:06 +0000 | [diff] [blame] | 56 | template <unsigned N> struct SkOTSetULONGBit { |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame] | 57 | static_assert(N < 32, "NTooBig"); |
commit-bot@chromium.org | d48ad8e | 2014-04-01 16:11:53 +0000 | [diff] [blame] | 58 | static const uint32_t bit = 1u << N; |
bungeman@google.com | 562b2e6 | 2014-03-12 21:41:06 +0000 | [diff] [blame] | 59 | static const SK_OT_ULONG value = SkTEndian_SwapBE32(bit); |
| 60 | }; |
| 61 | |
bungeman@google.com | f8d1aee | 2012-02-02 19:15:21 +0000 | [diff] [blame] | 62 | #endif |