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

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

Issue 1062093002: 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 1c445ae00e42af577f8a13ffc318a07d12e5b617..285a438979ca704e712625e9225378c52f02c58d 100644
--- a/third_party/ots/include/opentype-sanitiser.h
+++ b/third_party/ots/include/opentype-sanitiser.h
@@ -29,6 +29,9 @@ typedef unsigned __int64 uint64_t;
#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 {
// -----------------------------------------------------------------------------
@@ -37,9 +40,7 @@ namespace ots {
// -----------------------------------------------------------------------------
class OTSStream {
public:
- OTSStream() {
- ResetChecksum();
- }
+ OTSStream() : chksum_(0) {}
virtual ~OTSStream() {}
@@ -51,20 +52,15 @@ class OTSStream {
const size_t orig_length = length;
size_t offset = 0;
- 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);
+ 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);
chksum_ += ntohl(tmp);
- chksum_buffer_offset_ = 0;
+ length -= l;
+ offset += l;
}
while (length >= 4) {
@@ -77,11 +73,11 @@ class OTSStream {
}
if (length) {
- if (chksum_buffer_offset_ != 0) return false; // not reached
if (length > 4) return false; // not reached
- std::memcpy(chksum_buffer_,
- reinterpret_cast<const uint8_t*>(data) + offset, length);
- chksum_buffer_offset_ = length;
+ uint32_t tmp = 0;
+ std::memcpy(&tmp,
+ reinterpret_cast<const uint8_t*>(data) + offset, length);
+ chksum_ += ntohl(tmp);
}
return WriteRaw(data, orig_length);
@@ -142,41 +138,16 @@ class OTSStream {
}
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__
@@ -218,9 +189,6 @@ class OTSContext {
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