| 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 <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 // verify where exactly the glyphs are drawn. | 329 // verify where exactly the glyphs are drawn. |
| 330 class TestSkiaTextRenderer : public internal::SkiaTextRenderer { | 330 class TestSkiaTextRenderer : public internal::SkiaTextRenderer { |
| 331 public: | 331 public: |
| 332 struct TextLog { | 332 struct TextLog { |
| 333 TextLog() : glyph_count(0u), color(SK_ColorTRANSPARENT) {} | 333 TextLog() : glyph_count(0u), color(SK_ColorTRANSPARENT) {} |
| 334 PointF origin; | 334 PointF origin; |
| 335 size_t glyph_count; | 335 size_t glyph_count; |
| 336 SkColor color; | 336 SkColor color; |
| 337 }; | 337 }; |
| 338 | 338 |
| 339 struct DecorationLog { | |
| 340 DecorationLog(int x, int y, int width, bool underline, bool strike) | |
| 341 : x(x), y(y), width(width), underline(underline), strike(strike) {} | |
| 342 int x; | |
| 343 int y; | |
| 344 int width; | |
| 345 bool underline; | |
| 346 bool strike; | |
| 347 }; | |
| 348 | |
| 349 explicit TestSkiaTextRenderer(Canvas* canvas) | 339 explicit TestSkiaTextRenderer(Canvas* canvas) |
| 350 : internal::SkiaTextRenderer(canvas) {} | 340 : internal::SkiaTextRenderer(canvas) {} |
| 351 ~TestSkiaTextRenderer() override {} | 341 ~TestSkiaTextRenderer() override {} |
| 352 | 342 |
| 353 void GetTextLogAndReset(std::vector<TextLog>* text_log) { | 343 void GetTextLogAndReset(std::vector<TextLog>* text_log) { |
| 354 text_log_.swap(*text_log); | 344 text_log_.swap(*text_log); |
| 355 text_log_.clear(); | 345 text_log_.clear(); |
| 356 } | 346 } |
| 357 | 347 |
| 358 void GetDecorationLogAndReset(std::vector<DecorationLog>* decoration_log) { | |
| 359 decoration_log_.swap(*decoration_log); | |
| 360 decoration_log_.clear(); | |
| 361 } | |
| 362 | |
| 363 private: | 348 private: |
| 364 // internal::SkiaTextRenderer: | 349 // internal::SkiaTextRenderer: |
| 365 void DrawPosText(const SkPoint* pos, | 350 void DrawPosText(const SkPoint* pos, |
| 366 const uint16_t* glyphs, | 351 const uint16_t* glyphs, |
| 367 size_t glyph_count) override { | 352 size_t glyph_count) override { |
| 368 TextLog log_entry; | 353 TextLog log_entry; |
| 369 log_entry.glyph_count = glyph_count; | 354 log_entry.glyph_count = glyph_count; |
| 370 if (glyph_count > 0) { | 355 if (glyph_count > 0) { |
| 371 log_entry.origin = | 356 log_entry.origin = |
| 372 PointF(SkScalarToFloat(pos[0].x()), SkScalarToFloat(pos[0].y())); | 357 PointF(SkScalarToFloat(pos[0].x()), SkScalarToFloat(pos[0].y())); |
| 373 for (size_t i = 1U; i < glyph_count; ++i) { | 358 for (size_t i = 1U; i < glyph_count; ++i) { |
| 374 log_entry.origin.SetToMin( | 359 log_entry.origin.SetToMin( |
| 375 PointF(SkScalarToFloat(pos[i].x()), SkScalarToFloat(pos[i].y()))); | 360 PointF(SkScalarToFloat(pos[i].x()), SkScalarToFloat(pos[i].y()))); |
| 376 } | 361 } |
| 377 } | 362 } |
| 378 log_entry.color = | 363 log_entry.color = |
| 379 test::RenderTextTestApi::GetRendererPaint(this).getColor(); | 364 test::RenderTextTestApi::GetRendererPaint(this).getColor(); |
| 380 text_log_.push_back(log_entry); | 365 text_log_.push_back(log_entry); |
| 381 internal::SkiaTextRenderer::DrawPosText(pos, glyphs, glyph_count); | 366 internal::SkiaTextRenderer::DrawPosText(pos, glyphs, glyph_count); |
| 382 } | 367 } |
| 383 | 368 |
| 384 void DrawDecorations(int x, | |
| 385 int y, | |
| 386 int width, | |
| 387 bool underline, | |
| 388 bool strike) override { | |
| 389 decoration_log_.push_back(DecorationLog(x, y, width, underline, strike)); | |
| 390 internal::SkiaTextRenderer::DrawDecorations(x, y, width, underline, strike); | |
| 391 } | |
| 392 | |
| 393 std::vector<TextLog> text_log_; | 369 std::vector<TextLog> text_log_; |
| 394 std::vector<DecorationLog> decoration_log_; | |
| 395 | 370 |
| 396 DISALLOW_COPY_AND_ASSIGN(TestSkiaTextRenderer); | 371 DISALLOW_COPY_AND_ASSIGN(TestSkiaTextRenderer); |
| 397 }; | 372 }; |
| 398 | 373 |
| 399 // Given a buffer to test against, this can be used to test various areas of the | 374 // Given a buffer to test against, this can be used to test various areas of the |
| 400 // rectangular buffer against a specific color value. | 375 // rectangular buffer against a specific color value. |
| 401 class TestRectangleBuffer { | 376 class TestRectangleBuffer { |
| 402 public: | 377 public: |
| 403 TestRectangleBuffer(const wchar_t* string, | 378 TestRectangleBuffer(const wchar_t* string, |
| 404 const SkColor* buffer, | 379 const SkColor* buffer, |
| (...skipping 4260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4665 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 4640 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
| 4666 PrintRenderTextBackend()); | 4641 PrintRenderTextBackend()); |
| 4667 #endif | 4642 #endif |
| 4668 | 4643 |
| 4669 INSTANTIATE_TEST_CASE_P(, | 4644 INSTANTIATE_TEST_CASE_P(, |
| 4670 RenderTextHarfBuzzTest, | 4645 RenderTextHarfBuzzTest, |
| 4671 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 4646 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
| 4672 PrintRenderTextBackend()); | 4647 PrintRenderTextBackend()); |
| 4673 | 4648 |
| 4674 } // namespace gfx | 4649 } // namespace gfx |
| OLD | NEW |