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

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

Issue 2914543002: [vr] Bail on unhandled code points. (Closed)
Patch Set: Created 3 years, 6 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
165 gfx::FontList UiTexture::GetFontList(int size, base::string16 text) { 167 bool UiTexture::GetFontList(int size,
168 base::string16 text,
169 gfx::FontList* font_list) {
170 if (force_font_fallback_failure_for_testing_)
171 return false;
172
166 gfx::Font default_font(kDefaultFontFamily, size); 173 gfx::Font default_font(kDefaultFontFamily, size);
167 std::vector<gfx::Font> fonts{default_font}; 174 std::vector<gfx::Font> fonts{default_font};
168 175
169 std::set<std::string> names; 176 std::set<std::string> names;
170 // TODO(acondor): Query BrowserProcess to obtain the application locale. 177 // TODO(acondor): Query BrowserProcess to obtain the application locale.
171 for (UChar32 c : CollectDifferentChars(text)) { 178 for (UChar32 c : CollectDifferentChars(text)) {
172 std::string name = GetFallbackFontNameForChar(default_font, c, ""); 179 std::string name;
173 if (!name.empty()) 180 bool found_name = GetFallbackFontNameForChar(default_font, c, "", &name);
181 if (!found_name)
182 return false;
183 if (name.empty())
174 names.insert(name); 184 names.insert(name);
175 } 185 }
176 for (const auto& name : names) 186 for (const auto& name : names)
177 fonts.push_back(gfx::Font(name, size)); 187 fonts.push_back(gfx::Font(name, size));
178 return gfx::FontList(fonts); 188 *font_list = gfx::FontList(fonts);
189 return true;
190 }
191
192 void UiTexture::SetForceFontFallbackFailureForTesting(bool force) {
193 force_font_fallback_failure_for_testing_ = force;
179 } 194 }
180 195
181 } // namespace vr_shell 196 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/textures/ui_texture.h ('k') | chrome/browser/android/vr_shell/textures/url_bar_texture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698