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

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

Issue 2111373002: Reland of Link to DirectWrite directly, instead of calling LoadLibrary (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 12 matching lines...) Expand all
23 #include "ui/gfx/font.h" 23 #include "ui/gfx/font.h"
24 #include "ui/gfx/font_fallback.h" 24 #include "ui/gfx/font_fallback.h"
25 #include "ui/gfx/platform_font_win.h" 25 #include "ui/gfx/platform_font_win.h"
26 #include "ui/gfx/win/direct_write.h" 26 #include "ui/gfx/win/direct_write.h"
27 #include "ui/gfx/win/text_analysis_source.h" 27 #include "ui/gfx/win/text_analysis_source.h"
28 28
29 namespace gfx { 29 namespace gfx {
30 30
31 namespace { 31 namespace {
32 32
33 IDWriteFactory* g_factory = nullptr;
34
35 // Queries the registry to get a mapping from font filenames to font names. 33 // Queries the registry to get a mapping from font filenames to font names.
36 void QueryFontsFromRegistry(std::map<std::string, std::string>* map) { 34 void QueryFontsFromRegistry(std::map<std::string, std::string>* map) {
37 const wchar_t* kFonts = 35 const wchar_t* kFonts =
38 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; 36 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
39 37
40 base::win::RegistryValueIterator it(HKEY_LOCAL_MACHINE, kFonts); 38 base::win::RegistryValueIterator it(HKEY_LOCAL_MACHINE, kFonts);
41 for (; it.Valid(); ++it) { 39 for (; it.Valid(); ++it) {
42 const std::string filename = 40 const std::string filename =
43 base::ToLowerASCII(base::WideToUTF8(it.Value())); 41 base::ToLowerASCII(base::WideToUTF8(it.Value()));
44 (*map)[filename] = base::WideToUTF8(it.Name()); 42 (*map)[filename] = base::WideToUTF8(it.Name());
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // renderer this can cause hangs. Code that needs font fallback in the 348 // renderer this can cause hangs. Code that needs font fallback in the
351 // renderer should instead use the font proxy. 349 // renderer should instead use the font proxy.
352 DCHECK(base::MessageLoopForUI::IsCurrent()); 350 DCHECK(base::MessageLoopForUI::IsCurrent());
353 351
354 // Check that we have at least as much text as was claimed. If we have less 352 // Check that we have at least as much text as was claimed. If we have less
355 // text than expected then DirectWrite will become confused and crash. This 353 // text than expected then DirectWrite will become confused and crash. This
356 // shouldn't happen, but crbug.com/624905 shows that it happens sometimes. 354 // shouldn't happen, but crbug.com/624905 shows that it happens sometimes.
357 DCHECK_GE(wcslen(text), static_cast<size_t>(text_length)); 355 DCHECK_GE(wcslen(text), static_cast<size_t>(text_length));
358 text_length = std::min(wcslen(text), static_cast<size_t>(text_length)); 356 text_length = std::min(wcslen(text), static_cast<size_t>(text_length));
359 357
360 if (g_factory == nullptr) { 358 base::win::ScopedComPtr<IDWriteFactory> factory;
361 gfx::win::CreateDWriteFactory(&g_factory); 359 gfx::win::CreateDWriteFactory(factory.Receive());
362 }
363 base::win::ScopedComPtr<IDWriteFactory2> factory2; 360 base::win::ScopedComPtr<IDWriteFactory2> factory2;
364 g_factory->QueryInterface(factory2.Receive()); 361 factory.QueryInterface(factory2.Receive());
365 if (!factory2) { 362 if (!factory2) {
366 // IDWriteFactory2 is not available before Win8.1 363 // IDWriteFactory2 is not available before Win8.1
367 return GetUniscribeFallbackFont(font, text, text_length, result); 364 return GetUniscribeFallbackFont(font, text, text_length, result);
368 } 365 }
369 366
370 base::win::ScopedComPtr<IDWriteFontFallback> fallback; 367 base::win::ScopedComPtr<IDWriteFontFallback> fallback;
371 if (FAILED(factory2->GetSystemFontFallback(fallback.Receive()))) 368 if (FAILED(factory2->GetSystemFontFallback(fallback.Receive())))
372 return false; 369 return false;
373 370
374 base::string16 locale = base::UTF8ToUTF16(base::i18n::GetConfiguredLocale()); 371 base::string16 locale = base::UTF8ToUTF16(base::i18n::GetConfiguredLocale());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 base::string16 name; 405 base::string16 name;
409 if (FAILED(GetFamilyNameFromDirectWriteFont(mapped_font.get(), &name))) 406 if (FAILED(GetFamilyNameFromDirectWriteFont(mapped_font.get(), &name)))
410 return false; 407 return false;
411 *result = Font(base::UTF16ToUTF8(name), font.GetFontSize() * scale); 408 *result = Font(base::UTF16ToUTF8(name), font.GetFontSize() * scale);
412 return true; 409 return true;
413 } 410 }
414 return false; 411 return false;
415 } 412 }
416 413
417 } // namespace gfx 414 } // 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