Chromium Code Reviews| Index: chrome/browser/android/vr_shell/textures/ui_texture.cc |
| diff --git a/chrome/browser/android/vr_shell/textures/ui_texture.cc b/chrome/browser/android/vr_shell/textures/ui_texture.cc |
| index c93ca29e39126d88f285412d152d386b04552ae5..cd4cacf3f108635b00131e8abb691ea3612849f8 100644 |
| --- a/chrome/browser/android/vr_shell/textures/ui_texture.cc |
| +++ b/chrome/browser/android/vr_shell/textures/ui_texture.cc |
| @@ -4,17 +4,26 @@ |
| #include "chrome/browser/android/vr_shell/textures/ui_texture.h" |
| +#include <set> |
| #include <string> |
| #include <vector> |
| +#include "base/i18n/char_iterator.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/strings/string_util.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| +#include "third_party/skia/include/ports/SkFontMgr.h" |
| #include "ui/gfx/canvas.h" |
| +#include "ui/gfx/font_list.h" |
| #include "ui/gl/gl_bindings.h" |
| namespace vr_shell { |
| +namespace { |
| +constexpr char kDefaultFontFamily[] = "sans-serif"; |
| +} // namespace |
| + |
| // TODO(acondor): Create non-square textures to reduce memory usage. |
| UITexture::UITexture(int texture_handle, int texture_size) |
| : texture_handle_(texture_handle), |
| @@ -46,4 +55,25 @@ void UITexture::Flush() { |
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| } |
| +gfx::FontList UITexture::GetFontList(int size, base::string16 text) { |
|
mthiesse
2017/04/18 21:30:35
This feels like code that shouldn't be specific to
acondor_
2017/04/18 23:48:46
Added a TODO. It should be gfx::GetFallbackFonts,
|
| + gfx::Font default_font(kDefaultFontFamily, size); |
| + std::vector<gfx::Font> fonts{default_font}; |
| + sk_sp<SkFontMgr> font_mgr(SkFontMgr::RefDefault()); |
| + std::set<std::string> names; |
| + // TODO(acondor): Query BrowserProcess to obtain the application locale. |
| + for (base::i18n::UTF16CharIterator it(&text); !it.end(); it.Advance()) { |
| + sk_sp<SkTypeface> tf(font_mgr->matchFamilyStyleCharacter( |
| + default_font.GetFontName().c_str(), SkFontStyle(), nullptr, 0, |
| + it.get())); |
| + SkString sk_name; |
| + tf->getFamilyName(&sk_name); |
| + std::string name(sk_name.c_str()); |
| + if (name != kDefaultFontFamily) |
| + names.insert(name); |
| + } |
| + for (const auto& name : names) |
| + fonts.push_back(gfx::Font(name, size)); |
| + return gfx::FontList(fonts); |
| +} |
| + |
| } // namespace vr_shell |