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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/string_split.h" | |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/skia/include/core/SkSurface.h" | 17 #include "third_party/skia/include/core/SkSurface.h" |
17 #include "ui/gfx/break_list.h" | 18 #include "ui/gfx/break_list.h" |
18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
19 #include "ui/gfx/color_utils.h" | 20 #include "ui/gfx/color_utils.h" |
20 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.h" |
21 #include "ui/gfx/range/range.h" | 22 #include "ui/gfx/range/range.h" |
(...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2136 // by symbols, therefore the character should be changed. | 2137 // by symbols, therefore the character should be changed. |
2137 EXPECT_NE(WideToUTF16(kTestStrings[i]), render_text.GetDisplayText()); | 2138 EXPECT_NE(WideToUTF16(kTestStrings[i]), render_text.GetDisplayText()); |
2138 | 2139 |
2139 // Setting multiline will fix this, the newline characters will be back | 2140 // Setting multiline will fix this, the newline characters will be back |
2140 // to the original text. | 2141 // to the original text. |
2141 render_text.SetMultiline(true); | 2142 render_text.SetMultiline(true); |
2142 EXPECT_EQ(WideToUTF16(kTestStrings[i]), render_text.GetDisplayText()); | 2143 EXPECT_EQ(WideToUTF16(kTestStrings[i]), render_text.GetDisplayText()); |
2143 } | 2144 } |
2144 } | 2145 } |
2145 | 2146 |
2147 #if !defined(OS_MACOSX) | |
msw
2015/02/24 03:27:59
nit: Oh darn, this should work on Mac (using RTHB)
oshima
2015/02/24 03:49:33
This won't work on mac as is. This should work wit
| |
2148 // Ensure horizontal alignment works in multiline mode. | |
2149 TEST_F(RenderTextTest, Multiline_HorizontalAlignment) { | |
2150 const struct { | |
2151 const wchar_t* const text; | |
2152 const gfx::HorizontalAlignment alignment; | |
2153 } kTestStrings[] = { | |
2154 { L"abcdefghij\nhijkl", gfx::ALIGN_LEFT }, | |
2155 { L"nhijkl\nabcdefghij", gfx::ALIGN_LEFT }, | |
2156 // hebrew, 2nd line shorter | |
2157 { L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7\n\x5d0\x5d1\x5d2\x5d3", | |
2158 gfx::ALIGN_RIGHT }, | |
2159 // hebrew, 2nd line longer | |
2160 { L"\x5d0\x5d1\x5d2\x5d3\n\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7", | |
2161 gfx::ALIGN_RIGHT }, | |
2162 // arabic, 2nd line shorter | |
2163 { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664", | |
2164 gfx::ALIGN_RIGHT }, | |
2165 // arabic, 2nd line longer | |
2166 { L"\x660\x661\x662\x663\x664\n\x62a\x62b\x62c\x62d\x62e\x62f\x630", | |
2167 gfx::ALIGN_RIGHT }, | |
2168 }; | |
2169 const int kGlyphSize = 5; | |
2170 RenderTextHarfBuzz render_text; | |
2171 render_text.SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); | |
2172 render_text.set_glyph_width_for_test(kGlyphSize); | |
2173 render_text.SetDisplayRect(Rect(100, 1000)); | |
2174 render_text.SetMultiline(true); | |
2175 | |
2176 Canvas canvas; | |
2177 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | |
2178 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i, | |
2179 kTestStrings[i].text)); | |
2180 render_text.SetText(WideToUTF16(kTestStrings[i].text)); | |
2181 render_text.Draw(&canvas); | |
2182 ASSERT_LE(2u, render_text.lines().size()); | |
2183 if (kTestStrings[i].alignment == gfx::ALIGN_LEFT) { | |
2184 EXPECT_EQ(0, render_text.GetAlignmentOffset(0).x()); | |
2185 EXPECT_EQ(0, render_text.GetAlignmentOffset(1).x()); | |
2186 } else { | |
2187 std::vector<base::string16> lines; | |
2188 base::SplitString(base::WideToUTF16(kTestStrings[i].text), '\n', &lines); | |
2189 ASSERT_EQ(2u, lines.size()); | |
2190 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize; | |
2191 EXPECT_EQ(render_text.GetAlignmentOffset(0).x() + difference, | |
2192 render_text.GetAlignmentOffset(1).x()); | |
2193 } | |
2194 } | |
2195 } | |
2196 #endif | |
2197 | |
2146 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) { | 2198 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) { |
2147 const wchar_t* kTestStrings[] = { | 2199 const wchar_t* kTestStrings[] = { |
2148 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", | 2200 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", |
2149 }; | 2201 }; |
2150 | 2202 |
2151 RenderTextHarfBuzz render_text; | 2203 RenderTextHarfBuzz render_text; |
2152 render_text.SetDisplayRect(Rect(200, 1000)); | 2204 render_text.SetDisplayRect(Rect(200, 1000)); |
2153 Canvas canvas; | 2205 Canvas canvas; |
2154 | 2206 |
2155 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2207 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2552 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string; | 2604 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string; |
2553 for (int x = 1; x < kTestWidth; ++x) { | 2605 for (int x = 1; x < kTestWidth; ++x) { |
2554 color = buffer[width + x + y * kCanvasSize.width()]; | 2606 color = buffer[width + x + y * kCanvasSize.width()]; |
2555 EXPECT_EQ(SK_ColorWHITE, color) << string; | 2607 EXPECT_EQ(SK_ColorWHITE, color) << string; |
2556 } | 2608 } |
2557 } | 2609 } |
2558 } | 2610 } |
2559 } | 2611 } |
2560 | 2612 |
2561 } // namespace gfx | 2613 } // namespace gfx |
OLD | NEW |