name.h (1610B)
1 // Copyright (c) 2011-2017 The OTS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef OTS_NAME_H_ 6 #define OTS_NAME_H_ 7 8 #include <new> 9 #include <string> 10 #include <utility> 11 #include <vector> 12 #include <unordered_set> 13 14 #include "ots.h" 15 16 namespace ots { 17 18 struct NameRecord { 19 NameRecord() { 20 } 21 22 NameRecord(uint16_t platformID, uint16_t encodingID, 23 uint16_t languageID, uint16_t nameID) 24 : platform_id(platformID), 25 encoding_id(encodingID), 26 language_id(languageID), 27 name_id(nameID) { 28 } 29 30 uint16_t platform_id; 31 uint16_t encoding_id; 32 uint16_t language_id; 33 uint16_t name_id; 34 std::string text; 35 36 bool operator<(const NameRecord& rhs) const { 37 if (platform_id < rhs.platform_id) return true; 38 if (platform_id > rhs.platform_id) return false; 39 if (encoding_id < rhs.encoding_id) return true; 40 if (encoding_id > rhs.encoding_id) return false; 41 if (language_id < rhs.language_id) return true; 42 if (language_id > rhs.language_id) return false; 43 return name_id < rhs.name_id; 44 } 45 }; 46 47 class OpenTypeNAME : public Table { 48 public: 49 explicit OpenTypeNAME(Font *font, uint32_t tag) 50 : Table(font, tag, tag) { } 51 52 bool Parse(const uint8_t *data, size_t length); 53 bool Serialize(OTSStream *out); 54 bool IsValidNameId(uint16_t nameID, bool addIfMissing = false); 55 bool IsTrickyFont() const; 56 57 private: 58 std::vector<NameRecord> names; 59 std::vector<std::string> lang_tags; 60 std::unordered_set<uint16_t> name_ids; 61 }; 62 63 } // namespace ots 64 65 #endif // OTS_NAME_H_