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

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 1020853018: DNCI [RenderText] Added font size options in RenderText. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed some debug code Created 5 years, 8 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
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/break_iterator.h" 10 #include "base/i18n/break_iterator.h"
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 721 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
722 render_text->set_truncate_length(5); 722 render_text->set_truncate_length(5);
723 for (size_t i = 0; i < arraysize(cases); i++) { 723 for (size_t i = 0; i < arraysize(cases); i++) {
724 render_text->SetText(WideToUTF16(cases[i].text)); 724 render_text->SetText(WideToUTF16(cases[i].text));
725 EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text()); 725 EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text());
726 EXPECT_EQ(WideToUTF16(cases[i].display_text), render_text->GetDisplayText()) 726 EXPECT_EQ(WideToUTF16(cases[i].display_text), render_text->GetDisplayText())
727 << "For case " << i << ": " << cases[i].text; 727 << "For case " << i << ": " << cases[i].text;
728 } 728 }
729 } 729 }
730 730
731 TEST_F(RenderTextTest, FontSize) {
732 SCOPED_TRACE("FontSize");
733 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
734 const wchar_t* string = L"0gl1gl2gl3gl";
735 render_text->SetText(WideToUTF16(string));
736 const Size kCanvasSize(150, 55);
737 const int kTestSize = 10;
738
739 struct Tests {
740 int a_size;
741 int b_size;
742 int c_size;
743 BaselineStyle a_baseline;
744 bool b_bold;
745 SkColor c_color;
746 } const kTests[] = {
747 {18, 26, 0, NORMAL_BASELINE, false, SK_ColorBLACK},
748 {26, 18, 8, SUPERSCRIPT, true, SK_ColorLTGRAY},
749 {18, 26, 0, INFERIOR, false, SK_ColorRED},
750 {26, 18, 8, SUPERIOR, true, SK_ColorBLUE},
751 };
752
753 render_text->SetHorizontalAlignment(ALIGN_LEFT);
754 render_text->SetVerticalAlignment(VALIGN_TOP);
755 skia::RefPtr<SkSurface> surface = skia::AdoptRef(
756 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()));
757 scoped_ptr<Canvas> canvas(
758 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f));
759 Rect bounds = Rect(kTestSize, kTestSize, kCanvasSize.width() - kTestSize * 2,
760 kCanvasSize.height() - kTestSize * 2);
761 render_text->SetDisplayRect(bounds);
762 render_text->set_clip_to_display_rect(false);
763 const uint32* buffer =
764 static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr));
765 ASSERT_NE(nullptr, buffer);
766 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
msw 2015/03/30 21:14:35 As in the vertical alignment CL, I hope that testi
767 kCanvasSize.height());
768 for (const auto& test : kTests) {
769 surface->getCanvas()->clear(SK_ColorWHITE);
770 render_text->ApplyFontSize(test.a_size, Range(0, 3));
771 render_text->ApplyFontSize(test.b_size, Range(3, 6));
772 render_text->ApplyFontSize(test.c_size, Range(6, 9));
773 render_text->ApplyBaselineStyle(test.a_baseline, Range(2, 3));
774 render_text->ApplyStyle(BOLD, test.b_bold, Range(4, 6));
775 render_text->ApplyColor(test.c_color, Range(7, 9));
776 const Size string_size = render_text->GetStringSize();
777 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width());
778 ASSERT_LE(string_size.height() + kTestSize * 2, kCanvasSize.height());
779 Rect expected_rect(kTestSize, kTestSize, string_size.width(),
780 string_size.height());
781 render_text->Draw(canvas.get());
782 expected_rect.Inset(-1, -1);
783 rect_buffer.EnsureSolidBorder(SK_ColorWHITE, expected_rect);
784 }
785 }
786
731 TEST_F(RenderTextTest, TruncatedObscuredText) { 787 TEST_F(RenderTextTest, TruncatedObscuredText) {
732 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 788 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
733 render_text->set_truncate_length(3); 789 render_text->set_truncate_length(3);
734 render_text->SetObscured(true); 790 render_text->SetObscured(true);
735 render_text->SetText(WideToUTF16(L"abcdef")); 791 render_text->SetText(WideToUTF16(L"abcdef"));
736 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); 792 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text());
737 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText()); 793 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText());
738 } 794 }
739 795
740 TEST_F(RenderTextTest, TruncatedCursorMovementLTR) { 796 TEST_F(RenderTextTest, TruncatedCursorMovementLTR) {
(...skipping 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 const uint32* buffer = 2787 const uint32* buffer =
2732 static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr)); 2788 static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr));
2733 ASSERT_NE(nullptr, buffer); 2789 ASSERT_NE(nullptr, buffer);
2734 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), 2790 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
2735 kCanvasSize.height()); 2791 kCanvasSize.height());
2736 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width()); 2792 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width());
2737 ASSERT_LE(string_size.height() + kTestSize * 2, kCanvasSize.height()); 2793 ASSERT_LE(string_size.height() + kTestSize * 2, kCanvasSize.height());
2738 for (const auto& test : kTests) { 2794 for (const auto& test : kTests) {
2739 SCOPED_TRACE(base::StringPrintf("VerticalAlignement H %i, V %i", 2795 SCOPED_TRACE(base::StringPrintf("VerticalAlignement H %i, V %i",
2740 test.horizontal, test.vertical)); 2796 test.horizontal, test.vertical));
2741
2742 surface->getCanvas()->clear(SK_ColorWHITE); 2797 surface->getCanvas()->clear(SK_ColorWHITE);
2743 render_text->SetHorizontalAlignment(test.horizontal); 2798 render_text->SetHorizontalAlignment(test.horizontal);
2744 render_text->SetVerticalAlignment(test.vertical); 2799 render_text->SetVerticalAlignment(test.vertical);
2745 EXPECT_EQ(test.x - kTestSize, render_text->GetAlignmentOffset(0).x()); 2800 EXPECT_EQ(test.x - kTestSize, render_text->GetAlignmentOffset(0).x());
2746 EXPECT_EQ(test.y - kTestSize, render_text->GetAlignmentOffset(0).y()); 2801 EXPECT_EQ(test.y - kTestSize, render_text->GetAlignmentOffset(0).y());
2747 Rect expected_rect(test.x, test.y, string_size.width(), 2802 Rect expected_rect(test.x, test.y, string_size.width(),
2748 string_size.height()); 2803 string_size.height());
2749 expected_rect.Inset(-1, -1); 2804 expected_rect.Inset(-1, -1);
2750 render_text->Draw(canvas.get()); 2805 render_text->Draw(canvas.get());
2751 rect_buffer.EnsureSolidBorder(SK_ColorWHITE, expected_rect); 2806 rect_buffer.EnsureSolidBorder(SK_ColorWHITE, expected_rect);
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2969 string_size.set_width(string_size.width() / 2); 3024 string_size.set_width(string_size.width() / 2);
2970 render_text.SetDisplayRect(gfx::Rect(string_size)); 3025 render_text.SetDisplayRect(gfx::Rect(string_size));
2971 render_text.EnsureLayout(); 3026 render_text.EnsureLayout();
2972 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); 3027 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_);
2973 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); 3028 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count));
2974 EXPECT_NE(0, glyph_count); 3029 EXPECT_NE(0, glyph_count);
2975 } 3030 }
2976 #endif 3031 #endif
2977 3032
2978 } // namespace gfx 3033 } // namespace gfx
OLDNEW
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698