OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | 3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 FontCache::FontCache() | 58 FontCache::FontCache() |
59 : m_purgePreventCount(0) | 59 : m_purgePreventCount(0) |
60 { | 60 { |
61 } | 61 } |
62 #endif // !OS(WIN) || ENABLE(GDI_FONTS_ON_WINDOWS) | 62 #endif // !OS(WIN) || ENABLE(GDI_FONTS_ON_WINDOWS) |
63 | 63 |
64 struct FontPlatformDataCacheKey { | 64 struct FontPlatformDataCacheKey { |
65 WTF_MAKE_FAST_ALLOCATED; | 65 WTF_MAKE_FAST_ALLOCATED; |
66 public: | 66 public: |
67 FontPlatformDataCacheKey(const AtomicString& family = AtomicString(), float size = 0, unsigned weight = 0, bool italic = false, | 67 FontPlatformDataCacheKey(const AtomicString& family = AtomicString(), float size = 0, unsigned weight = 0, bool italic = false, |
68 bool isPrinterFont = false, FontOrientation orientation = Horizontal, Fo ntWidthVariant widthVariant = RegularWidth) | 68 bool isPrinterFont = false, FontOrientation orientation = Horizontal, Fo ntWidthVariant widthVariant = RegularWidth, |
69 const AtomicString& locale = AtomicString()) | |
69 : m_size(size * s_fontSizePrecisionMultiplier) | 70 : m_size(size * s_fontSizePrecisionMultiplier) |
70 , m_weight(weight) | 71 , m_weight(weight) |
71 , m_family(family) | 72 , m_family(family) |
72 , m_italic(italic) | 73 , m_italic(italic) |
73 , m_printerFont(isPrinterFont) | 74 , m_printerFont(isPrinterFont) |
74 , m_orientation(orientation) | 75 , m_orientation(orientation) |
75 , m_widthVariant(widthVariant) | 76 , m_widthVariant(widthVariant) |
77 , m_locale(locale) | |
76 { | 78 { |
77 } | 79 } |
78 | 80 |
79 FontPlatformDataCacheKey(HashTableDeletedValueType) : m_size(hashTableDelete dSize()) { } | 81 FontPlatformDataCacheKey(HashTableDeletedValueType) : m_size(hashTableDelete dSize()) { } |
80 bool isHashTableDeletedValue() const { return m_size == hashTableDeletedSize (); } | 82 bool isHashTableDeletedValue() const { return m_size == hashTableDeletedSize (); } |
81 | 83 |
82 bool operator==(const FontPlatformDataCacheKey& other) const | 84 bool operator==(const FontPlatformDataCacheKey& other) const |
83 { | 85 { |
84 return equalIgnoringCase(m_family, other.m_family) && m_size == other.m_ size | 86 return equalIgnoringCase(m_family, other.m_family) && m_size == other.m_ size |
85 && m_weight == other.m_weight && m_italic == other.m_italic && m_pri nterFont == other.m_printerFont | 87 && m_weight == other.m_weight && m_italic == other.m_italic && m_pri nterFont == other.m_printerFont |
86 && m_orientation == other.m_orientation && m_widthVariant == other.m _widthVariant; | 88 && m_orientation == other.m_orientation && m_widthVariant == other.m _widthVariant |
89 && m_locale == other.m_locale; | |
87 } | 90 } |
88 | 91 |
89 unsigned m_size; | 92 unsigned m_size; |
90 unsigned m_weight; | 93 unsigned m_weight; |
91 AtomicString m_family; | 94 AtomicString m_family; |
92 bool m_italic; | 95 bool m_italic; |
93 bool m_printerFont; | 96 bool m_printerFont; |
94 FontOrientation m_orientation; | 97 FontOrientation m_orientation; |
95 FontWidthVariant m_widthVariant; | 98 FontWidthVariant m_widthVariant; |
99 // Only set for platforms (e.g. Android) that FontCache::getFontDataForChara cter() may return different FontData | |
100 // for different locales of FontDescriptions. | |
falken
2013/09/25 08:11:51
So eventually all platforms will want this? It see
| |
101 AtomicString m_locale; | |
eseidel
2013/09/25 15:51:13
So WebKit doesn't seem to key based on locale. I'
| |
96 | 102 |
97 private: | 103 private: |
98 // Multiplying the floating point size by 100 gives two decimal | 104 // Multiplying the floating point size by 100 gives two decimal |
99 // point precision which should be sufficient. | 105 // point precision which should be sufficient. |
100 static const unsigned s_fontSizePrecisionMultiplier = 100; | 106 static const unsigned s_fontSizePrecisionMultiplier = 100; |
101 | 107 |
102 static unsigned hashTableDeletedSize() { return 0xFFFFFFFFU; } | 108 static unsigned hashTableDeletedSize() { return 0xFFFFFFFFU; } |
103 }; | 109 }; |
104 | 110 |
105 inline unsigned computeHash(const FontPlatformDataCacheKey& fontKey) | 111 inline unsigned computeHash(const FontPlatformDataCacheKey& fontKey) |
eseidel
2013/09/25 15:49:52
This is webkit's impl:
http://trac.webkit.org/brow
| |
106 { | 112 { |
107 unsigned hashCodes[5] = { | 113 unsigned hashCodes[6] = { |
108 CaseFoldingHash::hash(fontKey.m_family), | 114 fontKey.m_family.isNull() ? 0 : CaseFoldingHash::hash(fontKey.m_family), |
109 fontKey.m_size, | 115 fontKey.m_size, |
110 fontKey.m_weight, | 116 fontKey.m_weight, |
111 fontKey.m_widthVariant, | 117 fontKey.m_widthVariant, |
112 static_cast<unsigned>(fontKey.m_orientation) << 2 | static_cast<unsigned >(fontKey.m_italic) << 1 | static_cast<unsigned>(fontKey.m_printerFont) | 118 static_cast<unsigned>(fontKey.m_orientation) << 2 | static_cast<unsigned >(fontKey.m_italic) << 1 | static_cast<unsigned>(fontKey.m_printerFont), |
119 fontKey.m_locale.isNull() ? 0 : CaseFoldingHash::hash(fontKey.m_locale) | |
113 }; | 120 }; |
114 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | 121 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
115 } | 122 } |
116 | 123 |
117 struct FontPlatformDataCacheKeyHash { | 124 struct FontPlatformDataCacheKeyHash { |
118 static unsigned hash(const FontPlatformDataCacheKey& font) | 125 static unsigned hash(const FontPlatformDataCacheKey& font) |
119 { | 126 { |
120 return computeHash(font); | 127 return computeHash(font); |
121 } | 128 } |
122 | 129 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 if (!gFontPlatformDataCache) { | 207 if (!gFontPlatformDataCache) { |
201 gFontPlatformDataCache = new FontPlatformDataCache; | 208 gFontPlatformDataCache = new FontPlatformDataCache; |
202 platformInit(); | 209 platformInit(); |
203 } | 210 } |
204 | 211 |
205 float fontSize; | 212 float fontSize; |
206 if (RuntimeEnabledFeatures::subpixelFontScalingEnabled()) | 213 if (RuntimeEnabledFeatures::subpixelFontScalingEnabled()) |
207 fontSize = fontDescription.computedSize(); | 214 fontSize = fontDescription.computedSize(); |
208 else | 215 else |
209 fontSize = fontDescription.computedPixelSize(); | 216 fontSize = fontDescription.computedPixelSize(); |
217 | |
210 FontPlatformDataCacheKey key(familyName, fontSize, fontDescription.weight(), fontDescription.italic(), | 218 FontPlatformDataCacheKey key(familyName, fontSize, fontDescription.weight(), fontDescription.italic(), |
211 | 219 fontDescription.usePrinterFont(), fontDescription.orientation(), fontDes cription.widthVariant(), |
212 fontDescription.usePrinterFont(), fontDescription.orientation(), fontDes cription.widthVariant()); | 220 #if OS(ANDROID) |
221 // On Android FontPlatformData from different locales need to be disting uished | |
222 // to avoid conflict of glyphs from different locale-perferred fallback fonts. | |
falken
2013/09/25 08:11:51
s/perferred/preferred
I think comment can use ela
| |
223 fontDescription.locale()); | |
224 #else | |
225 AtomicString()); | |
226 #endif | |
213 FontPlatformData* result = 0; | 227 FontPlatformData* result = 0; |
214 bool foundResult; | 228 bool foundResult; |
215 FontPlatformDataCache::iterator it = gFontPlatformDataCache->find(key); | 229 FontPlatformDataCache::iterator it = gFontPlatformDataCache->find(key); |
216 if (it == gFontPlatformDataCache->end()) { | 230 if (it == gFontPlatformDataCache->end()) { |
217 result = createFontPlatformData(fontDescription, familyName); | 231 result = createFontPlatformData(fontDescription, familyName); |
218 gFontPlatformDataCache->set(key, result); | 232 gFontPlatformDataCache->set(key, result); |
219 foundResult = result; | 233 foundResult = result; |
220 } else { | 234 } else { |
221 result = it->value; | 235 result = it->value; |
222 foundResult = true; | 236 foundResult = true; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 case FontDescription::SansSerifFamily: | 604 case FontDescription::SansSerifFamily: |
591 default: | 605 default: |
592 fontPlatformData = getFontResourcePlatformData(description, sansStr); | 606 fontPlatformData = getFontResourcePlatformData(description, sansStr); |
593 break; | 607 break; |
594 } | 608 } |
595 | 609 |
596 return fontPlatformData; | 610 return fontPlatformData; |
597 } | 611 } |
598 | 612 |
599 } // namespace WebCore | 613 } // namespace WebCore |
OLD | NEW |