OLD | NEW |
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 | 15 |
15 #include "opentype-sanitiser.h" | 16 #include "opentype-sanitiser.h" |
16 | 17 |
| 18 // arraysize borrowed from base/basictypes.h |
| 19 template <typename T, size_t N> |
| 20 char (&ArraySizeHelper(T (&array)[N]))[N]; |
| 21 #define arraysize(array) (sizeof(ArraySizeHelper(array))) |
| 22 |
17 namespace ots { | 23 namespace ots { |
18 | 24 |
19 #if defined(_MSC_VER) || !defined(OTS_DEBUG) | 25 #if defined(_MSC_VER) || !defined(OTS_DEBUG) |
20 #define OTS_FAILURE() false | 26 #define OTS_FAILURE() false |
21 #else | 27 #else |
22 #define OTS_FAILURE() ots::Failure(__FILE__, __LINE__, __PRETTY_FUNCTION__) | 28 #define OTS_FAILURE() ots::Failure(__FILE__, __LINE__, __PRETTY_FUNCTION__) |
23 bool Failure(const char *f, int l, const char *fn); | 29 bool Failure(const char *f, int l, const char *fn); |
24 #endif | 30 #endif |
25 | 31 |
26 #if defined(_MSC_VER) | 32 #if defined(_MSC_VER) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 size_t length() const { return length_; } | 157 size_t length() const { return length_; } |
152 | 158 |
153 void set_offset(size_t newoffset) { offset_ = newoffset; } | 159 void set_offset(size_t newoffset) { offset_ = newoffset; } |
154 | 160 |
155 private: | 161 private: |
156 const uint8_t * const buffer_; | 162 const uint8_t * const buffer_; |
157 const size_t length_; | 163 const size_t length_; |
158 size_t offset_; | 164 size_t offset_; |
159 }; | 165 }; |
160 | 166 |
| 167 // Round a value up to the nearest multiple of 4. Don't round the value in the |
| 168 // case that rounding up overflows. |
| 169 template<typename T> T Round4(T value) { |
| 170 if (std::numeric_limits<T>::max() - value < 3) { |
| 171 return value; |
| 172 } |
| 173 return (value + 3) & ~3; |
| 174 } |
| 175 |
| 176 bool IsValidVersionTag(uint32_t tag); |
| 177 |
161 #define FOR_EACH_TABLE_TYPE \ | 178 #define FOR_EACH_TABLE_TYPE \ |
162 F(cff, CFF) \ | 179 F(cff, CFF) \ |
163 F(cmap, CMAP) \ | 180 F(cmap, CMAP) \ |
164 F(cvt, CVT) \ | 181 F(cvt, CVT) \ |
165 F(fpgm, FPGM) \ | 182 F(fpgm, FPGM) \ |
166 F(gasp, GASP) \ | 183 F(gasp, GASP) \ |
167 F(gdef, GDEF) \ | 184 F(gdef, GDEF) \ |
168 F(glyf, GLYF) \ | 185 F(glyf, GLYF) \ |
169 F(gpos, GPOS) \ | 186 F(gpos, GPOS) \ |
170 F(gsub, GSUB) \ | 187 F(gsub, GSUB) \ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 bool ots_##name##_should_serialise(OpenTypeFile *f); \ | 229 bool ots_##name##_should_serialise(OpenTypeFile *f); \ |
213 bool ots_##name##_serialise(OTSStream *s, OpenTypeFile *f); \ | 230 bool ots_##name##_serialise(OTSStream *s, OpenTypeFile *f); \ |
214 void ots_##name##_free(OpenTypeFile *f); | 231 void ots_##name##_free(OpenTypeFile *f); |
215 // TODO(yusukes): change these function names to follow Chromium coding rule. | 232 // TODO(yusukes): change these function names to follow Chromium coding rule. |
216 FOR_EACH_TABLE_TYPE | 233 FOR_EACH_TABLE_TYPE |
217 #undef F | 234 #undef F |
218 | 235 |
219 } // namespace ots | 236 } // namespace ots |
220 | 237 |
221 #endif // OTS_H_ | 238 #endif // OTS_H_ |
OLD | NEW |