| 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 6d14ae5cb676b73045bd062227a2fd91cf4c5bdd..adca8c875e3f5b8354358b868d46e077797d7fac 100644
|
| --- a/chrome/browser/android/vr_shell/textures/ui_texture.cc
|
| +++ b/chrome/browser/android/vr_shell/textures/ui_texture.cc
|
| @@ -12,12 +12,15 @@
|
| #include "base/i18n/rtl.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/strings/string_util.h"
|
| +#include "base/trace_event/trace_event.h"
|
| #include "chrome/browser/android/vr_shell/font_fallback.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "third_party/icu/source/common/unicode/uscript.h"
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/font_list.h"
|
| +#include "ui/gfx/render_text.h"
|
| +#include "ui/gfx/text_elider.h"
|
| #include "ui/gl/gl_bindings.h"
|
|
|
| namespace vr_shell {
|
| @@ -26,6 +29,33 @@ namespace {
|
|
|
| static constexpr char kDefaultFontFamily[] = "sans-serif";
|
|
|
| +std::unique_ptr<gfx::RenderText> CreateRenderText(
|
| + const base::string16& text,
|
| + const gfx::FontList& font_list,
|
| + SkColor color,
|
| + int flags) {
|
| + std::unique_ptr<gfx::RenderText> render_text(
|
| + gfx::RenderText::CreateInstance());
|
| + render_text->SetText(text);
|
| + render_text->SetFontList(font_list);
|
| + render_text->SetColor(color);
|
| +
|
| + if (flags & UiTexture::TEXT_ALIGN_LEFT)
|
| + render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
| + else if (flags & UiTexture::TEXT_ALIGN_RIGHT)
|
| + render_text->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
|
| + else if (flags & UiTexture::TEXT_ALIGN_CENTER)
|
| + render_text->SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
| +
|
| + const int font_style = font_list.GetFontStyle();
|
| + render_text->SetStyle(gfx::ITALIC, (font_style & gfx::Font::ITALIC) != 0);
|
| + render_text->SetStyle(gfx::UNDERLINE,
|
| + (font_style & gfx::Font::UNDERLINE) != 0);
|
| + render_text->SetWeight(font_list.GetFontWeight());
|
| +
|
| + return render_text;
|
| +}
|
| +
|
| std::set<UChar32> CollectDifferentChars(base::string16 text) {
|
| std::set<UChar32> characters;
|
| for (base::i18n::UTF16CharIterator it(&text); !it.end(); it.Advance()) {
|
| @@ -41,10 +71,76 @@ UiTexture::UiTexture() = default;
|
| UiTexture::~UiTexture() = default;
|
|
|
| void UiTexture::DrawAndLayout(SkCanvas* canvas, const gfx::Size& texture_size) {
|
| + TRACE_EVENT0("gpu", "UiTexture::DrawAndLayout");
|
| canvas->drawColor(SK_ColorTRANSPARENT);
|
| Draw(canvas, texture_size);
|
| }
|
|
|
| +std::vector<std::unique_ptr<gfx::RenderText>> UiTexture::PrepareDrawStringRect(
|
| + const base::string16& text,
|
| + const gfx::FontList& font_list,
|
| + SkColor color,
|
| + gfx::Rect* bounds,
|
| + int flags) {
|
| + DCHECK(bounds);
|
| +
|
| + std::vector<std::unique_ptr<gfx::RenderText>> lines;
|
| + gfx::Rect rect(*bounds);
|
| +
|
| + if (flags & MULTI_LINE) {
|
| + std::vector<base::string16> strings;
|
| + gfx::ElideRectangleText(text, font_list, bounds->width(),
|
| + bounds->height() ? bounds->height() : INT_MAX,
|
| + gfx::WRAP_LONG_WORDS, &strings);
|
| +
|
| + int height = 0;
|
| + int line_height = 0;
|
| + for (size_t i = 0; i < strings.size(); i++) {
|
| + std::unique_ptr<gfx::RenderText> render_text =
|
| + CreateRenderText(strings[i], font_list, color, flags);
|
| +
|
| + if (i == 0) {
|
| + // Measure line and center text vertically.
|
| + line_height = render_text->GetStringSize().height();
|
| + rect.set_height(line_height);
|
| + if (bounds->height()) {
|
| + const int text_height = strings.size() * line_height;
|
| + rect += gfx::Vector2d(0, (bounds->height() - text_height) / 2);
|
| + }
|
| + }
|
| +
|
| + render_text->SetDisplayRect(rect);
|
| + height += line_height;
|
| + rect += gfx::Vector2d(0, line_height);
|
| + lines.push_back(std::move(render_text));
|
| + }
|
| +
|
| + // Set calculated height.
|
| + if (bounds->height() == 0)
|
| + bounds->set_height(height);
|
| +
|
| + } else {
|
| + std::unique_ptr<gfx::RenderText> render_text =
|
| + CreateRenderText(text, font_list, color, flags);
|
| + if (bounds->width() != 0)
|
| + render_text->SetElideBehavior(gfx::TRUNCATE);
|
| + else
|
| + rect.set_width(INT_MAX);
|
| +
|
| + render_text->SetDisplayRect(rect);
|
| +
|
| + if (bounds->width() == 0) {
|
| + int text_width = render_text->GetStringSize().width();
|
| + bounds->set_width(text_width);
|
| + rect.set_width(text_width);
|
| + render_text->SetDisplayRect(rect);
|
| + }
|
| +
|
| + lines.push_back(std::move(render_text));
|
| + }
|
| + return lines;
|
| +}
|
| +
|
| bool UiTexture::IsRTL() {
|
| return base::i18n::IsRTL();
|
| }
|
|
|