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 2244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2255 std::vector<base::string16> lines; | 2255 std::vector<base::string16> lines; |
2256 base::SplitString(base::WideToUTF16(kTestStrings[i].text), '\n', &lines); | 2256 base::SplitString(base::WideToUTF16(kTestStrings[i].text), '\n', &lines); |
2257 ASSERT_EQ(2u, lines.size()); | 2257 ASSERT_EQ(2u, lines.size()); |
2258 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize; | 2258 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize; |
2259 EXPECT_EQ(render_text.GetAlignmentOffset(0).x() + difference, | 2259 EXPECT_EQ(render_text.GetAlignmentOffset(0).x() + difference, |
2260 render_text.GetAlignmentOffset(1).x()); | 2260 render_text.GetAlignmentOffset(1).x()); |
2261 } | 2261 } |
2262 } | 2262 } |
2263 } | 2263 } |
2264 | 2264 |
| 2265 TEST_F(RenderTextTest, Multiline_AllowCharacterBreak) { |
| 2266 RenderTextHarfBuzz render_text; |
| 2267 render_text.SetMultiline(true); |
| 2268 render_text.SetText(ASCIIToUTF16("foo bar baz")); |
| 2269 Size ideal_size = render_text.GetStringSize(); |
| 2270 |
| 2271 render_text.SetDisplayRect( |
| 2272 Rect(0, 0, ideal_size.width() / 2, ideal_size.height())); |
| 2273 render_text.SetAllowCharacterBreak(true); |
| 2274 |
| 2275 Canvas canvas; |
| 2276 render_text.Draw(&canvas); |
| 2277 EXPECT_LE(2u, render_text.lines().size()); |
| 2278 Range char_range = render_text.lines()[0].segments[0].char_range; |
| 2279 EXPECT_EQ(0u, char_range.start()); |
| 2280 // Broken in the middle of the second word "bar". |
| 2281 EXPECT_LT(4u, char_range.end()); |
| 2282 EXPECT_GT(8u, char_range.end()); |
| 2283 } |
| 2284 |
2265 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) { | 2285 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) { |
2266 const wchar_t* kTestStrings[] = { | 2286 const wchar_t* kTestStrings[] = { |
2267 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", | 2287 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", |
2268 }; | 2288 }; |
2269 | 2289 |
2270 RenderTextHarfBuzz render_text; | 2290 RenderTextHarfBuzz render_text; |
2271 render_text.SetDisplayRect(Rect(200, 1000)); | 2291 render_text.SetDisplayRect(Rect(200, 1000)); |
2272 Canvas canvas; | 2292 Canvas canvas; |
2273 | 2293 |
2274 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2294 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2822 string_size.set_width(string_size.width() / 2); | 2842 string_size.set_width(string_size.width() / 2); |
2823 render_text.SetDisplayRect(gfx::Rect(string_size)); | 2843 render_text.SetDisplayRect(gfx::Rect(string_size)); |
2824 render_text.EnsureLayout(); | 2844 render_text.EnsureLayout(); |
2825 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 2845 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
2826 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 2846 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
2827 EXPECT_NE(0, glyph_count); | 2847 EXPECT_NE(0, glyph_count); |
2828 } | 2848 } |
2829 #endif | 2849 #endif |
2830 | 2850 |
2831 } // namespace gfx | 2851 } // namespace gfx |
OLD | NEW |