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 | |
208 } // namespace | 166 } // namespace |
209 | 167 |
210 class RenderTextTest : public testing::Test { | 168 class RenderTextTest : public testing::Test { |
211 }; | 169 }; |
212 | 170 |
213 TEST_F(RenderTextTest, DefaultStyle) { | 171 TEST_F(RenderTextTest, DefaultStyle) { |
214 // Check the default styles applied to new instances and adjusted text. | 172 // Check the default styles applied to new instances and adjusted text. |
215 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 173 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
216 EXPECT_TRUE(render_text->text().empty()); | 174 EXPECT_TRUE(render_text->text().empty()); |
217 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; | 175 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; |
218 for (size_t i = 0; i < arraysize(cases); ++i) { | 176 for (size_t i = 0; i < arraysize(cases); ++i) { |
219 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); | 177 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); |
220 EXPECT_TRUE( | |
221 render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE)); | |
222 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) | 178 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) |
223 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false)); | 179 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false)); |
224 render_text->SetText(WideToUTF16(cases[i])); | 180 render_text->SetText(WideToUTF16(cases[i])); |
225 } | 181 } |
226 } | 182 } |
227 | 183 |
228 TEST_F(RenderTextTest, SetColorAndStyle) { | 184 TEST_F(RenderTextTest, SetColorAndStyle) { |
229 // Ensure custom default styles persist across setting and clearing text. | 185 // Ensure custom default styles persist across setting and clearing text. |
230 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 186 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
231 const SkColor color = SK_ColorRED; | 187 const SkColor color = SK_ColorRED; |
232 render_text->SetColor(color); | 188 render_text->SetColor(color); |
233 render_text->SetBaselineStyle(SUPERSCRIPT); | |
234 render_text->SetStyle(BOLD, true); | 189 render_text->SetStyle(BOLD, true); |
235 render_text->SetStyle(UNDERLINE, false); | 190 render_text->SetStyle(UNDERLINE, false); |
236 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; | 191 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; |
237 for (size_t i = 0; i < arraysize(cases); ++i) { | 192 for (size_t i = 0; i < arraysize(cases); ++i) { |
238 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); | 193 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); |
239 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT)); | |
240 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true)); | 194 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true)); |
241 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); | 195 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); |
242 render_text->SetText(WideToUTF16(cases[i])); | 196 render_text->SetText(WideToUTF16(cases[i])); |
243 | 197 |
244 // Ensure custom default styles can be applied after text has been set. | 198 // Ensure custom default styles can be applied after text has been set. |
245 if (i == 1) | 199 if (i == 1) |
246 render_text->SetStyle(STRIKE, true); | 200 render_text->SetStyle(STRIKE, true); |
247 if (i >= 1) | 201 if (i >= 1) |
248 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true)); | 202 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true)); |
249 } | 203 } |
250 } | 204 } |
251 | 205 |
252 TEST_F(RenderTextTest, ApplyColorAndStyle) { | 206 TEST_F(RenderTextTest, ApplyColorAndStyle) { |
253 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 207 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
254 render_text->SetText(ASCIIToUTF16("012345678")); | 208 render_text->SetText(ASCIIToUTF16("012345678")); |
255 | 209 |
256 // Apply a ranged color and style and check the resulting breaks. | 210 // Apply a ranged color and style and check the resulting breaks. |
257 render_text->ApplyColor(SK_ColorRED, Range(1, 4)); | 211 render_text->ApplyColor(SK_ColorRED, Range(1, 4)); |
258 render_text->ApplyBaselineStyle(SUPERIOR, Range(2, 4)); | |
259 render_text->ApplyStyle(BOLD, true, Range(2, 5)); | 212 render_text->ApplyStyle(BOLD, true, Range(2, 5)); |
260 std::vector<std::pair<size_t, SkColor> > expected_color; | 213 std::vector<std::pair<size_t, SkColor> > expected_color; |
261 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); | 214 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); |
262 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED)); | 215 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED)); |
263 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK)); | 216 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK)); |
264 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | 217 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)); | |
274 std::vector<std::pair<size_t, bool> > expected_style; | 218 std::vector<std::pair<size_t, bool> > expected_style; |
275 expected_style.push_back(std::pair<size_t, bool>(0, false)); | 219 expected_style.push_back(std::pair<size_t, bool>(0, false)); |
276 expected_style.push_back(std::pair<size_t, bool>(2, true)); | 220 expected_style.push_back(std::pair<size_t, bool>(2, true)); |
277 expected_style.push_back(std::pair<size_t, bool>(5, false)); | 221 expected_style.push_back(std::pair<size_t, bool>(5, false)); |
278 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style)); | 222 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style)); |
279 | 223 |
280 // Ensure setting a color, baseline, and style overrides the ranged colors, | 224 // Ensure setting a color and style overrides the ranged colors and styles. |
281 // baseline, and styles. | |
282 render_text->SetColor(SK_ColorBLUE); | 225 render_text->SetColor(SK_ColorBLUE); |
283 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLUE)); | 226 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLUE)); |
284 render_text->SetBaselineStyle(SUBSCRIPT); | |
285 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUBSCRIPT)); | |
286 render_text->SetStyle(BOLD, false); | 227 render_text->SetStyle(BOLD, false); |
287 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(false)); | 228 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(false)); |
288 | 229 |
289 // Apply a color, baseline, and style over the text end and check the | 230 // Apply a color and style over the text end and check the resulting breaks. |
290 // resulting breaks (INT_MAX should be used instead of the text length for | 231 // (INT_MAX should be used instead of the text length for the range end) |
291 // the range end) | |
292 const size_t text_length = render_text->text().length(); | 232 const size_t text_length = render_text->text().length(); |
293 render_text->ApplyColor(SK_ColorRED, Range(0, text_length)); | 233 render_text->ApplyColor(SK_ColorRED, Range(0, text_length)); |
294 render_text->ApplyBaselineStyle(SUPERIOR, Range(0, text_length)); | |
295 render_text->ApplyStyle(BOLD, true, Range(2, text_length)); | 234 render_text->ApplyStyle(BOLD, true, Range(2, text_length)); |
296 std::vector<std::pair<size_t, SkColor> > expected_color_end; | 235 std::vector<std::pair<size_t, SkColor> > expected_color_end; |
297 expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); | 236 expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); |
298 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color_end)); | 237 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)); | |
303 std::vector<std::pair<size_t, bool> > expected_style_end; | 238 std::vector<std::pair<size_t, bool> > expected_style_end; |
304 expected_style_end.push_back(std::pair<size_t, bool>(0, false)); | 239 expected_style_end.push_back(std::pair<size_t, bool>(0, false)); |
305 expected_style_end.push_back(std::pair<size_t, bool>(2, true)); | 240 expected_style_end.push_back(std::pair<size_t, bool>(2, true)); |
306 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style_end)); | 241 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style_end)); |
307 | 242 |
308 // Ensure ranged values adjust to accommodate text length changes. | 243 // Ensure ranged values adjust to accommodate text length changes. |
309 render_text->ApplyStyle(ITALIC, true, Range(0, 2)); | 244 render_text->ApplyStyle(ITALIC, true, Range(0, 2)); |
310 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); | 245 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); |
311 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); | 246 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); |
312 std::vector<std::pair<size_t, bool> > expected_italic; | 247 std::vector<std::pair<size_t, bool> > expected_italic; |
(...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2628 // Korean character "han". | 2563 // Korean character "han". |
2629 render_text.SetText(WideToUTF16(L"\xd55c")); | 2564 render_text.SetText(WideToUTF16(L"\xd55c")); |
2630 render_text.EnsureLayout(); | 2565 render_text.EnsureLayout(); |
2631 internal::TextRunList* run_list = render_text.GetRunList(); | 2566 internal::TextRunList* run_list = render_text.GetRunList(); |
2632 ASSERT_EQ(1U, run_list->size()); | 2567 ASSERT_EQ(1U, run_list->size()); |
2633 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); | 2568 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); |
2634 } | 2569 } |
2635 #endif // defined(OS_WIN) | 2570 #endif // defined(OS_WIN) |
2636 | 2571 |
2637 // Ensure that the width reported by RenderText is sufficient for drawing. Draws | 2572 // Ensure that the width reported by RenderText is sufficient for drawing. Draws |
2638 // to a canvas and checks whether any pixel beyond the bounding rectangle is | 2573 // to a canvas and checks whether any pixel beyond the width is colored. |
2639 // colored. | |
2640 TEST_F(RenderTextTest, TextDoesntClip) { | 2574 TEST_F(RenderTextTest, TextDoesntClip) { |
2641 const wchar_t* kTestStrings[] = { | 2575 const wchar_t* kTestStrings[] = { L"Save", L"Remove", L"TEST", L"W", L"WWW" }; |
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"}; | |
2652 const Size kCanvasSize(300, 50); | 2576 const Size kCanvasSize(300, 50); |
2653 const int kTestSize = 10; | 2577 const int kTestWidth = 10; |
2654 | 2578 |
2655 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 2579 skia::RefPtr<SkSurface> surface = skia::AdoptRef( |
2656 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); | 2580 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); |
2657 scoped_ptr<Canvas> canvas( | 2581 scoped_ptr<Canvas> canvas( |
2658 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f)); | 2582 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f)); |
2659 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 2583 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
2660 render_text->SetHorizontalAlignment(ALIGN_LEFT); | 2584 render_text->SetDisplayRect(Rect(kCanvasSize)); |
| 2585 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
2661 render_text->SetColor(SK_ColorBLACK); | 2586 render_text->SetColor(SK_ColorBLACK); |
2662 | 2587 |
2663 for (auto string : kTestStrings) { | 2588 for (auto string : kTestStrings) { |
2664 surface->getCanvas()->clear(SK_ColorWHITE); | 2589 surface->getCanvas()->clear(SK_ColorWHITE); |
2665 render_text->SetText(WideToUTF16(string)); | 2590 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)); | |
2671 render_text->SetStyle(BOLD, true); | 2591 render_text->SetStyle(BOLD, true); |
2672 render_text->SetDisplayRect( | 2592 render_text->Draw(canvas.get()); |
2673 Rect(kTestSize, kTestSize, string_size.width(), string_size.height())); | 2593 int width = render_text->GetStringSize().width(); |
2674 // Allow the RenderText to paint outside of its display rect. | 2594 ASSERT_LT(width + kTestWidth, kCanvasSize.width()); |
2675 render_text->set_clip_to_display_rect(false); | 2595 const uint32* buffer = static_cast<const uint32*>( |
2676 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width()); | 2596 surface->peekPixels(NULL, NULL)); |
| 2597 ASSERT_NE(nullptr, buffer); |
2677 | 2598 |
2678 render_text->Draw(canvas.get()); | 2599 for (int y = 0; y < kCanvasSize.height(); ++y) { |
2679 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); | 2600 // Allow one column of anti-aliased pixels past the expected width. |
2680 const uint32* buffer = | 2601 SkColor color = buffer[width + y * kCanvasSize.width()]; |
2681 static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr)); | 2602 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string; |
2682 ASSERT_NE(nullptr, buffer); | 2603 for (int x = 1; x < kTestWidth; ++x) { |
2683 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), | 2604 color = buffer[width + x + y * kCanvasSize.width()]; |
2684 kCanvasSize.height()); | 2605 EXPECT_EQ(SK_ColorWHITE, color) << string; |
2685 { | 2606 } |
2686 SCOPED_TRACE("TextDoesntClip Top Side"); | |
2687 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(), | |
2688 kTestSize); | |
2689 } | |
2690 { | |
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 | |
2715 } | 2607 } |
2716 } | 2608 } |
2717 } | 2609 } |
2718 | 2610 |
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 } | |
2773 | |
2774 } // namespace gfx | 2611 } // namespace gfx |
OLD | NEW |