SkOTTableTypes.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef SkOTTableTypes_DEFINED
  8. #define SkOTTableTypes_DEFINED
  9. #include "include/core/SkTypes.h"
  10. #include "src/core/SkEndian.h"
  11. //All SK_OT_ prefixed types should be considered as big endian.
  12. typedef uint8_t SK_OT_BYTE;
  13. #if CHAR_BIT == 8
  14. typedef signed char SK_OT_CHAR; //easier to debug
  15. #else
  16. typedef int8_t SK_OT_CHAR;
  17. #endif
  18. typedef uint16_t SK_OT_SHORT;
  19. typedef uint16_t SK_OT_USHORT;
  20. typedef uint32_t SK_OT_ULONG;
  21. typedef uint32_t SK_OT_LONG;
  22. //16.16 Signed fixed point representation.
  23. typedef int32_t SK_OT_Fixed;
  24. //2.14 Signed fixed point representation.
  25. typedef uint16_t SK_OT_F2DOT14;
  26. //F units are the units of measurement in em space.
  27. typedef uint16_t SK_OT_FWORD;
  28. typedef uint16_t SK_OT_UFWORD;
  29. //Number of seconds since 12:00 midnight, January 1, 1904.
  30. typedef uint64_t SK_OT_LONGDATETIME;
  31. #define SK_OT_BYTE_BITFIELD SK_UINT8_BITFIELD
  32. template<typename T> class SkOTTableTAG {
  33. public:
  34. /**
  35. * SkOTTableTAG<T>::value is the big endian value of an OpenType table tag.
  36. * It may be directly compared with raw big endian table data.
  37. */
  38. static const SK_OT_ULONG value = SkTEndian_SwapBE32(
  39. SkSetFourByteTag(T::TAG0, T::TAG1, T::TAG2, T::TAG3)
  40. );
  41. };
  42. /** SkOTSetUSHORTBit<N>::value is an SK_OT_USHORT with the Nth BE bit set. */
  43. template <unsigned N> struct SkOTSetUSHORTBit {
  44. static_assert(N < 16, "NTooBig");
  45. static const uint16_t bit = 1u << N;
  46. static const SK_OT_USHORT value = SkTEndian_SwapBE16(bit);
  47. };
  48. /** SkOTSetULONGBit<N>::value is an SK_OT_ULONG with the Nth BE bit set. */
  49. template <unsigned N> struct SkOTSetULONGBit {
  50. static_assert(N < 32, "NTooBig");
  51. static const uint32_t bit = 1u << N;
  52. static const SK_OT_ULONG value = SkTEndian_SwapBE32(bit);
  53. };
  54. #endif