diff options
Diffstat (limited to 'WebCore/platform/graphics/qt/FontCacheQt.cpp')
-rw-r--r-- | WebCore/platform/graphics/qt/FontCacheQt.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/WebCore/platform/graphics/qt/FontCacheQt.cpp b/WebCore/platform/graphics/qt/FontCacheQt.cpp index 114f073..668912e 100644 --- a/WebCore/platform/graphics/qt/FontCacheQt.cpp +++ b/WebCore/platform/graphics/qt/FontCacheQt.cpp @@ -26,8 +26,11 @@ #include "FontDescription.h" #include "FontPlatformData.h" #include "Font.h" +#include "StringHash.h" #include <wtf/StdLibExtras.h> +#include <QHash> + namespace WebCore { FontCache* fontCache() @@ -44,9 +47,31 @@ void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigne { } +typedef QHash<FontDescription, FontPlatformData*> FontPlatformDataCache; + +// using Q_GLOBAL_STATIC leads to crash. TODO investigate the way to fix this. +static FontPlatformDataCache* gFontPlatformDataCache; + +uint qHash(const FontDescription& key) +{ + uint value = CaseFoldingHash::hash(key.family().family()); + value ^= key.computedPixelSize(); + value ^= static_cast<int>(key.weight()); + return value; +} + FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& description, const AtomicString& family, bool checkingAlternateName) { - return new FontPlatformData(description); + if (!gFontPlatformDataCache) + gFontPlatformDataCache = new FontPlatformDataCache; + + FontPlatformData* fontData = gFontPlatformDataCache->value(description, 0); + if (!fontData) { + fontData = new FontPlatformData(description); + gFontPlatformDataCache->insert(description, fontData); + } + + return fontData; } SimpleFontData* FontCache::getCachedFontData(const FontPlatformData*) @@ -71,4 +96,12 @@ void FontCache::removeClient(FontSelector*) { } +void FontCache::invalidate() +{ + if (!gFontPlatformDataCache) + return; + + gFontPlatformDataCache->clear(); +} + } // namespace WebCore |