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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 915383003: Fix alignment format in multiline mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
Index: ui/gfx/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index 44aaa1a43b5772eefff567e04d4a8f802b97a011..e6ccdb3e2368a129e419ad54f08014b6a3979ea0 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -2003,6 +2003,45 @@ TEST_F(RenderTextTest, Multiline_Newline) {
}
}
+// Ensure RTL alignment works.
+TEST_F(RenderTextTest, Multiline_HorizontalAlignment) {
+ const struct {
+ const wchar_t* const text;
+ gfx::HorizontalAlignment alignment;
+ } kTestStrings[] = {
+ { L"abcdefghij\nhijkl", gfx::ALIGN_LEFT },
+ // hebrew
+ { L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7\n\x5d0\x5d1\x5d2\x5d3",
+ gfx::ALIGN_RIGHT },
+ // arabic
+ { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664",
+ gfx::ALIGN_RIGHT },
+ };
+ RenderTextHarfBuzz render_text;
+ render_text.SetHorizontalAlignment(gfx::ALIGN_TO_HEAD);
+ render_text.set_glyph_width_for_test(5);
+ render_text.SetDisplayRect(Rect(100, 1000));
+ render_text.SetMultiline(true);
+
+ Canvas canvas;
+ for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
+ SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i,
+ kTestStrings[i].text));
+ render_text.SetText(WideToUTF16(kTestStrings[i].text));
+ render_text.Draw(&canvas);
+ ASSERT_LE(2u, render_text.lines().size());
+ if (kTestStrings[i].alignment == gfx::ALIGN_LEFT) {
+ EXPECT_EQ(0, render_text.GetAlignmentOffset(0).x());
+ EXPECT_EQ(0, render_text.GetAlignmentOffset(1).x());
+ } else {
+ // Second string should be always shorter, thus
msw 2015/02/19 01:13:50 nit: consider: "The second line in the test string
+ // the seond line has longer alignment.
msw 2015/02/19 01:13:50 nit: "second"
+ EXPECT_LT(render_text.GetAlignmentOffset(0).x(),
+ render_text.GetAlignmentOffset(1).x());
+ }
+ }
+}
+
TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) {
const wchar_t* kTestStrings[] = {
L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n",

Powered by Google App Engine
This is Rietveld 408576698