webengine/osswebengine/WebCore/platform/FontCache.cpp
changeset 13 10e98eab6f85
parent 0 dd21522fd290
child 16 a359256acfc6
--- a/webengine/osswebengine/WebCore/platform/FontCache.cpp	Fri May 08 08:25:06 2009 +0300
+++ b/webengine/osswebengine/WebCore/platform/FontCache.cpp	Fri Jul 03 15:54:40 2009 +0100
@@ -33,6 +33,7 @@
 #include "FontFallbackList.h"
 #include "FontPlatformData.h"
 #include "StringHash.h"
+#include "staticobjectscontainer.h"
 #include <wtf/HashMap.h>
 
 namespace WebCore {
@@ -99,9 +100,28 @@
 };
 
 typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
+typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits>::iterator FontPlatformDataCacheIterator;
 
 static FontPlatformDataCache* gFontPlatformDataCache = 0;
 
+struct cleanupFontDataCache {
+    ~cleanupFontDataCache() {
+        if( gFontPlatformDataCache ) 
+        {
+			FontPlatformDataCacheIterator end = gFontPlatformDataCache->end();
+			for (FontPlatformDataCacheIterator it = gFontPlatformDataCache->begin(); it != end; ++it) 
+				{
+				FontPlatformData* obj = (*it).second;
+				delete obj;
+				}
+          gFontPlatformDataCache->clear();
+          delete gFontPlatformDataCache;
+          gFontPlatformDataCache=0;
+        }
+    }
+};
+static cleanupFontDataCache cleanFontDataCache;
+
 static const AtomicString& alternateFamilyName(const AtomicString& familyName)
 {
 #if PLATFORM(SYMBIAN)
@@ -138,7 +158,6 @@
 {
     if (!gFontPlatformDataCache) {
         gFontPlatformDataCache = new FontPlatformDataCache;
-        platformInit();
     }
 
     FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.bold(), fontDescription.italic(),
@@ -197,7 +216,7 @@
 };
 
 typedef HashMap<FontPlatformData, FontData*, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache;
-
+typedef HashMap<FontPlatformData, FontData*, FontDataCacheKeyHash, FontDataCacheKeyTraits>::iterator FontDataCacheIterator;
 static FontDataCache* gFontDataCache = 0;
 
 FontData* FontCache::getCachedFontData(const FontPlatformData* platformData)
@@ -217,6 +236,19 @@
     return result;
 }
 
+void FontCache::deleteFontDataCache() 
+{
+    if( gFontDataCache ) {
+        FontDataCacheIterator end = gFontDataCache->end();
+        for (FontDataCacheIterator it = gFontDataCache->begin(); it != end; ++it) {
+            FontData* obj = (*it).second;
+            delete obj;
+        }
+    }
+    delete gFontDataCache;
+    gFontDataCache = NULL;
+}
+
 const FontData* FontCache::getFontData(const Font& font, int& familyIndex)
 {
     FontPlatformData* result = 0;