OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 USING_FAST_MALLOC(FontSetCache); | 226 USING_FAST_MALLOC(FontSetCache); |
227 public: | 227 public: |
228 static FontSetCache& shared() | 228 static FontSetCache& shared() |
229 { | 229 { |
230 DEFINE_STATIC_LOCAL(FontSetCache, cache, ()); | 230 DEFINE_STATIC_LOCAL(FontSetCache, cache, ()); |
231 return cache; | 231 return cache; |
232 } | 232 } |
233 | 233 |
234 WebFallbackFont fallbackFontForCharInLocale(WebUChar32 c, const char* locale
) | 234 WebFallbackFont fallbackFontForCharInLocale(WebUChar32 c, const char* locale
) |
235 { | 235 { |
236 DEFINE_STATIC_LOCAL(AtomicString, kNoLocale, ("NO_LOCALE_SPECIFIED", Ato
micString::ConstructFromLiteral)); | 236 DEFINE_STATIC_LOCAL(AtomicString, noLocale, ("NO_LOCALE_SPECIFIED", Atom
icString::ConstructFromLiteral)); |
237 AtomicString localeKey; | 237 AtomicString localeKey; |
238 if (locale && strlen(locale)) { | 238 if (locale && strlen(locale)) { |
239 localeKey = AtomicString(locale); | 239 localeKey = AtomicString(locale); |
240 } else { | 240 } else { |
241 // String hash computation the m_setsByLocale map needs | 241 // String hash computation the m_setsByLocale map needs |
242 // a non-empty string. | 242 // a non-empty string. |
243 localeKey = kNoLocale; | 243 localeKey = noLocale; |
244 } | 244 } |
245 | 245 |
246 LocaleToCachedFont::iterator itr = m_setsByLocale.find(localeKey); | 246 LocaleToCachedFont::iterator itr = m_setsByLocale.find(localeKey); |
247 if (itr == m_setsByLocale.end()) { | 247 if (itr == m_setsByLocale.end()) { |
248 OwnPtr<CachedFontSet> newEntry = CachedFontSet::createForLocale(strl
en(locale) ? locale : 0); | 248 OwnPtr<CachedFontSet> newEntry = CachedFontSet::createForLocale(strl
en(locale) ? locale : 0); |
249 return m_setsByLocale.add(localeKey, newEntry.release()).storedValue
->value->fallbackFontForChar(c); | 249 return m_setsByLocale.add(localeKey, newEntry.release()).storedValue
->value->fallbackFontForChar(c); |
250 } | 250 } |
251 return itr.get()->value->fallbackFontForChar(c); | 251 return itr.get()->value->fallbackFontForChar(c); |
252 } | 252 } |
253 // FIXME: We may wish to add a way to prune the cache at a later time. | 253 // FIXME: We may wish to add a way to prune the cache at a later time. |
254 | 254 |
255 private: | 255 private: |
256 FontSetCache() { } | 256 FontSetCache() { } |
257 | 257 |
258 // FIXME: This shouldn't need to be AtomicString, but | 258 // FIXME: This shouldn't need to be AtomicString, but |
259 // currently HashTraits<const char*> isn't smart enough | 259 // currently HashTraits<const char*> isn't smart enough |
260 // to hash the string (only does pointer compares). | 260 // to hash the string (only does pointer compares). |
261 typedef HashMap<AtomicString, OwnPtr<CachedFontSet>> LocaleToCachedFont; | 261 typedef HashMap<AtomicString, OwnPtr<CachedFontSet>> LocaleToCachedFont; |
262 LocaleToCachedFont m_setsByLocale; | 262 LocaleToCachedFont m_setsByLocale; |
263 }; | 263 }; |
264 | 264 |
265 void WebFontInfo::fallbackFontForChar(WebUChar32 c, const char* locale, WebFallb
ackFont* fallbackFont) | 265 void WebFontInfo::fallbackFontForChar(WebUChar32 c, const char* locale, WebFallb
ackFont* fallbackFont) |
266 { | 266 { |
267 *fallbackFont = FontSetCache::shared().fallbackFontForCharInLocale(c, locale
); | 267 *fallbackFont = FontSetCache::shared().fallbackFontForCharInLocale(c, locale
); |
268 } | 268 } |
269 | 269 |
270 } // namespace blink | 270 } // namespace blink |
OLD | NEW |