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

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

Issue 2029343002: Link to DirectWrite directly, instead of calling LoadLibrary (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove global IDWriteFactory 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
34 // Queries the registry to get a mapping from font filenames to font names. 32 // Queries the registry to get a mapping from font filenames to font names.
35 void QueryFontsFromRegistry(std::map<std::string, std::string>* map) { 33 void QueryFontsFromRegistry(std::map<std::string, std::string>* map) {
36 const wchar_t* kFonts = 34 const wchar_t* kFonts =
37 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; 35 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
38 36
39 base::win::RegistryValueIterator it(HKEY_LOCAL_MACHINE, kFonts); 37 base::win::RegistryValueIterator it(HKEY_LOCAL_MACHINE, kFonts);
40 for (; it.Valid(); ++it) { 38 for (; it.Valid(); ++it) {
41 const std::string filename = 39 const std::string filename =
42 base::ToLowerASCII(base::WideToUTF8(it.Value())); 40 base::ToLowerASCII(base::WideToUTF8(it.Value()));
43 (*map)[filename] = base::WideToUTF8(it.Name()); 41 (*map)[filename] = base::WideToUTF8(it.Name());
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 bool GetFallbackFont(const Font& font, 341 bool GetFallbackFont(const Font& font,
344 const wchar_t* text, 342 const wchar_t* text,
345 int text_length, 343 int text_length,
346 Font* result) { 344 Font* result) {
347 // Creating a DirectWrite font fallback can be expensive. It's ok in the 345 // Creating a DirectWrite font fallback can be expensive. It's ok in the
348 // browser process because we can use the shared system fallback, but in the 346 // browser process because we can use the shared system fallback, but in the
349 // renderer this can cause hangs. Code that needs font fallback in the 347 // renderer this can cause hangs. Code that needs font fallback in the
350 // renderer should instead use the font proxy. 348 // renderer should instead use the font proxy.
351 DCHECK(base::MessageLoopForUI::IsCurrent()); 349 DCHECK(base::MessageLoopForUI::IsCurrent());
352 350
353 if (g_factory == nullptr) { 351 base::win::ScopedComPtr<IDWriteFactory> factory;
354 gfx::win::CreateDWriteFactory(&g_factory); 352 gfx::win::CreateDWriteFactory(factory.Receive());
355 }
356 base::win::ScopedComPtr<IDWriteFactory2> factory2; 353 base::win::ScopedComPtr<IDWriteFactory2> factory2;
357 g_factory->QueryInterface(factory2.Receive()); 354 factory.QueryInterface(factory2.Receive());
358 if (!factory2) { 355 if (!factory2) {
359 // IDWriteFactory2 is not available before Win8.1 356 // IDWriteFactory2 is not available before Win8.1
360 return GetUniscribeFallbackFont(font, text, text_length, result); 357 return GetUniscribeFallbackFont(font, text, text_length, result);
361 } 358 }
362 359
363 base::win::ScopedComPtr<IDWriteFontFallback> fallback; 360 base::win::ScopedComPtr<IDWriteFontFallback> fallback;
364 if (FAILED(factory2->GetSystemFontFallback(fallback.Receive()))) 361 if (FAILED(factory2->GetSystemFontFallback(fallback.Receive())))
365 return false; 362 return false;
366 363
367 base::string16 locale = base::UTF8ToUTF16(base::i18n::GetConfiguredLocale()); 364 base::string16 locale = base::UTF8ToUTF16(base::i18n::GetConfiguredLocale());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 base::string16 name; 398 base::string16 name;
402 if (FAILED(GetFamilyNameFromDirectWriteFont(mapped_font.get(), &name))) 399 if (FAILED(GetFamilyNameFromDirectWriteFont(mapped_font.get(), &name)))
403 return false; 400 return false;
404 *result = Font(base::UTF16ToUTF8(name), font.GetFontSize() * scale); 401 *result = Font(base::UTF16ToUTF8(name), font.GetFontSize() * scale);
405 return true; 402 return true;
406 } 403 }
407 return false; 404 return false;
408 } 405 }
409 406
410 } // namespace gfx 407 } // 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