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

Unified Diff: ui/gfx/win/direct_write.cc

Issue 738363002: Enable subpixel positioning for UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: std::round to std::floor(+0.5) Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/win/direct_write.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/win/direct_write.cc
diff --git a/ui/gfx/win/direct_write.cc b/ui/gfx/win/direct_write.cc
index 058f4be01deeaf50d02e11e2682cc4882c6f6b36..207b2c165b542c7811512add11e6e93d759403e3 100644
--- a/ui/gfx/win/direct_write.cc
+++ b/ui/gfx/win/direct_write.cc
@@ -4,11 +4,17 @@
#include "ui/gfx/win/direct_write.h"
+#include <dwrite.h>
+
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/win/registry.h"
+#include "base/win/scoped_comptr.h"
#include "base/win/windows_version.h"
+#include "skia/ext/fontmgr_default_win.h"
+#include "third_party/skia/include/ports/SkTypeface_win.h"
+#include "ui/gfx/platform_font_win.h"
#include "ui/gfx/switches.h"
#include "ui/gfx/win/dpi.h"
@@ -59,5 +65,49 @@ bool ShouldUseDirectWrite() {
return group_name != "Disabled";
}
+void MaybeInitializeDirectWrite() {
+ static bool tried_dwrite_initialize = false;
+ if (tried_dwrite_initialize)
+ return;
+ tried_dwrite_initialize = true;
+
+ if (!ShouldUseDirectWrite() ||
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableDirectWriteForUI) ||
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableHarfBuzzRenderText)) {
+ return;
+ }
+
+ using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
+ HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
+ if (!dwrite_dll)
+ return;
+
+ DWriteCreateFactoryProc dwrite_create_factory_proc =
+ reinterpret_cast<DWriteCreateFactoryProc>(
+ GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
+ // Not finding the DWriteCreateFactory function indicates a corrupt dll.
+ CHECK(dwrite_create_factory_proc);
+
+ base::win::ScopedComPtr<IDWriteFactory> factory;
+
+ CHECK(SUCCEEDED(
+ dwrite_create_factory_proc(
+ DWRITE_FACTORY_TYPE_SHARED,
+ __uuidof(IDWriteFactory),
+ reinterpret_cast<IUnknown**>(factory.Receive()))));
+ // The skia call to create a new DirectWrite font manager instance can fail
+ // if we are unable to get the system font collection from the DirectWrite
+ // factory. The GetSystemFontCollection method in the IDWriteFactory
+ // interface fails with E_INVALIDARG on certain Windows 7 gold versions
+ // (6.1.7600.*). We should just use GDI in these cases.
+ SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get());
+ if (direct_write_font_mgr) {
+ SetDefaultSkiaFactory(direct_write_font_mgr);
+ gfx::PlatformFontWin::SetDirectWriteFactory(factory.get());
+ }
+}
+
} // namespace win
} // namespace gfx
« no previous file with comments | « ui/gfx/win/direct_write.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698