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

Unified Diff: third_party/ots/include/opentype-sanitiser.h

Issue 1064913002: Revert of Update OTS to revision 6d2e08b (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/ots/README.chromium ('k') | third_party/ots/src/cmap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/ots/include/opentype-sanitiser.h
diff --git a/third_party/ots/include/opentype-sanitiser.h b/third_party/ots/include/opentype-sanitiser.h
index 285a438979ca704e712625e9225378c52f02c58d..1c445ae00e42af577f8a13ffc318a07d12e5b617 100644
--- a/third_party/ots/include/opentype-sanitiser.h
+++ b/third_party/ots/include/opentype-sanitiser.h
@@ -29,9 +29,6 @@
#include <cstddef>
#include <cstring>
-#define OTS_TAG(c1,c2,c3,c4) ((uint32_t)((((uint8_t)(c1))<<24)|(((uint8_t)(c2))<<16)|(((uint8_t)(c3))<<8)|((uint8_t)(c4))))
-#define OTS_UNTAG(tag) ((uint8_t)((tag)>>24)), ((uint8_t)((tag)>>16)), ((uint8_t)((tag)>>8)), ((uint8_t)(tag))
-
namespace ots {
// -----------------------------------------------------------------------------
@@ -40,7 +37,9 @@
// -----------------------------------------------------------------------------
class OTSStream {
public:
- OTSStream() : chksum_(0) {}
+ OTSStream() {
+ ResetChecksum();
+ }
virtual ~OTSStream() {}
@@ -52,15 +51,20 @@
const size_t orig_length = length;
size_t offset = 0;
-
- size_t chksum_offset = Tell() & 3;
- if (chksum_offset) {
- const size_t l = std::min(length, static_cast<size_t>(4) - chksum_offset);
- uint32_t tmp = 0;
- std::memcpy(reinterpret_cast<uint8_t *>(&tmp) + chksum_offset, data, l);
+ if (chksum_buffer_offset_) {
+ const size_t l =
+ std::min(length, static_cast<size_t>(4) - chksum_buffer_offset_);
+ std::memcpy(chksum_buffer_ + chksum_buffer_offset_, data, l);
+ chksum_buffer_offset_ += l;
+ offset += l;
+ length -= l;
+ }
+
+ if (chksum_buffer_offset_ == 4) {
+ uint32_t tmp;
+ std::memcpy(&tmp, chksum_buffer_, 4);
chksum_ += ntohl(tmp);
- length -= l;
- offset += l;
+ chksum_buffer_offset_ = 0;
}
while (length >= 4) {
@@ -73,11 +77,11 @@
}
if (length) {
+ if (chksum_buffer_offset_ != 0) return false; // not reached
if (length > 4) return false; // not reached
- uint32_t tmp = 0;
- std::memcpy(&tmp,
- reinterpret_cast<const uint8_t*>(data) + offset, length);
- chksum_ += ntohl(tmp);
+ std::memcpy(chksum_buffer_,
+ reinterpret_cast<const uint8_t*>(data) + offset, length);
+ chksum_buffer_offset_ = length;
}
return WriteRaw(data, orig_length);
@@ -138,16 +142,41 @@
}
void ResetChecksum() {
- assert((Tell() & 3) == 0);
chksum_ = 0;
+ chksum_buffer_offset_ = 0;
}
uint32_t chksum() const {
+ assert(chksum_buffer_offset_ == 0);
return chksum_;
+ }
+
+ struct ChecksumState {
+ uint32_t chksum;
+ uint8_t chksum_buffer[4];
+ unsigned chksum_buffer_offset;
+ };
+
+ ChecksumState SaveChecksumState() const {
+ ChecksumState s;
+ s.chksum = chksum_;
+ s.chksum_buffer_offset = chksum_buffer_offset_;
+ std::memcpy(s.chksum_buffer, chksum_buffer_, 4);
+
+ return s;
+ }
+
+ void RestoreChecksum(const ChecksumState &s) {
+ assert(chksum_buffer_offset_ == 0);
+ chksum_ += s.chksum;
+ chksum_buffer_offset_ = s.chksum_buffer_offset;
+ std::memcpy(chksum_buffer_, s.chksum_buffer, 4);
}
protected:
uint32_t chksum_;
+ uint8_t chksum_buffer_[4];
+ unsigned chksum_buffer_offset_;
};
#ifdef __GCC__
@@ -189,6 +218,9 @@
virtual TableAction GetTableAction(uint32_t tag) { return ots::TABLE_ACTION_DEFAULT; }
};
+// For backward compatibility - remove once Chrome switches over to the new API.
+bool Process(OTSStream *output, const uint8_t *input, size_t length);
+
} // namespace ots
#endif // OPENTYPE_SANITISER_H_
« no previous file with comments | « third_party/ots/README.chromium ('k') | third_party/ots/src/cmap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698