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

Unified Diff: ui/views/examples/multiline_example.cc

Issue 152473008: More or less implement RenderTextHarfBuzz (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Alexei's comments 2 Created 6 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 side-by-side diff with in-line comments
Download patch
« ui/gfx/render_text_harfbuzz.cc ('K') | « ui/gfx/switches.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/examples/multiline_example.cc
diff --git a/ui/views/examples/multiline_example.cc b/ui/views/examples/multiline_example.cc
index 86685a423ec73baf0426e57b5f9cccbfdd23684a..b2c62ebb3f73894552be34b97cb51a8aef6d9870 100644
--- a/ui/views/examples/multiline_example.cc
+++ b/ui/views/examples/multiline_example.cc
@@ -20,6 +20,16 @@ using base::ASCIIToUTF16;
namespace views {
namespace examples {
+namespace {
+
+gfx::Range ClampRange(gfx::Range range, size_t max) {
+ range.set_start(std::min(range.start(), max));
+ range.set_end(std::min(range.end(), max));
+ return range;
+}
+
+} // namespace
+
// A simple View that hosts a RenderText object.
class MultilineExample::RenderTextView : public View {
public:
@@ -61,17 +71,20 @@ class MultilineExample::RenderTextView : public View {
void SetText(const base::string16& new_contents) {
// Color and style the text inside |test_range| to test colors and styles.
- gfx::Range test_range(1, 21);
- test_range.set_start(std::min(test_range.start(), new_contents.length()));
- test_range.set_end(std::min(test_range.end(), new_contents.length()));
+ const size_t range_max = new_contents.length();
+ gfx::Range color_range = ClampRange(gfx::Range(1, 21), range_max);
+ gfx::Range bold_range = ClampRange(gfx::Range(4, 10), range_max);
+ gfx::Range italic_range = ClampRange(gfx::Range(7, 13), range_max);
render_text_->SetText(new_contents);
render_text_->SetColor(SK_ColorBLACK);
- render_text_->ApplyColor(0xFFFF0000, test_range);
+ render_text_->ApplyColor(0xFFFF0000, color_range);
render_text_->SetStyle(gfx::DIAGONAL_STRIKE, false);
- render_text_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, test_range);
+ render_text_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, color_range);
render_text_->SetStyle(gfx::UNDERLINE, false);
- render_text_->ApplyStyle(gfx::UNDERLINE, true, test_range);
+ render_text_->ApplyStyle(gfx::UNDERLINE, true, color_range);
+ render_text_->ApplyStyle(gfx::BOLD, true, bold_range);
+ render_text_->ApplyStyle(gfx::ITALIC, true, italic_range);
InvalidateLayout();
}
@@ -99,14 +112,15 @@ MultilineExample::~MultilineExample() {
}
void MultilineExample::CreateExampleView(View* container) {
- const char kTestString[] = "test string asdf 1234 test string asdf 1234 "
- "test string asdf 1234 test string asdf 1234";
+ const base::string16 kTestString = base::WideToUTF16(L"qwerty"
+ L"\x627\x644\x631\x626\x64A\x633\x64A\x629"
+ L"asdfgh");
render_text_view_ = new RenderTextView();
- render_text_view_->SetText(ASCIIToUTF16(kTestString));
+ render_text_view_->SetText(kTestString);
label_ = new Label();
- label_->SetText(ASCIIToUTF16(kTestString));
+ label_->SetText(kTestString);
label_->SetMultiLine(true);
label_->SetBorder(Border::CreateSolidBorder(2, SK_ColorCYAN));
@@ -117,7 +131,7 @@ void MultilineExample::CreateExampleView(View* container) {
textfield_ = new Textfield();
textfield_->set_controller(this);
- textfield_->SetText(ASCIIToUTF16(kTestString));
+ textfield_->SetText(kTestString);
GridLayout* layout = new GridLayout(container);
container->SetLayoutManager(layout);
« ui/gfx/render_text_harfbuzz.cc ('K') | « ui/gfx/switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698