OLD | NEW |
---|---|
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 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1996 continue; | 1996 continue; |
1997 | 1997 |
1998 for (size_t j = 0; j < kTestStrings[i].lines_count; ++j) { | 1998 for (size_t j = 0; j < kTestStrings[i].lines_count; ++j) { |
1999 SCOPED_TRACE(base::StringPrintf("Line %" PRIuS "", j)); | 1999 SCOPED_TRACE(base::StringPrintf("Line %" PRIuS "", j)); |
2000 VerifyLineSegments(kTestStrings[i].line_char_ranges[j], | 2000 VerifyLineSegments(kTestStrings[i].line_char_ranges[j], |
2001 render_text.lines_[j].segments); | 2001 render_text.lines_[j].segments); |
2002 } | 2002 } |
2003 } | 2003 } |
2004 } | 2004 } |
2005 | 2005 |
2006 // Ensure RTL alignment works. | |
2007 TEST_F(RenderTextTest, Multiline_HorizontalAlignment) { | |
2008 const struct { | |
2009 const wchar_t* const text; | |
2010 gfx::HorizontalAlignment alignment; | |
2011 } kTestStrings[] = { | |
2012 { L"abcdefghij\nhijkl", gfx::ALIGN_LEFT }, | |
2013 // hebrew | |
2014 { L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7\n\x5d0\x5d1\x5d2\x5d3", | |
2015 gfx::ALIGN_RIGHT }, | |
2016 // arabic | |
2017 { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664", | |
2018 gfx::ALIGN_RIGHT }, | |
2019 }; | |
2020 RenderTextHarfBuzz render_text; | |
2021 render_text.SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); | |
2022 render_text.set_glyph_width_for_test(5); | |
2023 render_text.SetDisplayRect(Rect(100, 1000)); | |
2024 render_text.SetMultiline(true); | |
2025 | |
2026 Canvas canvas; | |
2027 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | |
2028 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i, | |
2029 kTestStrings[i].text)); | |
2030 render_text.SetText(WideToUTF16(kTestStrings[i].text)); | |
2031 render_text.Draw(&canvas); | |
2032 ASSERT_LE(2u, render_text.lines().size()); | |
2033 if (kTestStrings[i].alignment == gfx::ALIGN_LEFT) { | |
2034 EXPECT_EQ(0, render_text.GetAlignmentOffset(0).x()); | |
2035 EXPECT_EQ(0, render_text.GetAlignmentOffset(1).x()); | |
2036 } else { | |
2037 // Second string should be always shorter, thus | |
msw
2015/02/19 01:13:50
nit: consider: "The second line in the test string
| |
2038 // the seond line has longer alignment. | |
msw
2015/02/19 01:13:50
nit: "second"
| |
2039 EXPECT_LT(render_text.GetAlignmentOffset(0).x(), | |
2040 render_text.GetAlignmentOffset(1).x()); | |
2041 } | |
2042 } | |
2043 } | |
2044 | |
2006 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) { | 2045 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) { |
2007 const wchar_t* kTestStrings[] = { | 2046 const wchar_t* kTestStrings[] = { |
2008 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", | 2047 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", |
2009 }; | 2048 }; |
2010 | 2049 |
2011 RenderTextHarfBuzz render_text; | 2050 RenderTextHarfBuzz render_text; |
2012 render_text.SetDisplayRect(Rect(200, 1000)); | 2051 render_text.SetDisplayRect(Rect(200, 1000)); |
2013 Canvas canvas; | 2052 Canvas canvas; |
2014 | 2053 |
2015 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2054 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2383 base::StringToLowerASCII(fonts[0].GetActualFontNameForTesting())); | 2422 base::StringToLowerASCII(fonts[0].GetActualFontNameForTesting())); |
2384 | 2423 |
2385 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 2424 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
2386 render_text->SetDisplayRect(Rect(0, 0, 25, 25)); | 2425 render_text->SetDisplayRect(Rect(0, 0, 25, 25)); |
2387 render_text->SetFontList(font_list); | 2426 render_text->SetFontList(font_list); |
2388 EXPECT_GT(render_text->GetBaseline(), font_list.GetBaseline()); | 2427 EXPECT_GT(render_text->GetBaseline(), font_list.GetBaseline()); |
2389 } | 2428 } |
2390 #endif | 2429 #endif |
2391 | 2430 |
2392 } // namespace gfx | 2431 } // namespace gfx |
OLD | NEW |