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