Index: content/common/font_cache_dispatcher_win.cc |
=================================================================== |
--- content/common/font_cache_dispatcher_win.cc (revision 158204) |
+++ content/common/font_cache_dispatcher_win.cc (working copy) |
@@ -4,12 +4,14 @@ |
#include "content/common/font_cache_dispatcher_win.h" |
+#include <string> |
#include <vector> |
#include <map> |
#include "base/logging.h" |
#include "base/string16.h" |
#include "content/common/child_process_messages.h" |
+#include "content/common/view_messages.h" |
namespace { |
typedef std::vector<string16> FontNameVector; |
@@ -96,6 +98,31 @@ |
} |
} |
+ void PreCacheFontCharacters(const LOGFONT& font, |
+ const std::wstring& str, |
+ FontCacheDispatcher* dispatcher) { |
+ // The only way windows seem to load properly, it is to create a similar |
+ // device (like the one in which we print), then do an ExtTextOut, |
+ // as we do in the printing thread, which is sandboxed. |
+ HDC hdc = CreateEnhMetaFile(NULL, NULL, NULL, NULL); |
+ HFONT font_handle = CreateFontIndirect(&font); |
+ DCHECK(NULL != font_handle); |
+ |
+ HGDIOBJ old_font = SelectObject(hdc, font_handle); |
+ DCHECK(NULL != old_font); |
+ |
+ ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, str.c_str(), str.length(), NULL); |
+ |
+ SelectObject(hdc, old_font); |
+ DeleteObject(font_handle); |
+ |
+ HENHMETAFILE metafile = CloseEnhMetaFile(hdc); |
+ |
+ if (metafile) { |
+ DeleteEnhMetaFile(metafile); |
+ } |
+ } |
+ |
private: |
struct CacheElement { |
CacheElement() |
@@ -150,6 +177,8 @@ |
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_PreCacheFont, OnPreCacheFont) |
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ReleaseCachedFonts, |
OnReleaseCachedFonts) |
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PreCacheFontCharacters, |
+ OnPreCacheFontCharacters) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
return handled; |
@@ -184,6 +213,17 @@ |
FontCache::GetInstance()->PreCacheFont(font, this); |
} |
+void FontCacheDispatcher::OnPreCacheFontCharacters(const LOGFONT& font, |
+ const std::wstring& str) { |
+ // First, comments from FontCacheDispatcher::OnPreCacheFont do apply here too. |
+ // Except that for True Type fonts, |
+ // GetTextMetrics will not load the font in memory. |
+ // The only way windows seem to load properly, it is to create a similar |
+ // device (like the one in which we print), then do an ExtTextOut, |
+ // as we do in the printing thread, which is sandboxed. |
+ FontCache::GetInstance()->PreCacheFontCharacters(font, str, this); |
+} |
+ |
void FontCacheDispatcher::OnReleaseCachedFonts() { |
// Release cached fonts that requested from a pid by decrementing the ref |
// count. When ref count is zero, the handles are released. |