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

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

Issue 924543004: adding baseline options for super/sub scripting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed draw rect test; added bug numbers 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 internal::SkiaTextRenderer::DrawDecorations( 155 internal::SkiaTextRenderer::DrawDecorations(
156 x, y, width, underline, strike, diagonal_strike); 156 x, y, width, underline, strike, diagonal_strike);
157 } 157 }
158 158
159 std::vector<TextLog> text_log_; 159 std::vector<TextLog> text_log_;
160 std::vector<DecorationLog> decoration_log_; 160 std::vector<DecorationLog> decoration_log_;
161 161
162 DISALLOW_COPY_AND_ASSIGN(TestSkiaTextRenderer); 162 DISALLOW_COPY_AND_ASSIGN(TestSkiaTextRenderer);
163 }; 163 };
164 164
165 // Given a buffer to test against, this can be used to test various areas of the
166 // rectangular buffer against a specific color value.
167 class TestRectangleBuffer {
168 public:
169 TestRectangleBuffer(const wchar_t* string,
170 const SkColor* buffer,
171 uint32_t stride,
172 uint32_t row_count)
173 : string_(string),
174 buffer_(buffer),
175 stride_(stride),
176 row_count_(row_count) {}
177
178 // Test whether any values in the rectangular area are anything other than
msw 2015/02/27 03:48:06 nit: s/whether/if/ for a one-liner.
dschuyler 2015/02/27 21:45:20 Done.
179 // |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 void AsciiRender(int left, int top, int width, int height) const {
200 std::cout << "AsciiRender: " << string_ << std::endl;
201 for (int y = top; y < top + height; ++y) {
202 ::testing::Message m;
203 m << y << ": ";
204 for (int x = left; x < left + width; ++x) {
205 m << AsciiColor(buffer_[x + y * stride_]);
206 }
207 std::cout << m << std::endl;
208 }
209 }
210
211 protected:
212 const wchar_t* string_;
213 const SkColor* buffer_;
214 int stride_;
215 int row_count_;
216
217 char AsciiColor(SkColor color) const {
218 unsigned char* c = (unsigned char*)&color;
219 unsigned char combined = c[0] | c[1] | c[2];
220 if (!c[3] && combined >= 'A' && combined <= 'Z') {
221 return combined;
222 }
223 if (255U == color_utils::GetLuminanceForColor(color)) {
224 return '-';
225 }
226 return 'a' + combined / 26;
227 }
228
229 private:
230 DISALLOW_COPY_AND_ASSIGN(TestRectangleBuffer);
231 };
232
165 } // namespace 233 } // namespace
166 234
167 class RenderTextTest : public testing::Test { 235 class RenderTextTest : public testing::Test {
168 }; 236 };
169 237
170 TEST_F(RenderTextTest, DefaultStyle) { 238 TEST_F(RenderTextTest, DefaultStyle) {
171 // Check the default styles applied to new instances and adjusted text. 239 // Check the default styles applied to new instances and adjusted text.
172 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 240 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
173 EXPECT_TRUE(render_text->text().empty()); 241 EXPECT_TRUE(render_text->text().empty());
174 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; 242 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" };
175 for (size_t i = 0; i < arraysize(cases); ++i) { 243 for (size_t i = 0; i < arraysize(cases); ++i) {
176 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); 244 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK));
245 EXPECT_TRUE(
246 render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE));
177 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) 247 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
178 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false)); 248 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false));
179 render_text->SetText(WideToUTF16(cases[i])); 249 render_text->SetText(WideToUTF16(cases[i]));
180 } 250 }
181 } 251 }
182 252
183 TEST_F(RenderTextTest, SetColorAndStyle) { 253 TEST_F(RenderTextTest, SetColorAndStyle) {
184 // Ensure custom default styles persist across setting and clearing text. 254 // Ensure custom default styles persist across setting and clearing text.
185 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 255 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
186 const SkColor color = SK_ColorRED; 256 const SkColor color = SK_ColorRED;
187 render_text->SetColor(color); 257 render_text->SetColor(color);
258 render_text->SetBaselineStyle(SUPERSCRIPT);
188 render_text->SetStyle(BOLD, true); 259 render_text->SetStyle(BOLD, true);
189 render_text->SetStyle(UNDERLINE, false); 260 render_text->SetStyle(UNDERLINE, false);
190 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; 261 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" };
191 for (size_t i = 0; i < arraysize(cases); ++i) { 262 for (size_t i = 0; i < arraysize(cases); ++i) {
192 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); 263 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color));
264 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT));
193 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true)); 265 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true));
194 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); 266 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false));
195 render_text->SetText(WideToUTF16(cases[i])); 267 render_text->SetText(WideToUTF16(cases[i]));
196 268
197 // Ensure custom default styles can be applied after text has been set. 269 // Ensure custom default styles can be applied after text has been set.
198 if (i == 1) 270 if (i == 1)
199 render_text->SetStyle(STRIKE, true); 271 render_text->SetStyle(STRIKE, true);
200 if (i >= 1) 272 if (i >= 1)
201 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true)); 273 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true));
202 } 274 }
203 } 275 }
204 276
205 TEST_F(RenderTextTest, ApplyColorAndStyle) { 277 TEST_F(RenderTextTest, ApplyColorAndStyle) {
206 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 278 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
207 render_text->SetText(ASCIIToUTF16("012345678")); 279 render_text->SetText(ASCIIToUTF16("012345678"));
208 280
209 // Apply a ranged color and style and check the resulting breaks. 281 // Apply a ranged color and style and check the resulting breaks.
210 render_text->ApplyColor(SK_ColorRED, Range(1, 4)); 282 render_text->ApplyColor(SK_ColorRED, Range(1, 4));
283 render_text->ApplyBaselineStyle(SUPERIOR, Range(2, 4));
211 render_text->ApplyStyle(BOLD, true, Range(2, 5)); 284 render_text->ApplyStyle(BOLD, true, Range(2, 5));
212 std::vector<std::pair<size_t, SkColor> > expected_color; 285 std::vector<std::pair<size_t, SkColor> > expected_color;
213 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); 286 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK));
214 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED)); 287 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED));
215 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK)); 288 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK));
216 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); 289 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color));
290 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_style;
291 expected_baseline_style.push_back(
292 std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE));
293 expected_baseline_style.push_back(
294 std::pair<size_t, BaselineStyle>(2, SUPERIOR));
295 expected_baseline_style.push_back(
296 std::pair<size_t, BaselineStyle>(4, NORMAL_BASELINE));
297 EXPECT_TRUE(
298 render_text->baselines().EqualsForTesting(expected_baseline_style));
217 std::vector<std::pair<size_t, bool> > expected_style; 299 std::vector<std::pair<size_t, bool> > expected_style;
218 expected_style.push_back(std::pair<size_t, bool>(0, false)); 300 expected_style.push_back(std::pair<size_t, bool>(0, false));
219 expected_style.push_back(std::pair<size_t, bool>(2, true)); 301 expected_style.push_back(std::pair<size_t, bool>(2, true));
220 expected_style.push_back(std::pair<size_t, bool>(5, false)); 302 expected_style.push_back(std::pair<size_t, bool>(5, false));
221 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style)); 303 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style));
222 304
223 // Ensure setting a color and style overrides the ranged colors and styles. 305 // Ensure setting a color, baseline, and style overrides the ranged colors,
306 // baseline, and styles.
224 render_text->SetColor(SK_ColorBLUE); 307 render_text->SetColor(SK_ColorBLUE);
225 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLUE)); 308 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLUE));
309 render_text->SetBaselineStyle(SUBSCRIPT);
310 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUBSCRIPT));
226 render_text->SetStyle(BOLD, false); 311 render_text->SetStyle(BOLD, false);
227 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(false)); 312 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(false));
228 313
229 // Apply a color and style over the text end and check the resulting breaks. 314 // Apply a color, baseline, and style over the text end and check the
230 // (INT_MAX should be used instead of the text length for the range end) 315 // resulting breaks (INT_MAX should be used instead of the text length for
316 // the range end)
231 const size_t text_length = render_text->text().length(); 317 const size_t text_length = render_text->text().length();
232 render_text->ApplyColor(SK_ColorRED, Range(0, text_length)); 318 render_text->ApplyColor(SK_ColorRED, Range(0, text_length));
319 render_text->ApplyBaselineStyle(SUPERIOR, Range(0, text_length));
233 render_text->ApplyStyle(BOLD, true, Range(2, text_length)); 320 render_text->ApplyStyle(BOLD, true, Range(2, text_length));
234 std::vector<std::pair<size_t, SkColor> > expected_color_end; 321 std::vector<std::pair<size_t, SkColor> > expected_color_end;
235 expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); 322 expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED));
236 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color_end)); 323 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color_end));
324 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_end;
325 expected_baseline_end.push_back(
326 std::pair<size_t, BaselineStyle>(0, SUPERIOR));
327 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline_end));
237 std::vector<std::pair<size_t, bool> > expected_style_end; 328 std::vector<std::pair<size_t, bool> > expected_style_end;
238 expected_style_end.push_back(std::pair<size_t, bool>(0, false)); 329 expected_style_end.push_back(std::pair<size_t, bool>(0, false));
239 expected_style_end.push_back(std::pair<size_t, bool>(2, true)); 330 expected_style_end.push_back(std::pair<size_t, bool>(2, true));
240 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style_end)); 331 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style_end));
241 332
242 // Ensure ranged values adjust to accommodate text length changes. 333 // Ensure ranged values adjust to accommodate text length changes.
243 render_text->ApplyStyle(ITALIC, true, Range(0, 2)); 334 render_text->ApplyStyle(ITALIC, true, Range(0, 2));
244 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); 335 render_text->ApplyStyle(ITALIC, true, Range(3, 6));
245 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); 336 render_text->ApplyStyle(ITALIC, true, Range(7, text_length));
246 std::vector<std::pair<size_t, bool> > expected_italic; 337 std::vector<std::pair<size_t, bool> > expected_italic;
(...skipping 2266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 // Korean character "han". 2604 // Korean character "han".
2514 render_text.SetText(WideToUTF16(L"\xd55c")); 2605 render_text.SetText(WideToUTF16(L"\xd55c"));
2515 render_text.EnsureLayout(); 2606 render_text.EnsureLayout();
2516 internal::TextRunList* run_list = render_text.GetRunList(); 2607 internal::TextRunList* run_list = render_text.GetRunList();
2517 ASSERT_EQ(1U, run_list->size()); 2608 ASSERT_EQ(1U, run_list->size());
2518 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); 2609 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs());
2519 } 2610 }
2520 #endif // defined(OS_WIN) 2611 #endif // defined(OS_WIN)
2521 2612
2522 // Ensure that the width reported by RenderText is sufficient for drawing. Draws 2613 // Ensure that the width reported by RenderText is sufficient for drawing. Draws
2523 // to a canvas and checks whether any pixel beyond the width is colored. 2614 // to a canvas and checks whether any pixel beyond the bounding rectangle is
2615 // colored.
2524 TEST_F(RenderTextTest, TextDoesntClip) { 2616 TEST_F(RenderTextTest, TextDoesntClip) {
2525 const wchar_t* kTestStrings[] = { L"Save", L"Remove", L"TEST", L"W", L"WWW" }; 2617 const wchar_t* kTestStrings[] = {
2618 // BUG=459812 The underscore will draw outside of the GetStringSize rect.
msw 2015/02/27 03:48:06 // TODO(mukai): Underscores draw outside GetString
dschuyler 2015/02/27 21:45:20 Done.
2619 // L"TEST_______",
2620 L"TEST some stuff",
2621 L"WWWWWWWWWW",
2622 L"gAXAXAXAXAXAXA",
2623 // BUG=459812 The A-Ring will draw outside of the GetStringSize rect.
msw 2015/02/27 03:48:06 // TODO(mukai): A-Ring draws outside GetStringSize
dschuyler 2015/02/27 21:45:20 Done.
2624 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5",
2625 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D"
2626 L"\x0628\x0627"};
2526 const Size kCanvasSize(300, 50); 2627 const Size kCanvasSize(300, 50);
2527 const int kTestWidth = 10; 2628 const int kTestSize = 10;
2528 2629
2529 skia::RefPtr<SkSurface> surface = skia::AdoptRef( 2630 skia::RefPtr<SkSurface> surface = skia::AdoptRef(
2530 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); 2631 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()));
2531 scoped_ptr<Canvas> canvas( 2632 scoped_ptr<Canvas> canvas(
2532 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f)); 2633 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f));
2533 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 2634 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
2534 render_text->SetDisplayRect(Rect(kCanvasSize)); 2635 render_text->SetDisplayRect(Rect(kCanvasSize));
msw 2015/02/27 03:48:06 I think you can remove this and rely on the calls
dschuyler 2015/02/27 21:45:20 Done.
2535 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); 2636 render_text->SetHorizontalAlignment(ALIGN_LEFT);
2536 render_text->SetColor(SK_ColorBLACK); 2637 render_text->SetColor(SK_ColorBLACK);
2537 2638
2538 for (auto string : kTestStrings) { 2639 for (auto string : kTestStrings) {
2539 surface->getCanvas()->clear(SK_ColorWHITE); 2640 surface->getCanvas()->clear(SK_ColorWHITE);
2540 render_text->SetText(WideToUTF16(string)); 2641 render_text->SetText(WideToUTF16(string));
2642 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2));
2643 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4));
2644 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6));
2645 render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8));
2541 render_text->SetStyle(BOLD, true); 2646 render_text->SetStyle(BOLD, true);
2647 render_text->SetDisplayRect(Rect(kTestSize, kTestSize,
2648 render_text->GetStringSize().width(),
msw 2015/02/27 03:48:06 nit: cache a Size string_size for use throughout.
dschuyler 2015/02/27 21:45:20 Done.
2649 render_text->GetStringSize().height()));
2650 // Allow the RenderText to paint outside of its display rect.
2651 render_text->set_clip_to_display_rect(false);
2652 ASSERT_LE(render_text->GetStringSize().width() + kTestSize * 2,
2653 kCanvasSize.width());
2654
2542 render_text->Draw(canvas.get()); 2655 render_text->Draw(canvas.get());
2543 int width = render_text->GetStringSize().width(); 2656 int width = render_text->GetStringSize().width();
2544 ASSERT_LT(width + kTestWidth, kCanvasSize.width()); 2657 ASSERT_LT(width + kTestSize, kCanvasSize.width());
2545 const uint32* buffer = static_cast<const uint32*>( 2658 const uint32* buffer =
2546 surface->peekPixels(NULL, NULL)); 2659 static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr));
2547 ASSERT_NE(nullptr, buffer); 2660 ASSERT_NE(nullptr, buffer);
2548 2661 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
2549 for (int y = 0; y < kCanvasSize.height(); ++y) { 2662 kCanvasSize.height());
2550 // Allow one column of anti-aliased pixels past the expected width. 2663 // Top side.
2551 SkColor color = buffer[width + y * kCanvasSize.width()]; 2664 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(),
2552 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string; 2665 kTestSize);
2553 for (int x = 1; x < kTestWidth; ++x) { 2666 // Bottom side.
2554 color = buffer[width + x + y * kCanvasSize.width()]; 2667 rect_buffer.EnsureSolidRect(
2555 EXPECT_EQ(SK_ColorWHITE, color) << string; 2668 SK_ColorWHITE, 0, kTestSize + render_text->GetStringSize().height(),
2556 } 2669 kCanvasSize.width(), kTestSize);
2557 } 2670 // Left side.
2671 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize, kTestSize,
2672 render_text->GetStringSize().height());
2673 // Right side.
2674 rect_buffer.EnsureSolidRect(
2675 SK_ColorWHITE, kTestSize + render_text->GetStringSize().width(),
2676 kTestSize, kTestSize, render_text->GetStringSize().height());
2677 #if 0
2678 // Debug Print.
2679 rect_buffer.AsciiRender(kTestSize - 2, kTestSize - 2,
2680 render_text->GetStringSize().width() + 4,
2681 render_text->GetStringSize().height() + 4);
2682 #endif
2558 } 2683 }
2559 } 2684 }
2560 2685
2686 // Ensure that the text will clip to the display rect. Draws to a canvas and
2687 // checks whether any pixel beyond the bounding rectangle is colored.
2688 TEST_F(RenderTextTest, TextDoesClip) {
2689 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"};
2690 const Size kCanvasSize(300, 50);
2691 const int kTestSize = 10;
2692
2693 skia::RefPtr<SkSurface> surface = skia::AdoptRef(
2694 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()));
2695 scoped_ptr<Canvas> canvas(
2696 Canvas::CreateCanvasWithoutScaling(surface->getCanvas(), 1.0f));
2697 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
2698 render_text->SetDisplayRect(Rect(kCanvasSize));
msw 2015/02/27 03:48:06 ditto
dschuyler 2015/02/27 21:45:20 Done.
2699 render_text->SetHorizontalAlignment(ALIGN_LEFT);
2700 render_text->SetColor(SK_ColorBLACK);
2701
2702 for (auto string : kTestStrings) {
2703 surface->getCanvas()->clear(SK_ColorWHITE);
2704 render_text->SetText(WideToUTF16(string));
2705 int fake_width = render_text->GetStringSize().width() / 2;
2706 int fake_height = render_text->GetStringSize().height() / 2;
2707 render_text->SetDisplayRect(
2708 Rect(kTestSize, kTestSize, fake_width, fake_height));
2709 render_text->set_clip_to_display_rect(true);
2710 render_text->Draw(canvas.get());
2711 int width = render_text->GetStringSize().width();
2712 ASSERT_LT(width + kTestSize, kCanvasSize.width());
2713 const uint32* buffer =
2714 static_cast<const uint32*>(surface->peekPixels(nullptr, nullptr));
2715 ASSERT_NE(nullptr, buffer);
2716 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(),
2717 kCanvasSize.height());
2718 // Top side.
2719 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(),
2720 kTestSize);
2721 // Bottom side.
2722 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize + fake_height,
2723 kCanvasSize.width(), kTestSize);
2724 // Left side.
2725 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize, kTestSize,
2726 fake_height);
2727 // Right side.
2728 rect_buffer.EnsureSolidRect(SK_ColorWHITE, kTestSize + fake_width,
2729 kTestSize, kTestSize, fake_height);
2730 }
2731 }
2732
2561 } // namespace gfx 2733 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698