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

Side by Side Diff: Source/core/platform/graphics/FontCacheKey.h

Issue 48113009: Move Font related classes to Source/platform/fonts (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix mac export Created 7 years, 1 month 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 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * 3. Neither the name of Google Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef FontCacheKey_h
32 #define FontCacheKey_h
33
34 #include "wtf/HashMap.h"
35 #include "wtf/HashTableDeletedValueType.h"
36 #include "wtf/text/AtomicStringHash.h"
37 #include "wtf/text/StringHash.h"
38
39 namespace WebCore {
40
41 // Multiplying the floating point size by 100 gives two decimal point
42 // precision which should be sufficient.
43 static const unsigned s_fontSizePrecisionMultiplier = 100;
44
45 struct FontCacheKey {
46 WTF_MAKE_FAST_ALLOCATED;
47 public:
48 FontCacheKey()
49 : m_familyName()
50 , m_fontSize(0)
51 , m_options(0) { }
52 FontCacheKey(AtomicString familyName, float fontSize, unsigned options)
53 : m_familyName(familyName)
54 , m_fontSize(fontSize * s_fontSizePrecisionMultiplier)
55 , m_options(options) { }
56 FontCacheKey(WTF::HashTableDeletedValueType)
57 : m_fontSize(hashTableDeletedSize()) { }
58
59 void setSynthetic(bool bold, bool italic)
60 {
61 m_options |= (bold ? 1 << 6 : 0) | (italic ? 1 << 7 : 0);
62 }
63
64 unsigned hash() const
65 {
66 unsigned hashCodes[3] = {
67 CaseFoldingHash::hash(m_familyName),
68 m_fontSize,
69 m_options
70 };
71 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
72 }
73
74 bool operator==(const FontCacheKey& other) const
75 {
76 return equalIgnoringCase(m_familyName, other.m_familyName)
77 && m_fontSize == other.m_fontSize
78 && m_options == other.m_options;
79 }
80
81 bool isHashTableDeletedValue() const
82 {
83 return m_fontSize == hashTableDeletedSize();
84 }
85
86 private:
87 static unsigned hashTableDeletedSize()
88 {
89 return 0xFFFFFFFFU;
90 }
91
92 AtomicString m_familyName;
93 unsigned m_fontSize;
94 unsigned m_options;
95 };
96
97 struct FontCacheKeyHash {
98 static unsigned hash(const FontCacheKey& key)
99 {
100 return key.hash();
101 }
102
103 static bool equal(const FontCacheKey& a, const FontCacheKey& b)
104 {
105 return a == b;
106 }
107
108 static const bool safeToCompareToEmptyOrDeleted = true;
109 };
110
111 struct FontCacheKeyTraits : WTF::SimpleClassHashTraits<FontCacheKey> { };
112
113 }
114
115 #endif // FontCacheKey_h
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/FontCache.cpp ('k') | Source/core/platform/graphics/FontCustomPlatformData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698