Line | Count | Source |
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_GLAT_H_ |
6 | | #define OTS_GLAT_H_ |
7 | | |
8 | | #include <vector> |
9 | | |
10 | | #include "ots.h" |
11 | | #include "graphite.h" |
12 | | |
13 | | namespace ots { |
14 | | |
15 | | // ----------------------------------------------------------------------------- |
16 | | // OpenTypeGLAT_Basic Interface |
17 | | // ----------------------------------------------------------------------------- |
18 | | |
19 | | class OpenTypeGLAT_Basic : public Table { |
20 | | public: |
21 | | explicit OpenTypeGLAT_Basic(Font* font, uint32_t tag) |
22 | 1.21k | : Table(font, tag, tag) { } |
23 | | |
24 | | virtual bool Parse(const uint8_t* data, size_t length) = 0; |
25 | | virtual bool Serialize(OTSStream* out) = 0; |
26 | | }; |
27 | | |
28 | | // ----------------------------------------------------------------------------- |
29 | | // OpenTypeGLAT_v1 |
30 | | // ----------------------------------------------------------------------------- |
31 | | |
32 | | class OpenTypeGLAT_v1 : public OpenTypeGLAT_Basic { |
33 | | public: |
34 | | explicit OpenTypeGLAT_v1(Font* font, uint32_t tag) |
35 | 287 | : OpenTypeGLAT_Basic(font, tag) { } |
36 | | |
37 | | bool Parse(const uint8_t* data, size_t length); |
38 | | bool Serialize(OTSStream* out); |
39 | | |
40 | | private: |
41 | | struct GlatEntry : public TablePart<OpenTypeGLAT_v1> { |
42 | | explicit GlatEntry(OpenTypeGLAT_v1* parent) |
43 | 60.6k | : TablePart<OpenTypeGLAT_v1>(parent) { } |
44 | | bool ParsePart(Buffer& table); |
45 | | bool SerializePart(OTSStream* out) const; |
46 | | uint8_t attNum; |
47 | | uint8_t num; |
48 | | std::vector<int16_t> attributes; |
49 | | }; |
50 | | uint32_t version; |
51 | | std::vector<GlatEntry> entries; |
52 | | }; |
53 | | |
54 | | // ----------------------------------------------------------------------------- |
55 | | // OpenTypeGLAT_v2 |
56 | | // ----------------------------------------------------------------------------- |
57 | | |
58 | | class OpenTypeGLAT_v2 : public OpenTypeGLAT_Basic { |
59 | | public: |
60 | | explicit OpenTypeGLAT_v2(Font* font, uint32_t tag) |
61 | 36 | : OpenTypeGLAT_Basic(font, tag) { } |
62 | | |
63 | | bool Parse(const uint8_t* data, size_t length); |
64 | | bool Serialize(OTSStream* out); |
65 | | |
66 | | private: |
67 | | struct GlatEntry : public TablePart<OpenTypeGLAT_v2> { |
68 | | explicit GlatEntry(OpenTypeGLAT_v2* parent) |
69 | 0 | : TablePart<OpenTypeGLAT_v2>(parent) { } |
70 | | bool ParsePart(Buffer& table); |
71 | | bool SerializePart(OTSStream* out) const; |
72 | | int16_t attNum; |
73 | | int16_t num; |
74 | | std::vector<int16_t> attributes; |
75 | | }; |
76 | | uint32_t version; |
77 | | std::vector<GlatEntry> entries; |
78 | | }; |
79 | | |
80 | | // ----------------------------------------------------------------------------- |
81 | | // OpenTypeGLAT_v3 |
82 | | // ----------------------------------------------------------------------------- |
83 | | |
84 | | class OpenTypeGLAT_v3 : public OpenTypeGLAT_Basic { |
85 | | public: |
86 | | explicit OpenTypeGLAT_v3(Font* font, uint32_t tag) |
87 | 896 | : OpenTypeGLAT_Basic(font, tag) { } |
88 | | |
89 | 896 | bool Parse(const uint8_t* data, size_t length) { |
90 | 896 | return this->Parse(data, length, false); |
91 | 896 | } |
92 | | bool Serialize(OTSStream* out); |
93 | | |
94 | | private: |
95 | | bool Parse(const uint8_t* data, size_t length, bool prevent_decompression); |
96 | | struct GlyphAttrs : public TablePart<OpenTypeGLAT_v3> { |
97 | | explicit GlyphAttrs(OpenTypeGLAT_v3* parent) |
98 | 12.9k | : TablePart<OpenTypeGLAT_v3>(parent), octabox(parent) { } |
99 | 0 | bool ParsePart(Buffer& table OTS_UNUSED) { return false; } |
100 | | bool ParsePart(Buffer& table, const size_t size); |
101 | | bool SerializePart(OTSStream* out) const; |
102 | | struct OctaboxMetrics : public TablePart<OpenTypeGLAT_v3> { |
103 | | explicit OctaboxMetrics(OpenTypeGLAT_v3* parent) |
104 | 12.9k | : TablePart<OpenTypeGLAT_v3>(parent) { } |
105 | | bool ParsePart(Buffer& table); |
106 | | bool SerializePart(OTSStream* out) const; |
107 | | struct SubboxEntry : public TablePart<OpenTypeGLAT_v3> { |
108 | | explicit SubboxEntry(OpenTypeGLAT_v3* parent) |
109 | 26.5k | : TablePart<OpenTypeGLAT_v3>(parent) { } |
110 | | bool ParsePart(Buffer& table); |
111 | | bool SerializePart(OTSStream* out) const; |
112 | | uint8_t left; |
113 | | uint8_t right; |
114 | | uint8_t bottom; |
115 | | uint8_t top; |
116 | | uint8_t diag_pos_min; |
117 | | uint8_t diag_pos_max; |
118 | | uint8_t diag_neg_min; |
119 | | uint8_t diag_neg_max; |
120 | | }; |
121 | | uint16_t subbox_bitmap; |
122 | | uint8_t diag_neg_min; |
123 | | uint8_t diag_neg_max; |
124 | | uint8_t diag_pos_min; |
125 | | uint8_t diag_pos_max; |
126 | | std::vector<SubboxEntry> subboxes; |
127 | | }; |
128 | | struct GlatEntry : public TablePart<OpenTypeGLAT_v3> { |
129 | | explicit GlatEntry(OpenTypeGLAT_v3* parent) |
130 | 46.8k | : TablePart<OpenTypeGLAT_v3>(parent) { } |
131 | | bool ParsePart(Buffer& table); |
132 | | bool SerializePart(OTSStream* out) const; |
133 | | int16_t attNum; |
134 | | int16_t num; |
135 | | std::vector<int16_t> attributes; |
136 | | }; |
137 | | OctaboxMetrics octabox; |
138 | | std::vector<GlatEntry> entries; |
139 | | }; |
140 | | uint32_t version; |
141 | | uint32_t compHead; // compression header |
142 | | static const uint32_t SCHEME = 0xF8000000; |
143 | | static const uint32_t FULL_SIZE = 0x07FFFFFF; |
144 | | static const uint32_t RESERVED = 0x07FFFFFE; |
145 | | static const uint32_t OCTABOXES = 0x00000001; |
146 | | std::vector<GlyphAttrs> entries; |
147 | | }; |
148 | | |
149 | | // ----------------------------------------------------------------------------- |
150 | | // OpenTypeGLAT |
151 | | // ----------------------------------------------------------------------------- |
152 | | |
153 | | class OpenTypeGLAT : public Table { |
154 | | public: |
155 | | explicit OpenTypeGLAT(Font* font, uint32_t tag) |
156 | 1.38k | : Table(font, tag, tag), font(font), tag(tag) { } |
157 | | OpenTypeGLAT(const OpenTypeGLAT& other) = delete; |
158 | | OpenTypeGLAT& operator=(const OpenTypeGLAT& other) = delete; |
159 | 1.38k | ~OpenTypeGLAT() { delete handler; } |
160 | | |
161 | | bool Parse(const uint8_t* data, size_t length); |
162 | | bool Serialize(OTSStream* out); |
163 | | |
164 | 6.50k | virtual bool ShouldSerialize() { |
165 | 6.50k | return handler && handler->ShouldSerialize(); |
166 | 6.50k | } |
167 | | |
168 | | private: |
169 | | Font* font; |
170 | | uint32_t tag; |
171 | | OpenTypeGLAT_Basic* handler = nullptr; |
172 | | }; |
173 | | |
174 | | } // namespace ots |
175 | | |
176 | | #endif // OTS_GLAT_H_ |