bungeman@google.com | 8ec9956 | 2012-02-07 21:30: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 SkSFNTHeader_DEFINED |
| 9 | #define SkSFNTHeader_DEFINED |
| 10 | |
| 11 | #include "SkEndian.h" |
bungeman@google.com | a550199 | 2012-05-18 19:06:41 +0000 | [diff] [blame] | 12 | #include "SkOTTableTypes.h" |
bungeman@google.com | 8ec9956 | 2012-02-07 21:30:21 +0000 | [diff] [blame] | 13 | |
| 14 | //All SK_SFNT_ prefixed types should be considered as big endian. |
| 15 | typedef uint16_t SK_SFNT_USHORT; |
| 16 | typedef uint32_t SK_SFNT_ULONG; |
| 17 | |
| 18 | #pragma pack(push, 1) |
| 19 | |
| 20 | struct SkSFNTHeader { |
| 21 | SK_SFNT_ULONG fontType; |
bungeman@google.com | ec95a4a | 2012-06-25 14:26:48 +0000 | [diff] [blame] | 22 | struct fontType_WindowsTrueType { |
| 23 | static const SK_OT_CHAR TAG0 = 0; |
| 24 | static const SK_OT_CHAR TAG1 = 1; |
| 25 | static const SK_OT_CHAR TAG2 = 0; |
| 26 | static const SK_OT_CHAR TAG3 = 0; |
| 27 | static const SK_OT_ULONG TAG = SkOTTableTAG<fontType_WindowsTrueType>::value; |
| 28 | }; |
| 29 | struct fontType_MacTrueType { |
| 30 | static const SK_OT_CHAR TAG0 = 't'; |
| 31 | static const SK_OT_CHAR TAG1 = 'r'; |
| 32 | static const SK_OT_CHAR TAG2 = 'u'; |
| 33 | static const SK_OT_CHAR TAG3 = 'e'; |
| 34 | static const SK_OT_ULONG TAG = SkOTTableTAG<fontType_MacTrueType>::value; |
| 35 | }; |
| 36 | struct fontType_PostScript { |
| 37 | static const SK_OT_CHAR TAG0 = 't'; |
| 38 | static const SK_OT_CHAR TAG1 = 'y'; |
| 39 | static const SK_OT_CHAR TAG2 = 'p'; |
| 40 | static const SK_OT_CHAR TAG3 = '1'; |
| 41 | static const SK_OT_ULONG TAG = SkOTTableTAG<fontType_PostScript>::value; |
| 42 | }; |
| 43 | struct fontType_OpenTypeCFF { |
| 44 | static const SK_OT_CHAR TAG0 = 'O'; |
| 45 | static const SK_OT_CHAR TAG1 = 'T'; |
| 46 | static const SK_OT_CHAR TAG2 = 'T'; |
| 47 | static const SK_OT_CHAR TAG3 = 'O'; |
| 48 | static const SK_OT_ULONG TAG = SkOTTableTAG<fontType_OpenTypeCFF>::value; |
| 49 | }; |
bungeman@google.com | 8ec9956 | 2012-02-07 21:30:21 +0000 | [diff] [blame] | 50 | |
| 51 | SK_SFNT_USHORT numTables; |
| 52 | SK_SFNT_USHORT searchRange; |
| 53 | SK_SFNT_USHORT entrySelector; |
| 54 | SK_SFNT_USHORT rangeShift; |
bungeman@google.com | a544f29 | 2012-11-20 18:52:23 +0000 | [diff] [blame^] | 55 | |
| 56 | struct TableDirectoryEntry { |
| 57 | SK_SFNT_ULONG tag; |
| 58 | SK_SFNT_ULONG checksum; |
| 59 | SK_SFNT_ULONG offset; //From beginning of header. |
| 60 | SK_SFNT_ULONG logicalLength; |
| 61 | }; //tableDirectoryEntries[numTables] |
bungeman@google.com | 8ec9956 | 2012-02-07 21:30:21 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | #pragma pack(pop) |
| 65 | |
| 66 | |
| 67 | SK_COMPILE_ASSERT(sizeof(SkSFNTHeader) == 12, sizeof_SkSFNTHeader_not_12); |
bungeman@google.com | a544f29 | 2012-11-20 18:52:23 +0000 | [diff] [blame^] | 68 | SK_COMPILE_ASSERT(sizeof(SkSFNTHeader::TableDirectoryEntry) == 16, sizeof_SkSFNTHeader_TableDirectoryEntry_not_16); |
bungeman@google.com | 8ec9956 | 2012-02-07 21:30:21 +0000 | [diff] [blame] | 69 | |
| 70 | #endif |