| 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 OPENTYPE_SANITISER_H_ | 5 #ifndef OPENTYPE_SANITISER_H_ |
| 6 #define OPENTYPE_SANITISER_H_ | 6 #define OPENTYPE_SANITISER_H_ |
| 7 | 7 |
| 8 #if defined(_WIN32) | 8 #if defined(_WIN32) |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 typedef signed char int8_t; | 10 typedef signed char int8_t; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 return WriteRaw(data, orig_length); | 83 return WriteRaw(data, orig_length); |
| 84 } | 84 } |
| 85 | 85 |
| 86 virtual bool Seek(off_t position) = 0; | 86 virtual bool Seek(off_t position) = 0; |
| 87 virtual off_t Tell() const = 0; | 87 virtual off_t Tell() const = 0; |
| 88 | 88 |
| 89 virtual bool Pad(size_t bytes) { | 89 virtual bool Pad(size_t bytes) { |
| 90 static const uint32_t kZero = 0; | 90 static const uint32_t kZero = 0; |
| 91 while (bytes >= 4) { | 91 while (bytes >= 4) { |
| 92 if (!WriteTag(kZero)) return false; | 92 if (!Write(&kZero, 4)) return false; |
| 93 bytes -= 4; | 93 bytes -= 4; |
| 94 } | 94 } |
| 95 while (bytes) { | 95 while (bytes) { |
| 96 static const uint8_t kZerob = 0; | 96 static const uint8_t kZerob = 0; |
| 97 if (!Write(&kZerob, 1)) return false; | 97 if (!Write(&kZerob, 1)) return false; |
| 98 bytes--; | 98 bytes--; |
| 99 } | 99 } |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 126 | 126 |
| 127 bool WriteS32(int32_t v) { | 127 bool WriteS32(int32_t v) { |
| 128 v = htonl(v); | 128 v = htonl(v); |
| 129 return Write(&v, sizeof(v)); | 129 return Write(&v, sizeof(v)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool WriteR64(uint64_t v) { | 132 bool WriteR64(uint64_t v) { |
| 133 return Write(&v, sizeof(v)); | 133 return Write(&v, sizeof(v)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool WriteTag(uint32_t v) { | |
| 137 return Write(&v, sizeof(v)); | |
| 138 } | |
| 139 | |
| 140 void ResetChecksum() { | 136 void ResetChecksum() { |
| 141 assert((Tell() & 3) == 0); | 137 assert((Tell() & 3) == 0); |
| 142 chksum_ = 0; | 138 chksum_ = 0; |
| 143 } | 139 } |
| 144 | 140 |
| 145 uint32_t chksum() const { | 141 uint32_t chksum() const { |
| 146 return chksum_; | 142 return chksum_; |
| 147 } | 143 } |
| 148 | 144 |
| 149 protected: | 145 protected: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 167 public: | 163 public: |
| 168 OTSContext() {} | 164 OTSContext() {} |
| 169 virtual ~OTSContext() {} | 165 virtual ~OTSContext() {} |
| 170 | 166 |
| 171 // Process a given OpenType file and write out a sanitised version | 167 // Process a given OpenType file and write out a sanitised version |
| 172 // output: a pointer to an object implementing the OTSStream interface. Th
e | 168 // output: a pointer to an object implementing the OTSStream interface. Th
e |
| 173 // sanitisied output will be written to this. In the even of a failure, | 169 // sanitisied output will be written to this. In the even of a failure, |
| 174 // partial output may have been written. | 170 // partial output may have been written. |
| 175 // input: the OpenType file | 171 // input: the OpenType file |
| 176 // length: the size, in bytes, of |input| | 172 // length: the size, in bytes, of |input| |
| 177 bool Process(OTSStream *output, const uint8_t *input, size_t length); | 173 // index: if the input is a font collection and index is specified, then |
| 174 // the corresponding font will be returned, otherwise the whole |
| 175 // collection. Ignored for non-collection fonts. |
| 176 bool Process(OTSStream *output, const uint8_t *input, size_t length, uint32_
t index = -1); |
| 178 | 177 |
| 179 // This function will be called when OTS is reporting an error. | 178 // This function will be called when OTS is reporting an error. |
| 180 // level: the severity of the generated message: | 179 // level: the severity of the generated message: |
| 181 // 0: error messages in case OTS fails to sanitize the font. | 180 // 0: error messages in case OTS fails to sanitize the font. |
| 182 // 1: warning messages about issue OTS fixed in the sanitized font. | 181 // 1: warning messages about issue OTS fixed in the sanitized font. |
| 183 virtual void Message(int level, const char *format, ...) MSGFUNC_FMT_ATTR {} | 182 virtual void Message(int level, const char *format, ...) MSGFUNC_FMT_ATTR {} |
| 184 | 183 |
| 185 // This function will be called when OTS needs to decide what to do for a | 184 // This function will be called when OTS needs to decide what to do for a |
| 186 // font table. | 185 // font table. |
| 187 // tag: table tag as an integer in big-endian byte order, independent of | 186 // tag: table tag as an integer in big-endian byte order, independent of |
| 188 // platform endianness | 187 // platform endianness |
| 189 virtual TableAction GetTableAction(uint32_t tag) { return ots::TABLE_ACTION_
DEFAULT; } | 188 virtual TableAction GetTableAction(uint32_t tag) { return ots::TABLE_ACTION_
DEFAULT; } |
| 190 }; | 189 }; |
| 191 | 190 |
| 192 } // namespace ots | 191 } // namespace ots |
| 193 | 192 |
| 194 #endif // OPENTYPE_SANITISER_H_ | 193 #endif // OPENTYPE_SANITISER_H_ |
| OLD | NEW |