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

Unified Diff: third_party/WebKit/Source/platform/fonts/opentype/FontSettings.cpp

Issue 2581083003: Initial OpenType Font Variations Support (Closed)
Patch Set: Fix Windows compilation by avoiding VLA Created 4 years 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
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..167604f2c2579260a80fb1c6669b61a3c62291eb
--- /dev/null
+++ b/third_party/WebKit/Source/platform/fonts/opentype/FontSettings.cpp
@@ -0,0 +1,36 @@
+// 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 {
+
+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)));
+};
+
+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

Powered by Google App Engine
This is Rietveld 408576698