OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/android/vr_shell/textures/ui_texture.h" | 5 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 bool UiTexture::IsRTL() { | 39 bool UiTexture::IsRTL() { |
40 return base::i18n::IsRTL(); | 40 return base::i18n::IsRTL(); |
41 } | 41 } |
42 | 42 |
43 gfx::FontList UiTexture::GetFontList(int size, base::string16 text) { | 43 gfx::FontList UiTexture::GetFontList(int size, base::string16 text) { |
44 gfx::Font default_font(kDefaultFontFamily, size); | 44 gfx::Font default_font(kDefaultFontFamily, size); |
45 std::vector<gfx::Font> fonts{default_font}; | 45 std::vector<gfx::Font> fonts{default_font}; |
46 | 46 |
| 47 std::set<wchar_t> characters; |
| 48 for (base::i18n::UTF16CharIterator it(&text); !it.end(); it.Advance()) { |
| 49 characters.insert(it.get()); |
| 50 } |
47 // TODO(acondor): Obtain fallback fonts with gfx::GetFallbackFonts | 51 // TODO(acondor): Obtain fallback fonts with gfx::GetFallbackFonts |
48 // (which is not implemented for android yet) in order to avoid | 52 // (which is not implemented for android yet) in order to avoid |
49 // querying per character. | 53 // querying per character. |
50 | 54 |
51 sk_sp<SkFontMgr> font_mgr(SkFontMgr::RefDefault()); | 55 sk_sp<SkFontMgr> font_mgr(SkFontMgr::RefDefault()); |
52 std::set<std::string> names; | 56 std::set<std::string> names; |
53 // TODO(acondor): Query BrowserProcess to obtain the application locale. | 57 // TODO(acondor): Query BrowserProcess to obtain the application locale. |
54 for (base::i18n::UTF16CharIterator it(&text); !it.end(); it.Advance()) { | 58 for (wchar_t character : characters) { |
55 sk_sp<SkTypeface> tf(font_mgr->matchFamilyStyleCharacter( | 59 sk_sp<SkTypeface> tf(font_mgr->matchFamilyStyleCharacter( |
56 default_font.GetFontName().c_str(), SkFontStyle(), nullptr, 0, | 60 kDefaultFontFamily, SkFontStyle(), nullptr, 0, character)); |
57 it.get())); | 61 |
58 // TODO(acondor): How should we handle no matching font? | 62 // TODO(acondor): How should we handle no matching font? |
59 if (!tf) | 63 if (!tf) |
60 continue; | 64 continue; |
61 SkString sk_name; | 65 SkString sk_name; |
62 tf->getFamilyName(&sk_name); | 66 tf->getFamilyName(&sk_name); |
63 std::string name(sk_name.c_str()); | 67 std::string name(sk_name.c_str()); |
64 if (name != kDefaultFontFamily) | 68 if (name != kDefaultFontFamily) |
65 names.insert(name); | 69 names.insert(name); |
66 } | 70 } |
67 for (const auto& name : names) | 71 for (const auto& name : names) |
68 fonts.push_back(gfx::Font(name, size)); | 72 fonts.push_back(gfx::Font(name, size)); |
69 return gfx::FontList(fonts); | 73 return gfx::FontList(fonts); |
70 } | 74 } |
71 | 75 |
72 } // namespace vr_shell | 76 } // namespace vr_shell |
OLD | NEW |