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