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

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

Issue 2581083003: Initial OpenType Font Variations Support (Closed)
Patch Set: Fix makeUnique syntax Created 3 years, 12 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/fonts/opentype/FontSettings.h"
6
7 #include "wtf/HashFunctions.h"
8 #include "wtf/StringHasher.h"
9 #include "wtf/text/AtomicStringHash.h"
10 #include "wtf/text/StringHash.h"
11
12 namespace blink {
13
14 uint32_t atomicStringToFourByteTag(AtomicString tag) {
15 DCHECK_EQ(tag.length(), 4u);
16 return (((tag[0]) << 24) | ((tag[1]) << 16) | ((tag[2]) << 8) | (tag[3]));
17 }
18
19 static inline void addToHash(unsigned& hash, unsigned key) {
20 hash = ((hash << 5) + hash) + key; // Djb2
21 };
22
23 static inline void addFloatToHash(unsigned& hash, float value) {
24 addToHash(hash, WTF::FloatHash<float>::hash(value));
25 };
26
27 unsigned FontVariationSettings::hash() const {
28 unsigned computedHash = size() ? 5381 : 0;
29 unsigned numFeatures = size();
30 for (unsigned i = 0; i < numFeatures; ++i) {
31 StringHasher stringHasher;
32 const AtomicString& tag = at(i).tag();
33 for (unsigned j = 0; j < tag.length(); j++) {
34 stringHasher.addCharacter(tag[j]);
35 }
36 addToHash(computedHash, stringHasher.hash());
37 addFloatToHash(computedHash, at(i).value());
38 }
39 return computedHash;
40 }
41
42 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698