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

Unified 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, 9 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.h ('K') | « ui/gfx/render_text_mac.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index 6b13ee1aeab30577ee8fd6b3d52b3688070051f4..1338df85d2ecaf0d476ce82054a464a6353af040 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -728,6 +728,62 @@ TEST_F(RenderTextTest, TruncatedText) {
}
}
+TEST_F(RenderTextTest, FontSize) {
+ SCOPED_TRACE("FontSize");
+ scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
+ const wchar_t* string = L"0gl1gl2gl3gl";
+ render_text->SetText(WideToUTF16(string));
+ const Size kCanvasSize(150, 55);
+ const int kTestSize = 10;
+
+ struct Tests {
+ int a_size;
+ int b_size;
+ int c_size;
+ BaselineStyle a_baseline;
+ bool b_bold;
+ SkColor c_color;
+ } const kTests[] = {
+ {18, 26, 0, NORMAL_BASELINE, false, SK_ColorBLACK},
+ {26, 18, 8, SUPERSCRIPT, true, SK_ColorLTGRAY},
+ {18, 26, 0, INFERIOR, false, SK_ColorRED},
+ {26, 18, 8, SUPERIOR, true, SK_ColorBLUE},
+ };
+
+ render_text->SetHorizontalAlignment(ALIGN_LEFT);
+ render_text->SetVerticalAlignment(VALIGN_TOP);
+ skia::RefPtr<SkSurface> surface = skia::AdoptRef(
+ SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()));
+ scoped_ptr<Canvas> canvas(
+ Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f));
+ Rect bounds = Rect(kTestSize, kTestSize, kCanvasSize.width() - kTestSize * 2,
+ kCanvasSize.height() - kTestSize * 2);
+ render_text->SetDisplayRect(bounds);
+ render_text->set_clip_to_display_rect(false);
+ const uint32* buffer =
+ static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr));
+ ASSERT_NE(nullptr, buffer);
+ TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
msw 2015/03/30 21:14:35 As in the vertical alignment CL, I hope that testi
+ kCanvasSize.height());
+ for (const auto& test : kTests) {
+ surface->getCanvas()->clear(SK_ColorWHITE);
+ render_text->ApplyFontSize(test.a_size, Range(0, 3));
+ render_text->ApplyFontSize(test.b_size, Range(3, 6));
+ render_text->ApplyFontSize(test.c_size, Range(6, 9));
+ render_text->ApplyBaselineStyle(test.a_baseline, Range(2, 3));
+ render_text->ApplyStyle(BOLD, test.b_bold, Range(4, 6));
+ render_text->ApplyColor(test.c_color, Range(7, 9));
+ const Size string_size = render_text->GetStringSize();
+ ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width());
+ ASSERT_LE(string_size.height() + kTestSize * 2, kCanvasSize.height());
+ Rect expected_rect(kTestSize, kTestSize, string_size.width(),
+ string_size.height());
+ render_text->Draw(canvas.get());
+ expected_rect.Inset(-1, -1);
+ rect_buffer.EnsureSolidBorder(SK_ColorWHITE, expected_rect);
+ }
+}
+
TEST_F(RenderTextTest, TruncatedObscuredText) {
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->set_truncate_length(3);
@@ -2738,7 +2794,6 @@ TEST_F(RenderTextTest, VerticalAlignment) {
for (const auto& test : kTests) {
SCOPED_TRACE(base::StringPrintf("VerticalAlignement H %i, V %i",
test.horizontal, test.vertical));
-
surface->getCanvas()->clear(SK_ColorWHITE);
render_text->SetHorizontalAlignment(test.horizontal);
render_text->SetVerticalAlignment(test.vertical);
« 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