Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Side by Side Diff: webkit/port/platform/graphics/chromium/FontUtilsChromiumWin.cpp

Issue 14410: Fix purify complaint about FontData structs being leaked. These are held in ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "FontUtilsChromiumWin.h" 6 #include "FontUtilsChromiumWin.h"
7 7
8 #include <limits> 8 #include <limits>
9 9
10 #include "PlatformString.h" 10 #include "PlatformString.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 HFONT hfont; 113 HFONT hfont;
114 int ascent; 114 int ascent;
115 mutable SCRIPT_CACHE scriptCache; 115 mutable SCRIPT_CACHE scriptCache;
116 }; 116 };
117 117
118 // Again, using hash_map does not earn us much here. page_cycler_test intl2 118 // Again, using hash_map does not earn us much here. page_cycler_test intl2
119 // gave us a 'better' result with map than with hash_map even though they're 119 // gave us a 'better' result with map than with hash_map even though they're
120 // well-within 1-sigma of each other so that the difference is not significant. 120 // well-within 1-sigma of each other so that the difference is not significant.
121 // On the other hand, some pages in intl2 seem to take longer to load with map 121 // On the other hand, some pages in intl2 seem to take longer to load with map
122 // in the 1st pass. Need to experiment further. 122 // in the 1st pass. Need to experiment further.
123 typedef HashMap<String, FontData*> FontDataCache; 123 typedef HashMap<String, FontData> FontDataCache;
124 124
125 } // namespace 125 } // namespace
126 126
127 // TODO(jungshik) : this is font fallback code version 0.1 127 // TODO(jungshik) : this is font fallback code version 0.1
128 // - Cover all the scripts 128 // - Cover all the scripts
129 // - Get the default font for each script/generic family from the 129 // - Get the default font for each script/generic family from the
130 // preference instead of hardcoding in the source. 130 // preference instead of hardcoding in the source.
131 // (at least, read values from the registry for IE font settings). 131 // (at least, read values from the registry for IE font settings).
132 // - Support generic families (from FontDescription) 132 // - Support generic families (from FontDescription)
133 // - If the default font for a script is not available, 133 // - If the default font for a script is not available,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 String fontKey = String::format("%1d:%d:%ls", style, logfont->lfHeight, fami ly); 270 String fontKey = String::format("%1d:%d:%ls", style, logfont->lfHeight, fami ly);
271 FontDataCache::iterator iter = fontDataCache.find(fontKey); 271 FontDataCache::iterator iter = fontDataCache.find(fontKey);
272 FontData *derived; 272 FontData *derived;
273 if (iter == fontDataCache.end()) { 273 if (iter == fontDataCache.end()) {
274 ASSERT(wcslen(family) < LF_FACESIZE); 274 ASSERT(wcslen(family) < LF_FACESIZE);
275 wcscpy_s(logfont->lfFaceName, LF_FACESIZE, family); 275 wcscpy_s(logfont->lfFaceName, LF_FACESIZE, family);
276 // TODO(jungshik): CreateFontIndirect always comes up with 276 // TODO(jungshik): CreateFontIndirect always comes up with
277 // a font even if there's no font matching the name. Need to 277 // a font even if there's no font matching the name. Need to
278 // check it against what we actually want (as is done in 278 // check it against what we actually want (as is done in
279 // FontCacheWin.cpp) 279 // FontCacheWin.cpp)
280 derived = new FontData; 280 pair<FontDataCache::iterator, bool> entry = fontDataCache.add(fontKey, F ontData());
281 derived = &entry.first->second;
281 derived->hfont = CreateFontIndirect(logfont); 282 derived->hfont = CreateFontIndirect(logfont);
282 // GetAscent may return kUndefinedAscent, but we still want to 283 // GetAscent may return kUndefinedAscent, but we still want to
283 // cache it so that we won't have to call CreateFontIndirect once 284 // cache it so that we won't have to call CreateFontIndirect once
284 // more for HFONT next time. 285 // more for HFONT next time.
285 derived->ascent = GetAscent(derived->hfont); 286 derived->ascent = GetAscent(derived->hfont);
286 fontDataCache.add(fontKey, derived);
287 } else { 287 } else {
288 derived = iter->second; 288 derived = &iter->second;
289 // Last time, GetAscent failed so that only HFONT was 289 // Last time, GetAscent failed so that only HFONT was
290 // cached. Try once more assuming that TryPreloadFont 290 // cached. Try once more assuming that TryPreloadFont
291 // was called by a caller between calls. 291 // was called by a caller between calls.
292 if (kUndefinedAscent == derived->ascent) 292 if (kUndefinedAscent == derived->ascent)
293 derived->ascent = GetAscent(derived->hfont); 293 derived->ascent = GetAscent(derived->hfont);
294 } 294 }
295 *hfont = derived->hfont; 295 *hfont = derived->hfont;
296 *ascent = derived->ascent; 296 *ascent = derived->ascent;
297 *scriptCache = &(derived->scriptCache); 297 *scriptCache = &(derived->scriptCache);
298 return *ascent != kUndefinedAscent; 298 return *ascent != kUndefinedAscent;
299 } 299 }
300 300
301 int GetStyleFromLogfont(const LOGFONT* logfont) { 301 int GetStyleFromLogfont(const LOGFONT* logfont) {
302 // TODO(jungshik) : consider defining UNDEFINED or INVALID for style and 302 // TODO(jungshik) : consider defining UNDEFINED or INVALID for style and
303 // returning it when logfont is NULL 303 // returning it when logfont is NULL
304 if (!logfont) { 304 if (!logfont) {
305 ASSERT_NOT_REACHED(); 305 ASSERT_NOT_REACHED();
306 return FONT_STYLE_NORMAL; 306 return FONT_STYLE_NORMAL;
307 } 307 }
308 return (logfont->lfItalic ? FONT_STYLE_ITALIC : FONT_STYLE_NORMAL) | 308 return (logfont->lfItalic ? FONT_STYLE_ITALIC : FONT_STYLE_NORMAL) |
309 (logfont->lfUnderline ? FONT_STYLE_UNDERLINED : FONT_STYLE_NORMAL) | 309 (logfont->lfUnderline ? FONT_STYLE_UNDERLINED : FONT_STYLE_NORMAL) |
310 (logfont->lfWeight >= 700 ? FONT_STYLE_BOLD : FONT_STYLE_NORMAL); 310 (logfont->lfWeight >= 700 ? FONT_STYLE_BOLD : FONT_STYLE_NORMAL);
311 } 311 }
312 312
313 } // namespace WebCore 313 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698