summaryrefslogtreecommitdiffstats
path: root/Source/ThirdParty/woff2/src/woff2_common.cc
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2016-09-28 16:39:37 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2017-02-02 12:31:01 +0000
commit9daf1655d7e4eaaa6ed5f44055a4b4fd399fd25c (patch)
tree322337ad0acbc75732f916376ec6d36e7ec0e5bc /Source/ThirdParty/woff2/src/woff2_common.cc
parent6882a04fb36642862b11efe514251d32070c3d65 (diff)
Imported WebKit commit eb954cdcf58f9b915b2fcb6f8e4cb3a60650a4f3
Change-Id: I8dda875c38075d43b76fe3a21acb0ffa102bb82d Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/ThirdParty/woff2/src/woff2_common.cc')
-rw-r--r--Source/ThirdParty/woff2/src/woff2_common.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/Source/ThirdParty/woff2/src/woff2_common.cc b/Source/ThirdParty/woff2/src/woff2_common.cc
new file mode 100644
index 000000000..39dc54e6f
--- /dev/null
+++ b/Source/ThirdParty/woff2/src/woff2_common.cc
@@ -0,0 +1,53 @@
+// Copyright 2013 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Helpers common across multiple parts of woff2
+
+#include <algorithm>
+
+#include "./woff2_common.h"
+
+namespace woff2 {
+
+
+uint32_t ComputeULongSum(const uint8_t* buf, size_t size) {
+ uint32_t checksum = 0;
+ for (size_t i = 0; i < size; i += 4) {
+#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
+ uint32_t v = *reinterpret_cast<const uint32_t*>(buf + i);
+ checksum += (((v & 0xFF) << 24) | ((v & 0xFF00) << 8) |
+ ((v & 0xFF0000) >> 8) | ((v & 0xFF000000) >> 24));
+#elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
+ checksum += *reinterpret_cast<const uint32_t*>(buf + i);
+#else
+ checksum += (buf[i] << 24) | (buf[i + 1] << 16) |
+ (buf[i + 2] << 8) | buf[i + 3];
+#endif
+ }
+ return checksum;
+}
+
+size_t CollectionHeaderSize(uint32_t header_version, uint32_t num_fonts) {
+ size_t size = 0;
+ if (header_version == 0x00020000) {
+ size += 12; // ulDsig{Tag,Length,Offset}
+ }
+ if (header_version == 0x00010000 || header_version == 0x00020000) {
+ size += 12 // TTCTag, Version, numFonts
+ + 4 * num_fonts; // OffsetTable[numFonts]
+ }
+ return size;
+}
+
+} // namespace woff2