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

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

Issue 1015533016: Move allow_character_break property to RenderText. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix 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 unified diff | Download patch
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 2058 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 } 2069 }
2070 2070
2071 // Ensure strings wrap onto multiple lines for a small available width. 2071 // Ensure strings wrap onto multiple lines for a small available width.
2072 TEST_F(RenderTextTest, Multiline_MinWidth) { 2072 TEST_F(RenderTextTest, Multiline_MinWidth) {
2073 const wchar_t* kTestStrings[] = { kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, 2073 const wchar_t* kTestStrings[] = { kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl,
2074 kRtlLtr, kRtlLtrRtl }; 2074 kRtlLtr, kRtlLtrRtl };
2075 2075
2076 RenderTextHarfBuzz render_text; 2076 RenderTextHarfBuzz render_text;
2077 render_text.SetDisplayRect(Rect(1, 1000)); 2077 render_text.SetDisplayRect(Rect(1, 1000));
2078 render_text.SetMultiline(true); 2078 render_text.SetMultiline(true);
2079 render_text.SetWordWrapBehavior(WRAP_LONG_WORDS);
2079 Canvas canvas; 2080 Canvas canvas;
2080 2081
2081 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2082 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2082 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2083 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2083 render_text.SetText(WideToUTF16(kTestStrings[i])); 2084 render_text.SetText(WideToUTF16(kTestStrings[i]));
2084 render_text.Draw(&canvas); 2085 render_text.Draw(&canvas);
2085 EXPECT_GT(render_text.lines_.size(), 1U); 2086 EXPECT_GT(render_text.lines_.size(), 1U);
2086 } 2087 }
2087 } 2088 }
2088 2089
(...skipping 13 matching lines...) Expand all
2102 { L"\x062A\x0641\x0627\x062D\x05EA\x05E4\x05D5\x05D6\x05D9" 2103 { L"\x062A\x0641\x0627\x062D\x05EA\x05E4\x05D5\x05D6\x05D9"
2103 L"\x05DA\x05DB\x05DD", Range(0, 4), Range(4, 12), false } 2104 L"\x05DA\x05DB\x05DD", Range(0, 4), Range(4, 12), false }
2104 }; 2105 };
2105 2106
2106 RenderTextHarfBuzz render_text; 2107 RenderTextHarfBuzz render_text;
2107 // Specify the fixed width for characters to suppress the possible variations 2108 // Specify the fixed width for characters to suppress the possible variations
2108 // of linebreak results. 2109 // of linebreak results.
2109 render_text.set_glyph_width_for_test(5); 2110 render_text.set_glyph_width_for_test(5);
2110 render_text.SetDisplayRect(Rect(50, 1000)); 2111 render_text.SetDisplayRect(Rect(50, 1000));
2111 render_text.SetMultiline(true); 2112 render_text.SetMultiline(true);
2113 render_text.SetWordWrapBehavior(WRAP_LONG_WORDS);
2112 render_text.SetHorizontalAlignment(ALIGN_TO_HEAD); 2114 render_text.SetHorizontalAlignment(ALIGN_TO_HEAD);
2113 2115
2114 Canvas canvas; 2116 Canvas canvas;
2115 TestSkiaTextRenderer renderer(&canvas); 2117 TestSkiaTextRenderer renderer(&canvas);
2116 2118
2117 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2119 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2118 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2120 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2119 render_text.SetText(WideToUTF16(kTestStrings[i].text)); 2121 render_text.SetText(WideToUTF16(kTestStrings[i].text));
2120 render_text.EnsureLayout(); 2122 render_text.EnsureLayout();
2121 render_text.DrawVisualTextInternal(&renderer); 2123 render_text.DrawVisualTextInternal(&renderer);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 std::vector<base::string16> lines; 2290 std::vector<base::string16> lines;
2289 base::SplitString(base::WideToUTF16(kTestStrings[i].text), '\n', &lines); 2291 base::SplitString(base::WideToUTF16(kTestStrings[i].text), '\n', &lines);
2290 ASSERT_EQ(2u, lines.size()); 2292 ASSERT_EQ(2u, lines.size());
2291 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize; 2293 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize;
2292 EXPECT_EQ(render_text.GetAlignmentOffset(0).x() + difference, 2294 EXPECT_EQ(render_text.GetAlignmentOffset(0).x() + difference,
2293 render_text.GetAlignmentOffset(1).x()); 2295 render_text.GetAlignmentOffset(1).x());
2294 } 2296 }
2295 } 2297 }
2296 } 2298 }
2297 2299
2300 TEST_F(RenderTextTest, Multiline_WordWrapBehavior) {
2301 const int kGlyphSize = 5;
2302 const struct {
2303 const WordWrapBehavior behavior;
2304 const size_t num_lines;
2305 const Range char_ranges[4];
2306 } kTestScenarios[] = {
2307 { IGNORE_LONG_WORDS, 3u,
2308 { Range(0, 4), Range(4, 11), Range(11, 14), Range::InvalidRange() } },
2309 { TRUNCATE_LONG_WORDS, 3u,
2310 { Range(0, 4), Range(4, 8), Range(11, 14), Range::InvalidRange() } },
2311 { WRAP_LONG_WORDS, 4u,
2312 { Range(0, 4), Range(4, 8), Range(8, 11), Range(11, 14) } },
2313 // TODO(mukai): implement ELIDE_LONG_WORDS. It's not used right now.
2314 };
2315 RenderTextHarfBuzz render_text;
2316 render_text.SetMultiline(true);
2317 render_text.SetText(ASCIIToUTF16("foo fooooo foo"));
2318 render_text.set_glyph_width_for_test(kGlyphSize);
2319 render_text.SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0));
2320
2321 Canvas canvas;
2322
2323 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) {
2324 SCOPED_TRACE(base::StringPrintf(
2325 "kTestScenarios[%" PRIuS "] %d", i, kTestScenarios[i].behavior));
2326 render_text.SetWordWrapBehavior(kTestScenarios[i].behavior);
2327 render_text.Draw(&canvas);
2328
2329 ASSERT_EQ(kTestScenarios[i].num_lines, render_text.lines().size());
2330 for (size_t j = 0; j < render_text.lines().size(); ++j) {
2331 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j));
2332 EXPECT_EQ(kTestScenarios[i].char_ranges[j],
2333 render_text.lines()[j].segments[0].char_range);
2334 }
2335 }
2336 }
2337
2298 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) { 2338 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) {
2299 const wchar_t* kTestStrings[] = { 2339 const wchar_t* kTestStrings[] = {
2300 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", 2340 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n",
2301 }; 2341 };
2302 2342
2303 RenderTextHarfBuzz render_text; 2343 RenderTextHarfBuzz render_text;
2304 render_text.SetDisplayRect(Rect(200, 1000)); 2344 render_text.SetDisplayRect(Rect(200, 1000));
2305 Canvas canvas; 2345 Canvas canvas;
2306 2346
2307 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2347 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 string_size.set_width(string_size.width() / 2); 2912 string_size.set_width(string_size.width() / 2);
2873 render_text.SetDisplayRect(gfx::Rect(string_size)); 2913 render_text.SetDisplayRect(gfx::Rect(string_size));
2874 render_text.EnsureLayout(); 2914 render_text.EnsureLayout();
2875 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); 2915 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_);
2876 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); 2916 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count));
2877 EXPECT_NE(0, glyph_count); 2917 EXPECT_NE(0, glyph_count);
2878 } 2918 }
2879 #endif 2919 #endif
2880 2920
2881 } // namespace gfx 2921 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698