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

Unified Diff: content/common/font_cache_dispatcher_win.cc

Issue 11363008: Fix for 128506: Random Chinese/Japanese characters are missing in documents printed via the syst... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698