SkSFNTHeader.h 2.2 KB

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