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

Side by Side Diff: ui/gfx/font_fallback_win.cc

Issue 2117683002: Revert of Link to DirectWrite directly, instead of calling LoadLibrary (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months 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
« no previous file with comments | « ui/gfx/BUILD.gn ('k') | ui/gfx/gfx.gyp » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/font_fallback_win.h" 5 #include "ui/gfx/font_fallback_win.h"
6 6
7 #include <dwrite_2.h> 7 #include <dwrite_2.h>
8 #include <usp10.h> 8 #include <usp10.h>
9 #include <wrl.h> 9 #include <wrl.h>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "ui/gfx/font.h" 22 #include "ui/gfx/font.h"
23 #include "ui/gfx/font_fallback.h" 23 #include "ui/gfx/font_fallback.h"
24 #include "ui/gfx/platform_font_win.h" 24 #include "ui/gfx/platform_font_win.h"
25 #include "ui/gfx/win/direct_write.h" 25 #include "ui/gfx/win/direct_write.h"
26 #include "ui/gfx/win/text_analysis_source.h" 26 #include "ui/gfx/win/text_analysis_source.h"
27 27
28 namespace gfx { 28 namespace gfx {
29 29
30 namespace { 30 namespace {
31 31
32 IDWriteFactory* g_factory = nullptr;
33
32 // Queries the registry to get a mapping from font filenames to font names. 34 // Queries the registry to get a mapping from font filenames to font names.
33 void QueryFontsFromRegistry(std::map<std::string, std::string>* map) { 35 void QueryFontsFromRegistry(std::map<std::string, std::string>* map) {
34 const wchar_t* kFonts = 36 const wchar_t* kFonts =
35 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; 37 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
36 38
37 base::win::RegistryValueIterator it(HKEY_LOCAL_MACHINE, kFonts); 39 base::win::RegistryValueIterator it(HKEY_LOCAL_MACHINE, kFonts);
38 for (; it.Valid(); ++it) { 40 for (; it.Valid(); ++it) {
39 const std::string filename = 41 const std::string filename =
40 base::ToLowerASCII(base::WideToUTF8(it.Value())); 42 base::ToLowerASCII(base::WideToUTF8(it.Value()));
41 (*map)[filename] = base::WideToUTF8(it.Name()); 43 (*map)[filename] = base::WideToUTF8(it.Name());
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 bool GetFallbackFont(const Font& font, 343 bool GetFallbackFont(const Font& font,
342 const wchar_t* text, 344 const wchar_t* text,
343 int text_length, 345 int text_length,
344 Font* result) { 346 Font* result) {
345 // Creating a DirectWrite font fallback can be expensive. It's ok in the 347 // Creating a DirectWrite font fallback can be expensive. It's ok in the
346 // browser process because we can use the shared system fallback, but in the 348 // browser process because we can use the shared system fallback, but in the
347 // renderer this can cause hangs. Code that needs font fallback in the 349 // renderer this can cause hangs. Code that needs font fallback in the
348 // renderer should instead use the font proxy. 350 // renderer should instead use the font proxy.
349 DCHECK(base::MessageLoopForUI::IsCurrent()); 351 DCHECK(base::MessageLoopForUI::IsCurrent());
350 352
351 base::win::ScopedComPtr<IDWriteFactory> factory; 353 if (g_factory == nullptr) {
352 gfx::win::CreateDWriteFactory(factory.Receive()); 354 gfx::win::CreateDWriteFactory(&g_factory);
355 }
353 base::win::ScopedComPtr<IDWriteFactory2> factory2; 356 base::win::ScopedComPtr<IDWriteFactory2> factory2;
354 factory.QueryInterface(factory2.Receive()); 357 g_factory->QueryInterface(factory2.Receive());
355 if (!factory2) { 358 if (!factory2) {
356 // IDWriteFactory2 is not available before Win8.1 359 // IDWriteFactory2 is not available before Win8.1
357 return GetUniscribeFallbackFont(font, text, text_length, result); 360 return GetUniscribeFallbackFont(font, text, text_length, result);
358 } 361 }
359 362
360 base::win::ScopedComPtr<IDWriteFontFallback> fallback; 363 base::win::ScopedComPtr<IDWriteFontFallback> fallback;
361 if (FAILED(factory2->GetSystemFontFallback(fallback.Receive()))) 364 if (FAILED(factory2->GetSystemFontFallback(fallback.Receive())))
362 return false; 365 return false;
363 366
364 base::string16 locale = base::UTF8ToUTF16(base::i18n::GetConfiguredLocale()); 367 base::string16 locale = base::UTF8ToUTF16(base::i18n::GetConfiguredLocale());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 base::string16 name; 401 base::string16 name;
399 if (FAILED(GetFamilyNameFromDirectWriteFont(mapped_font.get(), &name))) 402 if (FAILED(GetFamilyNameFromDirectWriteFont(mapped_font.get(), &name)))
400 return false; 403 return false;
401 *result = Font(base::UTF16ToUTF8(name), font.GetFontSize() * scale); 404 *result = Font(base::UTF16ToUTF8(name), font.GetFontSize() * scale);
402 return true; 405 return true;
403 } 406 }
404 return false; 407 return false;
405 } 408 }
406 409
407 } // namespace gfx 410 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/BUILD.gn ('k') | ui/gfx/gfx.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698