| Index: third_party/ots/src/ots.h
|
| diff --git a/third_party/ots/src/ots.h b/third_party/ots/src/ots.h
|
| index ba3ba77a286cf3ad57bcee654689d01ebec4d74a..b2dd9ad48d7255b0e98cd43eec033d3205c0f1be 100644
|
| --- a/third_party/ots/src/ots.h
|
| +++ b/third_party/ots/src/ots.h
|
| @@ -12,6 +12,7 @@
|
| #include <cstdlib>
|
| #include <cstring>
|
| #include <limits>
|
| +#include <map>
|
|
|
| #include "opentype-sanitiser.h"
|
|
|
| @@ -55,14 +56,14 @@ namespace ots {
|
|
|
| // Generate a message with an associated table tag
|
| #define OTS_FAILURE_MSG_TAG_(otf_,msg_,tag_) \
|
| - (OTS_MESSAGE_(0,otf_,"%4.4s: %s", tag_, msg_), false)
|
| + (OTS_MESSAGE_(0,otf_,"%c%c%c%c: %s", OTS_UNTAG(tag_), msg_), false)
|
|
|
| // Convenience macros for use in files that only handle a single table tag,
|
| // defined as TABLE_NAME at the top of the file; the 'file' variable is
|
| // expected to be the current OpenTypeFile pointer.
|
| -#define OTS_FAILURE_MSG(...) OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__)
|
| +#define OTS_FAILURE_MSG(...) OTS_FAILURE_MSG_(font->file, TABLE_NAME ": " __VA_ARGS__)
|
|
|
| -#define OTS_WARNING(...) OTS_WARNING_MSG_(file, TABLE_NAME ": " __VA_ARGS__)
|
| +#define OTS_WARNING(...) OTS_WARNING_MSG_(font->file, TABLE_NAME ": " __VA_ARGS__)
|
|
|
| // -----------------------------------------------------------------------------
|
| // Buffer helper class
|
| @@ -145,15 +146,6 @@ class Buffer {
|
| return ReadU32(reinterpret_cast<uint32_t*>(value));
|
| }
|
|
|
| - bool ReadTag(uint32_t *value) {
|
| - if (offset_ + 4 > length_) {
|
| - return OTS_FAILURE();
|
| - }
|
| - std::memcpy(value, buffer_ + offset_, sizeof(uint32_t));
|
| - offset_ += 4;
|
| - return true;
|
| - }
|
| -
|
| bool ReadR64(uint64_t *value) {
|
| if (offset_ + 8 > length_) {
|
| return OTS_FAILURE();
|
| @@ -225,35 +217,72 @@ bool IsValidVersionTag(uint32_t tag);
|
| FOR_EACH_TABLE_TYPE
|
| #undef F
|
|
|
| -struct OpenTypeFile {
|
| - OpenTypeFile() {
|
| -#define F(name, capname) name = NULL;
|
| +struct Font;
|
| +struct OpenTypeFile;
|
| +
|
| +#define F(name, capname) \
|
| +bool ots_##name##_parse(Font *f, const uint8_t *d, size_t l); \
|
| +bool ots_##name##_should_serialise(Font *f); \
|
| +bool ots_##name##_serialise(OTSStream *s, Font *f); \
|
| +void ots_##name##_reuse(Font *f, Font *o);\
|
| +void ots_##name##_free(Font *f);
|
| +FOR_EACH_TABLE_TYPE
|
| +#undef F
|
| +
|
| +struct Font {
|
| + Font(const OpenTypeFile *f) {
|
| + file = f;
|
| +#define F(name, capname) \
|
| + name = NULL; \
|
| + name##_reused = false;
|
| FOR_EACH_TABLE_TYPE
|
| #undef F
|
| }
|
|
|
| + ~Font() {
|
| +#define F(name, capname) \
|
| + if (!name##_reused) {\
|
| + ots_##name##_free(this); \
|
| + }
|
| + FOR_EACH_TABLE_TYPE
|
| +#undef F
|
| + }
|
| +
|
| + const OpenTypeFile *file;
|
| +
|
| uint32_t version;
|
| uint16_t num_tables;
|
| uint16_t search_range;
|
| uint16_t entry_selector;
|
| uint16_t range_shift;
|
|
|
| - OTSContext *context;
|
| -
|
| -#define F(name, capname) OpenType##capname *name;
|
| +#define F(name, capname) \
|
| + OpenType##capname *name; \
|
| + bool name##_reused;
|
| FOR_EACH_TABLE_TYPE
|
| #undef F
|
| };
|
|
|
| -#define F(name, capname) \
|
| -bool ots_##name##_parse(OpenTypeFile *f, const uint8_t *d, size_t l); \
|
| -bool ots_##name##_should_serialise(OpenTypeFile *f); \
|
| -bool ots_##name##_serialise(OTSStream *s, OpenTypeFile *f); \
|
| -void ots_##name##_free(OpenTypeFile *f);
|
| -// TODO(yusukes): change these function names to follow Chromium coding rule.
|
| -FOR_EACH_TABLE_TYPE
|
| -#undef F
|
| +struct OutputTable {
|
| + uint32_t tag;
|
| + size_t offset;
|
| + size_t length;
|
| + uint32_t chksum;
|
| +
|
| + bool operator<(const OutputTable& other) const {
|
| + return tag < other.tag;
|
| + }
|
| +};
|
| +
|
| +typedef std::map<uint32_t, std::pair<Font*, OutputTable> > TableMap;
|
| +
|
| +struct OpenTypeFile {
|
| + OTSContext *context;
|
| + TableMap tables;
|
| +};
|
|
|
| } // namespace ots
|
|
|
| +#undef FOR_EACH_TABLE_TYPE
|
| +
|
| #endif // OTS_H_
|
|
|