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

Side by Side Diff: chrome/browser/android/vr_shell/textures/ui_texture.cc

Issue 2902393002: [vr] Bail on unhandled code points. (Closed)
Patch Set: histograms Created 3 years, 7 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
OLDNEW
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 11 matching lines...) Expand all
22 #include "ui/gfx/render_text.h" 22 #include "ui/gfx/render_text.h"
23 #include "ui/gfx/text_elider.h" 23 #include "ui/gfx/text_elider.h"
24 #include "ui/gl/gl_bindings.h" 24 #include "ui/gl/gl_bindings.h"
25 25
26 namespace vr_shell { 26 namespace vr_shell {
27 27
28 namespace { 28 namespace {
29 29
30 static constexpr char kDefaultFontFamily[] = "sans-serif"; 30 static constexpr char kDefaultFontFamily[] = "sans-serif";
31 31
32 static bool force_font_fallback_failure_for_testing_ = false;
33
32 std::set<UChar32> CollectDifferentChars(base::string16 text) { 34 std::set<UChar32> CollectDifferentChars(base::string16 text) {
33 std::set<UChar32> characters; 35 std::set<UChar32> characters;
34 for (base::i18n::UTF16CharIterator it(&text); !it.end(); it.Advance()) { 36 for (base::i18n::UTF16CharIterator it(&text); !it.end(); it.Advance()) {
35 characters.insert(it.get()); 37 characters.insert(it.get());
36 } 38 }
37 return characters; 39 return characters;
38 } 40 }
39 41
40 } // namespace 42 } // namespace
41 43
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 157 }
156 158
157 bool UiTexture::IsRTL() { 159 bool UiTexture::IsRTL() {
158 return base::i18n::IsRTL(); 160 return base::i18n::IsRTL();
159 } 161 }
160 162
161 gfx::FontList UiTexture::GetDefaultFontList(int size) { 163 gfx::FontList UiTexture::GetDefaultFontList(int size) {
162 return gfx::FontList(gfx::Font(kDefaultFontFamily, size)); 164 return gfx::FontList(gfx::Font(kDefaultFontFamily, size));
163 } 165 }
164 166
167 bool UiTexture::CheckFontList(int size, base::string16 text) {
168 if (force_font_fallback_failure_for_testing_)
169 return false;
170
171 gfx::Font default_font(kDefaultFontFamily, size);
172 // TODO(acondor): Query BrowserProcess to obtain the application locale.
173 for (UChar32 c : CollectDifferentChars(text)) {
174 std::string name;
175 if (!GetFallbackFontNameForChar(default_font, c, "", &name))
176 return false;
177 }
178 return true;
179 }
180
165 gfx::FontList UiTexture::GetFontList(int size, base::string16 text) { 181 gfx::FontList UiTexture::GetFontList(int size, base::string16 text) {
166 gfx::Font default_font(kDefaultFontFamily, size); 182 gfx::Font default_font(kDefaultFontFamily, size);
167 std::vector<gfx::Font> fonts{default_font}; 183 std::vector<gfx::Font> fonts{default_font};
168 184
169 std::set<std::string> names; 185 std::set<std::string> names;
170 // TODO(acondor): Query BrowserProcess to obtain the application locale. 186 // TODO(acondor): Query BrowserProcess to obtain the application locale.
171 for (UChar32 c : CollectDifferentChars(text)) { 187 for (UChar32 c : CollectDifferentChars(text)) {
172 std::string name = GetFallbackFontNameForChar(default_font, c, ""); 188 std::string name;
173 if (!name.empty()) 189 bool found_name = GetFallbackFontNameForChar(default_font, c, "", &name);
190 if (found_name && !name.empty())
174 names.insert(name); 191 names.insert(name);
175 } 192 }
176 for (const auto& name : names) 193 for (const auto& name : names)
177 fonts.push_back(gfx::Font(name, size)); 194 fonts.push_back(gfx::Font(name, size));
178 return gfx::FontList(fonts); 195 return gfx::FontList(fonts);
179 } 196 }
180 197
198 void UiTexture::SetForceFontFallbackFailureForTesting(bool force) {
199 force_font_fallback_failure_for_testing_ = force;
200 }
201
181 } // namespace vr_shell 202 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698