cmap.h (2580B)
1 // Copyright (c) 2009-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_CMAP_H_ 6 #define OTS_CMAP_H_ 7 8 #include <vector> 9 10 #include "ots.h" 11 12 namespace ots { 13 14 struct OpenTypeCMAPSubtableRange { 15 uint32_t start_range; 16 uint32_t end_range; 17 uint32_t start_glyph_id; 18 }; 19 20 struct OpenTypeCMAPSubtableVSRange { 21 uint32_t unicode_value; 22 uint8_t additional_count; 23 }; 24 25 struct OpenTypeCMAPSubtableVSMapping { 26 uint32_t unicode_value; 27 uint16_t glyph_id; 28 }; 29 30 struct OpenTypeCMAPSubtableVSRecord { 31 uint32_t var_selector; 32 uint32_t default_offset; 33 uint32_t non_default_offset; 34 std::vector<OpenTypeCMAPSubtableVSRange> ranges; 35 std::vector<OpenTypeCMAPSubtableVSMapping> mappings; 36 }; 37 38 class OpenTypeCMAP : public Table { 39 public: 40 explicit OpenTypeCMAP(Font *font, uint32_t tag) 41 : Table(font, tag, tag), 42 subtable_0_3_4_data(NULL), 43 subtable_0_3_4_length(0), 44 subtable_0_5_14_length(0), 45 subtable_3_0_4_data(NULL), 46 subtable_3_0_4_length(0), 47 subtable_3_1_4_data(NULL), 48 subtable_3_1_4_length(0) { 49 } 50 51 bool Parse(const uint8_t *data, size_t length); 52 bool Serialize(OTSStream *out); 53 54 private: 55 // Platform 0, Encoding 3, Format 4, Unicode BMP table. 56 const uint8_t *subtable_0_3_4_data; 57 size_t subtable_0_3_4_length; 58 59 // Platform 0, Encoding 5, Format 14, Unicode Variation Sequence table. 60 size_t subtable_0_5_14_length; 61 std::vector<OpenTypeCMAPSubtableVSRecord> subtable_0_5_14; 62 63 // Platform 3, Encoding 0, Format 4, MS Symbol table. 64 const uint8_t *subtable_3_0_4_data; 65 size_t subtable_3_0_4_length; 66 // Platform 3, Encoding 1, Format 4, MS Unicode BMP table. 67 const uint8_t *subtable_3_1_4_data; 68 size_t subtable_3_1_4_length; 69 70 // Platform 3, Encoding 10, Format 12, MS Unicode UCS-4 table. 71 std::vector<OpenTypeCMAPSubtableRange> subtable_3_10_12; 72 // Platform 3, Encoding 10, Format 13, MS UCS-4 Fallback table. 73 std::vector<OpenTypeCMAPSubtableRange> subtable_3_10_13; 74 // Platform 1, Encoding 0, Format 0, Mac Roman table. 75 std::vector<uint8_t> subtable_1_0_0; 76 77 bool ParseFormat4(int platform, int encoding, const uint8_t *data, 78 size_t length, uint16_t num_glyphs); 79 bool Parse31012(const uint8_t *data, size_t length, uint16_t num_glyphs); 80 bool Parse31013(const uint8_t *data, size_t length, uint16_t num_glyphs); 81 bool Parse0514(const uint8_t *data, size_t length); 82 bool Parse100(const uint8_t *data, size_t length); 83 }; 84 85 } // namespace ots 86 87 #endif