blob: 119f17ef77c96a82dc9ef82aed8aa5a7296ffa49 [file] [log] [blame]
bungeman@google.comf8d1aee2012-02-02 19:15:21 +00001/*
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.
15typedef uint8_t SK_OT_BYTE;
16#if CHAR_BIT == 8
17typedef signed char SK_OT_CHAR; //easier to debug
18#else
19typedef int8_t SK_OT_CHAR;
20#endif
bungeman@google.coma544f292012-11-20 18:52:23 +000021typedef uint16_t SK_OT_SHORT;
bungeman@google.comf8d1aee2012-02-02 19:15:21 +000022typedef uint16_t SK_OT_USHORT;
23typedef uint32_t SK_OT_ULONG;
bungeman@google.coma544f292012-11-20 18:52:23 +000024typedef uint32_t SK_OT_LONG;
25//16.16 Signed fixed point representation.
bungeman@google.comf8d1aee2012-02-02 19:15:21 +000026typedef int32_t SK_OT_Fixed;
bungeman@google.coma544f292012-11-20 18:52:23 +000027//2.14 Signed fixed point representation.
28typedef uint16_t SK_OT_F2DOT14;
bungeman@google.comf8d1aee2012-02-02 19:15:21 +000029//F units are the units of measurement in em space.
bungeman@google.coma544f292012-11-20 18:52:23 +000030typedef uint16_t SK_OT_FWORD;
bungeman@google.comf8d1aee2012-02-02 19:15:21 +000031typedef uint16_t SK_OT_UFWORD;
32//Number of seconds since 12:00 midnight, January 1, 1904.
33typedef uint64_t SK_OT_LONGDATETIME;
34
35#define SK_OT_BYTE_BITFIELD SK_UINT8_BITFIELD
36
bungeman@google.comec95a4a2012-06-25 14:26:48 +000037template<typename T> class SkOTTableTAG {
38public:
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.com562b2e62014-03-12 21:41:06 +000048/** SkOTSetUSHORTBit<N>::value is an SK_OT_USHORT with the Nth BE bit set. */
49template <unsigned N> struct SkOTSetUSHORTBit {
bungeman99fe8222015-08-20 07:57:51 -070050 static_assert(N < 16, "NTooBig");
commit-bot@chromium.orgd48ad8e2014-04-01 16:11:53 +000051 static const uint16_t bit = 1u << N;
bungeman@google.com562b2e62014-03-12 21:41:06 +000052 static const SK_OT_USHORT value = SkTEndian_SwapBE16(bit);
53};
54
commit-bot@chromium.orgd48ad8e2014-04-01 16:11:53 +000055/** SkOTSetULONGBit<N>::value is an SK_OT_ULONG with the Nth BE bit set. */
bungeman@google.com562b2e62014-03-12 21:41:06 +000056template <unsigned N> struct SkOTSetULONGBit {
bungeman99fe8222015-08-20 07:57:51 -070057 static_assert(N < 32, "NTooBig");
commit-bot@chromium.orgd48ad8e2014-04-01 16:11:53 +000058 static const uint32_t bit = 1u << N;
bungeman@google.com562b2e62014-03-12 21:41:06 +000059 static const SK_OT_ULONG value = SkTEndian_SwapBE32(bit);
60};
61
bungeman@google.comf8d1aee2012-02-02 19:15:21 +000062#endif