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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 internal::SkiaTextRenderer::DrawDecorations( | 156 internal::SkiaTextRenderer::DrawDecorations( |
157 x, y, width, underline, strike, diagonal_strike); | 157 x, y, width, underline, strike, diagonal_strike); |
158 } | 158 } |
159 | 159 |
160 std::vector<TextLog> text_log_; | 160 std::vector<TextLog> text_log_; |
161 std::vector<DecorationLog> decoration_log_; | 161 std::vector<DecorationLog> decoration_log_; |
162 | 162 |
163 DISALLOW_COPY_AND_ASSIGN(TestSkiaTextRenderer); | 163 DISALLOW_COPY_AND_ASSIGN(TestSkiaTextRenderer); |
164 }; | 164 }; |
165 | 165 |
| 166 // Given a buffer to test against, this can be used to test various areas of the |
| 167 // rectangular buffer against a specific color value. |
| 168 class TestRectangleBuffer { |
| 169 public: |
| 170 TestRectangleBuffer(const wchar_t* string, |
| 171 const SkColor* buffer, |
| 172 uint32_t stride, |
| 173 uint32_t row_count) |
| 174 : string_(string), |
| 175 buffer_(buffer), |
| 176 stride_(stride), |
| 177 row_count_(row_count) {} |
| 178 |
| 179 // Test if any values in the rectangular area are anything other than |color|. |
| 180 void EnsureSolidRect(SkColor color, |
| 181 int left, |
| 182 int top, |
| 183 int width, |
| 184 int height) const { |
| 185 ASSERT_LT(top, row_count_) << string_; |
| 186 ASSERT_LE(top + height, row_count_) << string_; |
| 187 ASSERT_LT(left, stride_) << string_; |
| 188 ASSERT_LE(left + width, stride_) << string_ << ", left " << left |
| 189 << ", width " << width << ", stride_ " |
| 190 << stride_; |
| 191 for (int y = top; y < top + height; ++y) { |
| 192 for (int x = left; x < left + width; ++x) { |
| 193 SkColor color = buffer_[x + y * stride_]; |
| 194 EXPECT_EQ(SK_ColorWHITE, color) << string_ << " at " << x << ", " << y; |
| 195 } |
| 196 } |
| 197 } |
| 198 |
| 199 private: |
| 200 const wchar_t* string_; |
| 201 const SkColor* buffer_; |
| 202 int stride_; |
| 203 int row_count_; |
| 204 |
| 205 DISALLOW_COPY_AND_ASSIGN(TestRectangleBuffer); |
| 206 }; |
| 207 |
166 } // namespace | 208 } // namespace |
167 | 209 |
168 class RenderTextTest : public testing::Test { | 210 class RenderTextTest : public testing::Test { |
169 }; | 211 }; |
170 | 212 |
171 TEST_F(RenderTextTest, DefaultStyle) { | 213 TEST_F(RenderTextTest, DefaultStyle) { |
172 // Check the default styles applied to new instances and adjusted text. | 214 // Check the default styles applied to new instances and adjusted text. |
173 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 215 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
174 EXPECT_TRUE(render_text->text().empty()); | 216 EXPECT_TRUE(render_text->text().empty()); |
175 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; | 217 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; |
176 for (size_t i = 0; i < arraysize(cases); ++i) { | 218 for (size_t i = 0; i < arraysize(cases); ++i) { |
177 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); | 219 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); |
| 220 EXPECT_TRUE( |
| 221 render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE)); |
178 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) | 222 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) |
179 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false)); | 223 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false)); |
180 render_text->SetText(WideToUTF16(cases[i])); | 224 render_text->SetText(WideToUTF16(cases[i])); |
181 } | 225 } |
182 } | 226 } |
183 | 227 |
184 TEST_F(RenderTextTest, SetColorAndStyle) { | 228 TEST_F(RenderTextTest, SetColorAndStyle) { |
185 // Ensure custom default styles persist across setting and clearing text. | 229 // Ensure custom default styles persist across setting and clearing text. |
186 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 230 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
187 const SkColor color = SK_ColorRED; | 231 const SkColor color = SK_ColorRED; |
188 render_text->SetColor(color); | 232 render_text->SetColor(color); |
| 233 render_text->SetBaselineStyle(SUPERSCRIPT); |
189 render_text->SetStyle(BOLD, true); | 234 render_text->SetStyle(BOLD, true); |
190 render_text->SetStyle(UNDERLINE, false); | 235 render_text->SetStyle(UNDERLINE, false); |
191 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; | 236 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; |
192 for (size_t i = 0; i < arraysize(cases); ++i) { | 237 for (size_t i = 0; i < arraysize(cases); ++i) { |
193 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); | 238 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); |
| 239 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT)); |
194 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true)); | 240 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true)); |
195 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); | 241 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); |
196 render_text->SetText(WideToUTF16(cases[i])); | 242 render_text->SetText(WideToUTF16(cases[i])); |
197 | 243 |
198 // Ensure custom default styles can be applied after text has been set. | 244 // Ensure custom default styles can be applied after text has been set. |
199 if (i == 1) | 245 if (i == 1) |
200 render_text->SetStyle(STRIKE, true); | 246 render_text->SetStyle(STRIKE, true); |
201 if (i >= 1) | 247 if (i >= 1) |
202 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true)); | 248 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true)); |
203 } | 249 } |
204 } | 250 } |
205 | 251 |
206 TEST_F(RenderTextTest, ApplyColorAndStyle) { | 252 TEST_F(RenderTextTest, ApplyColorAndStyle) { |
207 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 253 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
208 render_text->SetText(ASCIIToUTF16("012345678")); | 254 render_text->SetText(ASCIIToUTF16("012345678")); |
209 | 255 |
210 // Apply a ranged color and style and check the resulting breaks. | 256 // Apply a ranged color and style and check the resulting breaks. |
211 render_text->ApplyColor(SK_ColorRED, Range(1, 4)); | 257 render_text->ApplyColor(SK_ColorRED, Range(1, 4)); |
| 258 render_text->ApplyBaselineStyle(SUPERIOR, Range(2, 4)); |
212 render_text->ApplyStyle(BOLD, true, Range(2, 5)); | 259 render_text->ApplyStyle(BOLD, true, Range(2, 5)); |
213 std::vector<std::pair<size_t, SkColor> > expected_color; | 260 std::vector<std::pair<size_t, SkColor> > expected_color; |
214 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); | 261 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); |
215 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED)); | 262 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED)); |
216 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK)); | 263 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK)); |
217 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | 264 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); |
| 265 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_style; |
| 266 expected_baseline_style.push_back( |
| 267 std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE)); |
| 268 expected_baseline_style.push_back( |
| 269 std::pair<size_t, BaselineStyle>(2, SUPERIOR)); |
| 270 expected_baseline_style.push_back( |
| 271 std::pair<size_t, BaselineStyle>(4, NORMAL_BASELINE)); |
| 272 EXPECT_TRUE( |
| 273 render_text->baselines().EqualsForTesting(expected_baseline_style)); |
218 std::vector<std::pair<size_t, bool> > expected_style; | 274 std::vector<std::pair<size_t, bool> > expected_style; |
219 expected_style.push_back(std::pair<size_t, bool>(0, false)); | 275 expected_style.push_back(std::pair<size_t, bool>(0, false)); |
220 expected_style.push_back(std::pair<size_t, bool>(2, true)); | 276 expected_style.push_back(std::pair<size_t, bool>(2, true)); |
221 expected_style.push_back(std::pair<size_t, bool>(5, false)); | 277 expected_style.push_back(std::pair<size_t, bool>(5, false)); |
222 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style)); | 278 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style)); |
223 | 279 |
224 // Ensure setting a color and style overrides the ranged colors and styles. | 280 // Ensure setting a color, baseline, and style overrides the ranged colors, |
| 281 // baseline, and styles. |
225 render_text->SetColor(SK_ColorBLUE); | 282 render_text->SetColor(SK_ColorBLUE); |
226 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLUE)); | 283 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLUE)); |
| 284 render_text->SetBaselineStyle(SUBSCRIPT); |
| 285 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUBSCRIPT)); |
227 render_text->SetStyle(BOLD, false); | 286 render_text->SetStyle(BOLD, false); |
228 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(false)); | 287 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(false)); |
229 | 288 |
230 // Apply a color and style over the text end and check the resulting breaks. | 289 // Apply a color, baseline, and style over the text end and check the |
231 // (INT_MAX should be used instead of the text length for the range end) | 290 // resulting breaks (INT_MAX should be used instead of the text length for |
| 291 // the range end) |
232 const size_t text_length = render_text->text().length(); | 292 const size_t text_length = render_text->text().length(); |
233 render_text->ApplyColor(SK_ColorRED, Range(0, text_length)); | 293 render_text->ApplyColor(SK_ColorRED, Range(0, text_length)); |
| 294 render_text->ApplyBaselineStyle(SUPERIOR, Range(0, text_length)); |
234 render_text->ApplyStyle(BOLD, true, Range(2, text_length)); | 295 render_text->ApplyStyle(BOLD, true, Range(2, text_length)); |
235 std::vector<std::pair<size_t, SkColor> > expected_color_end; | 296 std::vector<std::pair<size_t, SkColor> > expected_color_end; |
236 expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); | 297 expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); |
237 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color_end)); | 298 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color_end)); |
| 299 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_end; |
| 300 expected_baseline_end.push_back( |
| 301 std::pair<size_t, BaselineStyle>(0, SUPERIOR)); |
| 302 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline_end)); |
238 std::vector<std::pair<size_t, bool> > expected_style_end; | 303 std::vector<std::pair<size_t, bool> > expected_style_end; |
239 expected_style_end.push_back(std::pair<size_t, bool>(0, false)); | 304 expected_style_end.push_back(std::pair<size_t, bool>(0, false)); |
240 expected_style_end.push_back(std::pair<size_t, bool>(2, true)); | 305 expected_style_end.push_back(std::pair<size_t, bool>(2, true)); |
241 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style_end)); | 306 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style_end)); |
242 | 307 |
243 // Ensure ranged values adjust to accommodate text length changes. | 308 // Ensure ranged values adjust to accommodate text length changes. |
244 render_text->ApplyStyle(ITALIC, true, Range(0, 2)); | 309 render_text->ApplyStyle(ITALIC, true, Range(0, 2)); |
245 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); | 310 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); |
246 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); | 311 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); |
247 std::vector<std::pair<size_t, bool> > expected_italic; | 312 std::vector<std::pair<size_t, bool> > expected_italic; |
(...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2563 // Korean character "han". | 2628 // Korean character "han". |
2564 render_text.SetText(WideToUTF16(L"\xd55c")); | 2629 render_text.SetText(WideToUTF16(L"\xd55c")); |
2565 render_text.EnsureLayout(); | 2630 render_text.EnsureLayout(); |
2566 internal::TextRunList* run_list = render_text.GetRunList(); | 2631 internal::TextRunList* run_list = render_text.GetRunList(); |
2567 ASSERT_EQ(1U, run_list->size()); | 2632 ASSERT_EQ(1U, run_list->size()); |
2568 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); | 2633 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); |
2569 } | 2634 } |
2570 #endif // defined(OS_WIN) | 2635 #endif // defined(OS_WIN) |
2571 | 2636 |
2572 // Ensure that the width reported by RenderText is sufficient for drawing. Draws | 2637 // Ensure that the width reported by RenderText is sufficient for drawing. Draws |
2573 // to a canvas and checks whether any pixel beyond the width is colored. | 2638 // to a canvas and checks whether any pixel beyond the bounding rectangle is |
| 2639 // colored. |
2574 TEST_F(RenderTextTest, TextDoesntClip) { | 2640 TEST_F(RenderTextTest, TextDoesntClip) { |
2575 const wchar_t* kTestStrings[] = { L"Save", L"Remove", L"TEST", L"W", L"WWW" }; | 2641 const wchar_t* kTestStrings[] = { |
| 2642 L" ", |
| 2643 // TODO(mukai): Underscores draw outside GetStringSize; crbug.com/459812. |
| 2644 // L"TEST_______", |
| 2645 L"TEST some stuff", |
| 2646 L"WWWWWWWWWW", |
| 2647 L"gAXAXAXAXAXAXA", |
| 2648 // TODO(mukai): A-Ring draws outside GetStringSize; crbug.com/459812. |
| 2649 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", |
| 2650 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" |
| 2651 L"\x0628\x0627"}; |
2576 const Size kCanvasSize(300, 50); | 2652 const Size kCanvasSize(300, 50); |
2577 const int kTestWidth = 10; | 2653 const int kTestSize = 10; |
2578 | 2654 |
2579 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 2655 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
2580 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); | 2656 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); |
2581 scoped_ptr<Canvas> canvas( | 2657 scoped_ptr<Canvas> canvas( |
2582 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f)); | 2658 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f)); |
2583 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 2659 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
2584 render_text->SetDisplayRect(Rect(kCanvasSize)); | 2660 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
2585 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
2586 render_text->SetColor(SK_ColorBLACK); | 2661 render_text->SetColor(SK_ColorBLACK); |
2587 | 2662 |
2588 for (auto string : kTestStrings) { | 2663 for (auto string : kTestStrings) { |
2589 surface->getCanvas()->clear(SK_ColorWHITE); | 2664 surface->getCanvas()->clear(SK_ColorWHITE); |
2590 render_text->SetText(WideToUTF16(string)); | 2665 render_text->SetText(WideToUTF16(string)); |
| 2666 const Size string_size = render_text->GetStringSize(); |
| 2667 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); |
| 2668 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4)); |
| 2669 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6)); |
| 2670 render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8)); |
2591 render_text->SetStyle(BOLD, true); | 2671 render_text->SetStyle(BOLD, true); |
| 2672 render_text->SetDisplayRect( |
| 2673 Rect(kTestSize, kTestSize, string_size.width(), string_size.height())); |
| 2674 // Allow the RenderText to paint outside of its display rect. |
| 2675 render_text->set_clip_to_display_rect(false); |
| 2676 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width()); |
| 2677 |
2592 render_text->Draw(canvas.get()); | 2678 render_text->Draw(canvas.get()); |
2593 int width = render_text->GetStringSize().width(); | 2679 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); |
2594 ASSERT_LT(width + kTestWidth, kCanvasSize.width()); | 2680 const uint32* buffer = |
2595 const uint32* buffer = static_cast<const uint32*>( | 2681 static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr)); |
2596 surface->peekPixels(NULL, NULL)); | |
2597 ASSERT_NE(nullptr, buffer); | 2682 ASSERT_NE(nullptr, buffer); |
2598 | 2683 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), |
2599 for (int y = 0; y < kCanvasSize.height(); ++y) { | 2684 kCanvasSize.height()); |
2600 // Allow one column of anti-aliased pixels past the expected width. | 2685 { |
2601 SkColor color = buffer[width + y * kCanvasSize.width()]; | 2686 SCOPED_TRACE("TextDoesntClip Top Side"); |
2602 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string; | 2687 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(), |
2603 for (int x = 1; x < kTestWidth; ++x) { | 2688 kTestSize); |
2604 color = buffer[width + x + y * kCanvasSize.width()]; | 2689 } |
2605 EXPECT_EQ(SK_ColorWHITE, color) << string; | 2690 { |
2606 } | 2691 SCOPED_TRACE("TextDoesntClip Bottom Side"); |
| 2692 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, |
| 2693 kTestSize + string_size.height(), |
| 2694 kCanvasSize.width(), kTestSize); |
| 2695 } |
| 2696 { |
| 2697 SCOPED_TRACE("TextDoesntClip Left Side"); |
| 2698 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 2699 // TODO(mukai): On Windows and Mac smoothing draws left of text. |
| 2700 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize, kTestSize - 1, |
| 2701 string_size.height()); |
| 2702 #else |
| 2703 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize, kTestSize, |
| 2704 string_size.height()); |
| 2705 #endif |
| 2706 } |
| 2707 { |
| 2708 SCOPED_TRACE("TextDoesntClip Right Side"); |
| 2709 #if !defined(OS_MACOSX) |
| 2710 // TODO(mukai): On Mac text draws to right of GetStringSize |
| 2711 rect_buffer.EnsureSolidRect(SK_ColorWHITE, |
| 2712 kTestSize + string_size.width(), kTestSize, |
| 2713 kTestSize, string_size.height()); |
| 2714 #endif |
2607 } | 2715 } |
2608 } | 2716 } |
2609 } | 2717 } |
| 2718 |
| 2719 // Ensure that the text will clip to the display rect. Draws to a canvas and |
| 2720 // checks whether any pixel beyond the bounding rectangle is colored. |
| 2721 TEST_F(RenderTextTest, TextDoesClip) { |
| 2722 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; |
| 2723 const Size kCanvasSize(300, 50); |
| 2724 const int kTestSize = 10; |
| 2725 |
| 2726 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
| 2727 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); |
| 2728 scoped_ptr<Canvas> canvas( |
| 2729 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f)); |
| 2730 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 2731 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
| 2732 render_text->SetColor(SK_ColorBLACK); |
| 2733 |
| 2734 for (auto string : kTestStrings) { |
| 2735 surface->getCanvas()->clear(SK_ColorWHITE); |
| 2736 render_text->SetText(WideToUTF16(string)); |
| 2737 const Size string_size = render_text->GetStringSize(); |
| 2738 int fake_width = string_size.width() / 2; |
| 2739 int fake_height = string_size.height() / 2; |
| 2740 render_text->SetDisplayRect( |
| 2741 Rect(kTestSize, kTestSize, fake_width, fake_height)); |
| 2742 render_text->set_clip_to_display_rect(true); |
| 2743 render_text->Draw(canvas.get()); |
| 2744 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); |
| 2745 const uint32* buffer = |
| 2746 static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr)); |
| 2747 ASSERT_NE(nullptr, buffer); |
| 2748 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), |
| 2749 kCanvasSize.height()); |
| 2750 { |
| 2751 SCOPED_TRACE("TextDoesClip Top Side"); |
| 2752 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(), |
| 2753 kTestSize); |
| 2754 } |
| 2755 |
| 2756 { |
| 2757 SCOPED_TRACE("TextDoesClip Bottom Side"); |
| 2758 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize + fake_height, |
| 2759 kCanvasSize.width(), kTestSize); |
| 2760 } |
| 2761 { |
| 2762 SCOPED_TRACE("TextDoesClip Left Side"); |
| 2763 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize, kTestSize, |
| 2764 fake_height); |
| 2765 } |
| 2766 { |
| 2767 SCOPED_TRACE("TextDoesClip Right Side"); |
| 2768 rect_buffer.EnsureSolidRect(SK_ColorWHITE, kTestSize + fake_width, |
| 2769 kTestSize, kTestSize, fake_height); |
| 2770 } |
| 2771 } |
| 2772 } |
2610 | 2773 |
2611 } // namespace gfx | 2774 } // namespace gfx |
OLD | NEW |