31 |
31 |
32 #include "Font.h" |
32 #include "Font.h" |
33 #include "FontFallbackList.h" |
33 #include "FontFallbackList.h" |
34 #include "FontPlatformData.h" |
34 #include "FontPlatformData.h" |
35 #include "StringHash.h" |
35 #include "StringHash.h" |
|
36 #include "staticobjectscontainer.h" |
36 #include <wtf/HashMap.h> |
37 #include <wtf/HashMap.h> |
37 |
38 |
38 namespace WebCore { |
39 namespace WebCore { |
39 |
40 |
40 struct FontPlatformDataCacheKey { |
41 struct FontPlatformDataCacheKey { |
97 return key; |
98 return key; |
98 } |
99 } |
99 }; |
100 }; |
100 |
101 |
101 typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache; |
102 typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache; |
|
103 typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits>::iterator FontPlatformDataCacheIterator; |
102 |
104 |
103 static FontPlatformDataCache* gFontPlatformDataCache = 0; |
105 static FontPlatformDataCache* gFontPlatformDataCache = 0; |
|
106 |
|
107 struct cleanupFontDataCache { |
|
108 ~cleanupFontDataCache() { |
|
109 if( gFontPlatformDataCache ) |
|
110 { |
|
111 FontPlatformDataCacheIterator end = gFontPlatformDataCache->end(); |
|
112 for (FontPlatformDataCacheIterator it = gFontPlatformDataCache->begin(); it != end; ++it) |
|
113 { |
|
114 FontPlatformData* obj = (*it).second; |
|
115 delete obj; |
|
116 } |
|
117 gFontPlatformDataCache->clear(); |
|
118 delete gFontPlatformDataCache; |
|
119 gFontPlatformDataCache=0; |
|
120 } |
|
121 } |
|
122 }; |
|
123 static cleanupFontDataCache cleanFontDataCache; |
104 |
124 |
105 static const AtomicString& alternateFamilyName(const AtomicString& familyName) |
125 static const AtomicString& alternateFamilyName(const AtomicString& familyName) |
106 { |
126 { |
107 #if PLATFORM(SYMBIAN) |
127 #if PLATFORM(SYMBIAN) |
108 return FontCache::systemFontFamilyName( familyName ); |
128 return FontCache::systemFontFamilyName( familyName ); |
136 const AtomicString& familyName, |
156 const AtomicString& familyName, |
137 bool checkingAlternateName) |
157 bool checkingAlternateName) |
138 { |
158 { |
139 if (!gFontPlatformDataCache) { |
159 if (!gFontPlatformDataCache) { |
140 gFontPlatformDataCache = new FontPlatformDataCache; |
160 gFontPlatformDataCache = new FontPlatformDataCache; |
141 platformInit(); |
|
142 } |
161 } |
143 |
162 |
144 FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.bold(), fontDescription.italic(), |
163 FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.bold(), fontDescription.italic(), |
145 fontDescription.usePrinterFont()); |
164 fontDescription.usePrinterFont()); |
146 FontPlatformData* result = 0; |
165 FontPlatformData* result = 0; |
195 return key; |
214 return key; |
196 } |
215 } |
197 }; |
216 }; |
198 |
217 |
199 typedef HashMap<FontPlatformData, FontData*, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache; |
218 typedef HashMap<FontPlatformData, FontData*, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache; |
200 |
219 typedef HashMap<FontPlatformData, FontData*, FontDataCacheKeyHash, FontDataCacheKeyTraits>::iterator FontDataCacheIterator; |
201 static FontDataCache* gFontDataCache = 0; |
220 static FontDataCache* gFontDataCache = 0; |
202 |
221 |
203 FontData* FontCache::getCachedFontData(const FontPlatformData* platformData) |
222 FontData* FontCache::getCachedFontData(const FontPlatformData* platformData) |
204 { |
223 { |
205 if (!platformData) |
224 if (!platformData) |
213 result = new FontData(*platformData); |
232 result = new FontData(*platformData); |
214 gFontDataCache->set(*platformData, result); |
233 gFontDataCache->set(*platformData, result); |
215 } |
234 } |
216 |
235 |
217 return result; |
236 return result; |
|
237 } |
|
238 |
|
239 void FontCache::deleteFontDataCache() |
|
240 { |
|
241 if( gFontDataCache ) { |
|
242 FontDataCacheIterator end = gFontDataCache->end(); |
|
243 for (FontDataCacheIterator it = gFontDataCache->begin(); it != end; ++it) { |
|
244 FontData* obj = (*it).second; |
|
245 delete obj; |
|
246 } |
|
247 } |
|
248 delete gFontDataCache; |
|
249 gFontDataCache = NULL; |
218 } |
250 } |
219 |
251 |
220 const FontData* FontCache::getFontData(const Font& font, int& familyIndex) |
252 const FontData* FontCache::getFontData(const Font& font, int& familyIndex) |
221 { |
253 { |
222 FontPlatformData* result = 0; |
254 FontPlatformData* result = 0; |