1 // [Blend2D]
2 // 2D Vector Graphics Powered by a JIT Compiler.
3 //
4 // [License]
5 // Zlib - See LICENSE.md file in the package.
6 
7 #ifndef BLEND2D_OPENTYPE_OTNAME_P_H
8 #define BLEND2D_OPENTYPE_OTNAME_P_H
9 
10 #include "../opentype/otdefs_p.h"
11 
12 //! \cond INTERNAL
13 //! \addtogroup blend2d_internal_opentype
14 //! \{
15 
16 namespace BLOpenType {
17 
18 // ============================================================================
19 // [BLOpenType::NameTable]
20 // ============================================================================
21 
22 //! OpenType 'name' table.
23 //!
24 //! External Resources:
25 //!   - https://docs.microsoft.com/en-us/typography/opentype/spec/name
26 //!   - https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
27 struct NameTable {
28   enum : uint32_t { kMinSize = 6 };
29 
30   struct NameRecord {
31     UInt16 platformId;
32     UInt16 specificId;
33     UInt16 languageId;
34     UInt16 nameId;
35     UInt16 length;
36     Offset16 offset;
37   };
38 
39   struct LangTagRecord {
40     UInt16 length;
41     Offset16 offset;
42   };
43 
44   UInt16 format;
45   UInt16 recordCount;
46   Offset16 stringOffset;
47   /*
48   NameRecord nameRecords[count];
49   UInt16 langTagCount;
50   LangTagRecord langTagRecords[langTagCount];
51   */
52 
hasLangTagsNameTable53   BL_INLINE bool hasLangTags() const noexcept { return format() >= 1; }
54 
55   //! The name records where count is the number of records.
nameRecordsNameTable56   BL_INLINE const NameRecord* nameRecords() const noexcept {
57     return blOffsetPtr<const NameRecord>(this, 6);
58   }
59 
langTagCountNameTable60   BL_INLINE uint16_t langTagCount(size_t recordCount_) const noexcept {
61     return blOffsetPtr<const UInt16>(this, 6 + recordCount_ * sizeof(NameRecord))->value();
62   }
63 
langTagRecordsNameTable64   BL_INLINE const LangTagRecord* langTagRecords(size_t recordCount_) const noexcept {
65     return blOffsetPtr<const LangTagRecord>(this, 6 + recordCount_ * sizeof(NameRecord) + 2);
66   }
67 };
68 
69 // ============================================================================
70 // [BLOpenType::NameImpl]
71 // ============================================================================
72 
73 namespace NameImpl {
74   BL_HIDDEN BLResult init(BLOTFaceImpl* faceI, const BLFontData* fontData) noexcept;
75 } // {NameImpl}
76 
77 } // {BLOpenType}
78 
79 //! \}
80 //! \endcond
81 
82 #endif // BLEND2D_OPENTYPE_OTNAME_P_H
83