Index: third_party/WebKit/Source/platform/fonts/opentype/FontSettings.cpp |
diff --git a/third_party/WebKit/Source/platform/fonts/opentype/FontSettings.cpp b/third_party/WebKit/Source/platform/fonts/opentype/FontSettings.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..09ff20d003b77da720a95abfd04759b01cf44509 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/fonts/opentype/FontSettings.cpp |
@@ -0,0 +1,41 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "platform/fonts/opentype/FontSettings.h" |
+ |
+#include "wtf/StringHasher.h" |
+#include "wtf/text/AtomicStringHash.h" |
+#include "wtf/text/StringHash.h" |
+ |
+namespace blink { |
+ |
+uint32_t atomicStringToFourByteTag(AtomicString tag) { |
+ DCHECK_EQ(tag.length(), 4u); |
+ return (((tag[0]) << 24) | ((tag[1]) << 16) | ((tag[2]) << 8) | (tag[3])); |
+} |
+ |
+static inline void addToHash(unsigned& hash, unsigned key) { |
+ hash = ((hash << 5) + hash) + key; // Djb2 |
+}; |
+ |
+static inline void addFloatToHash(unsigned& hash, float value) { |
+ addToHash(hash, StringHasher::hashMemory(&value, sizeof(value))); |
kojii
2016/12/21 14:53:12
Not important but just from curiosity, why don't w
drott
2016/12/21 15:22:00
Good point, took this from similar code in FontDes
|
+}; |
+ |
+unsigned FontVariationSettings::hash() const { |
+ unsigned computedHash = size() ? 5381 : 0; |
+ unsigned numFeatures = size(); |
+ for (unsigned i = 0; i < numFeatures; ++i) { |
+ StringHasher stringHasher; |
+ const AtomicString& tag = at(i).tag(); |
+ for (unsigned j = 0; j < tag.length(); j++) { |
+ stringHasher.addCharacter(tag[j]); |
+ } |
+ addToHash(computedHash, stringHasher.hash()); |
+ addFloatToHash(computedHash, at(i).value()); |
+ } |
+ return computedHash; |
+} |
+ |
+} // namespace blink |