Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: third_party/ots/src/ots.h

Issue 1252363005: Update OTS to revision a7a3b94 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/ots/src/os2.cc ('k') | third_party/ots/src/ots.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef OTS_H_ 5 #ifndef OTS_H_
6 #define OTS_H_ 6 #define OTS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <cstdarg> 9 #include <cstdarg>
10 #include <cstddef> 10 #include <cstddef>
11 #include <cstdio> 11 #include <cstdio>
12 #include <cstdlib> 12 #include <cstdlib>
13 #include <cstring> 13 #include <cstring>
14 #include <limits> 14 #include <limits>
15 #include <map>
15 16
16 #include "opentype-sanitiser.h" 17 #include "opentype-sanitiser.h"
17 18
18 // arraysize borrowed from base/basictypes.h 19 // arraysize borrowed from base/basictypes.h
19 template <typename T, size_t N> 20 template <typename T, size_t N>
20 char (&ArraySizeHelper(T (&array)[N]))[N]; 21 char (&ArraySizeHelper(T (&array)[N]))[N];
21 #define arraysize(array) (sizeof(ArraySizeHelper(array))) 22 #define arraysize(array) (sizeof(ArraySizeHelper(array)))
22 23
23 namespace ots { 24 namespace ots {
24 25
(...skipping 23 matching lines...) Expand all
48 49
49 // Generate a simple message 50 // Generate a simple message
50 #define OTS_FAILURE_MSG_(otf_,...) \ 51 #define OTS_FAILURE_MSG_(otf_,...) \
51 (OTS_MESSAGE_(0,otf_,__VA_ARGS__), false) 52 (OTS_MESSAGE_(0,otf_,__VA_ARGS__), false)
52 53
53 #define OTS_WARNING_MSG_(otf_,...) \ 54 #define OTS_WARNING_MSG_(otf_,...) \
54 OTS_MESSAGE_(1,otf_,__VA_ARGS__) 55 OTS_MESSAGE_(1,otf_,__VA_ARGS__)
55 56
56 // Generate a message with an associated table tag 57 // Generate a message with an associated table tag
57 #define OTS_FAILURE_MSG_TAG_(otf_,msg_,tag_) \ 58 #define OTS_FAILURE_MSG_TAG_(otf_,msg_,tag_) \
58 (OTS_MESSAGE_(0,otf_,"%4.4s: %s", tag_, msg_), false) 59 (OTS_MESSAGE_(0,otf_,"%c%c%c%c: %s", OTS_UNTAG(tag_), msg_), false)
59 60
60 // Convenience macros for use in files that only handle a single table tag, 61 // Convenience macros for use in files that only handle a single table tag,
61 // defined as TABLE_NAME at the top of the file; the 'file' variable is 62 // defined as TABLE_NAME at the top of the file; the 'file' variable is
62 // expected to be the current OpenTypeFile pointer. 63 // expected to be the current OpenTypeFile pointer.
63 #define OTS_FAILURE_MSG(...) OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__) 64 #define OTS_FAILURE_MSG(...) OTS_FAILURE_MSG_(font->file, TABLE_NAME ": " __VA_A RGS__)
64 65
65 #define OTS_WARNING(...) OTS_WARNING_MSG_(file, TABLE_NAME ": " __VA_ARGS__) 66 #define OTS_WARNING(...) OTS_WARNING_MSG_(font->file, TABLE_NAME ": " __VA_ARGS_ _)
66 67
67 // ----------------------------------------------------------------------------- 68 // -----------------------------------------------------------------------------
68 // Buffer helper class 69 // Buffer helper class
69 // 70 //
70 // This class perform some trival buffer operations while checking for 71 // This class perform some trival buffer operations while checking for
71 // out-of-bounds errors. As a family they return false if anything is amiss, 72 // out-of-bounds errors. As a family they return false if anything is amiss,
72 // updating the current offset otherwise. 73 // updating the current offset otherwise.
73 // ----------------------------------------------------------------------------- 74 // -----------------------------------------------------------------------------
74 class Buffer { 75 class Buffer {
75 public: 76 public:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 std::memcpy(value, buffer_ + offset_, sizeof(uint32_t)); 139 std::memcpy(value, buffer_ + offset_, sizeof(uint32_t));
139 *value = ntohl(*value); 140 *value = ntohl(*value);
140 offset_ += 4; 141 offset_ += 4;
141 return true; 142 return true;
142 } 143 }
143 144
144 bool ReadS32(int32_t *value) { 145 bool ReadS32(int32_t *value) {
145 return ReadU32(reinterpret_cast<uint32_t*>(value)); 146 return ReadU32(reinterpret_cast<uint32_t*>(value));
146 } 147 }
147 148
148 bool ReadTag(uint32_t *value) {
149 if (offset_ + 4 > length_) {
150 return OTS_FAILURE();
151 }
152 std::memcpy(value, buffer_ + offset_, sizeof(uint32_t));
153 offset_ += 4;
154 return true;
155 }
156
157 bool ReadR64(uint64_t *value) { 149 bool ReadR64(uint64_t *value) {
158 if (offset_ + 8 > length_) { 150 if (offset_ + 8 > length_) {
159 return OTS_FAILURE(); 151 return OTS_FAILURE();
160 } 152 }
161 std::memcpy(value, buffer_ + offset_, sizeof(uint64_t)); 153 std::memcpy(value, buffer_ + offset_, sizeof(uint64_t));
162 offset_ += 8; 154 offset_ += 8;
163 return true; 155 return true;
164 } 156 }
165 157
166 const uint8_t *buffer() const { return buffer_; } 158 const uint8_t *buffer() const { return buffer_; }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 F(prep, PREP) \ 210 F(prep, PREP) \
219 F(vdmx, VDMX) \ 211 F(vdmx, VDMX) \
220 F(vorg, VORG) \ 212 F(vorg, VORG) \
221 F(vhea, VHEA) \ 213 F(vhea, VHEA) \
222 F(vmtx, VMTX) 214 F(vmtx, VMTX)
223 215
224 #define F(name, capname) struct OpenType##capname; 216 #define F(name, capname) struct OpenType##capname;
225 FOR_EACH_TABLE_TYPE 217 FOR_EACH_TABLE_TYPE
226 #undef F 218 #undef F
227 219
228 struct OpenTypeFile { 220 struct Font;
229 OpenTypeFile() { 221 struct OpenTypeFile;
230 #define F(name, capname) name = NULL; 222
223 #define F(name, capname) \
224 bool ots_##name##_parse(Font *f, const uint8_t *d, size_t l); \
225 bool ots_##name##_should_serialise(Font *f); \
226 bool ots_##name##_serialise(OTSStream *s, Font *f); \
227 void ots_##name##_reuse(Font *f, Font *o);\
228 void ots_##name##_free(Font *f);
229 FOR_EACH_TABLE_TYPE
230 #undef F
231
232 struct Font {
233 Font(const OpenTypeFile *f) {
234 file = f;
235 #define F(name, capname) \
236 name = NULL; \
237 name##_reused = false;
231 FOR_EACH_TABLE_TYPE 238 FOR_EACH_TABLE_TYPE
232 #undef F 239 #undef F
233 } 240 }
234 241
242 ~Font() {
243 #define F(name, capname) \
244 if (!name##_reused) {\
245 ots_##name##_free(this); \
246 }
247 FOR_EACH_TABLE_TYPE
248 #undef F
249 }
250
251 const OpenTypeFile *file;
252
235 uint32_t version; 253 uint32_t version;
236 uint16_t num_tables; 254 uint16_t num_tables;
237 uint16_t search_range; 255 uint16_t search_range;
238 uint16_t entry_selector; 256 uint16_t entry_selector;
239 uint16_t range_shift; 257 uint16_t range_shift;
240 258
241 OTSContext *context; 259 #define F(name, capname) \
242 260 OpenType##capname *name; \
243 #define F(name, capname) OpenType##capname *name; 261 bool name##_reused;
244 FOR_EACH_TABLE_TYPE 262 FOR_EACH_TABLE_TYPE
245 #undef F 263 #undef F
246 }; 264 };
247 265
248 #define F(name, capname) \ 266 struct OutputTable {
249 bool ots_##name##_parse(OpenTypeFile *f, const uint8_t *d, size_t l); \ 267 uint32_t tag;
250 bool ots_##name##_should_serialise(OpenTypeFile *f); \ 268 size_t offset;
251 bool ots_##name##_serialise(OTSStream *s, OpenTypeFile *f); \ 269 size_t length;
252 void ots_##name##_free(OpenTypeFile *f); 270 uint32_t chksum;
253 // TODO(yusukes): change these function names to follow Chromium coding rule. 271
254 FOR_EACH_TABLE_TYPE 272 bool operator<(const OutputTable& other) const {
255 #undef F 273 return tag < other.tag;
274 }
275 };
276
277 typedef std::map<uint32_t, std::pair<Font*, OutputTable> > TableMap;
278
279 struct OpenTypeFile {
280 OTSContext *context;
281 TableMap tables;
282 };
256 283
257 } // namespace ots 284 } // namespace ots
258 285
286 #undef FOR_EACH_TABLE_TYPE
287
259 #endif // OTS_H_ 288 #endif // OTS_H_
OLDNEW
« no previous file with comments | « third_party/ots/src/os2.cc ('k') | third_party/ots/src/ots.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698