| 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 3741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3752 L"TEST some stuff", | 3752 L"TEST some stuff", |
| 3753 L"WWWWWWWWWW", | 3753 L"WWWWWWWWWW", |
| 3754 L"gAXAXAXAXAXAXA", | 3754 L"gAXAXAXAXAXAXA", |
| 3755 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. | 3755 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. |
| 3756 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", | 3756 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", |
| 3757 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" | 3757 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" |
| 3758 L"\x0628\x0627"}; | 3758 L"\x0628\x0627"}; |
| 3759 const Size kCanvasSize(300, 50); | 3759 const Size kCanvasSize(300, 50); |
| 3760 const int kTestSize = 10; | 3760 const int kTestSize = 10; |
| 3761 | 3761 |
| 3762 sk_sp<SkSurface> surface = | 3762 sk_sp<cc::PaintSurface> surface = cc::PaintSurface::MakeRasterN32Premul( |
| 3763 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); | 3763 kCanvasSize.width(), kCanvasSize.height()); |
| 3764 Canvas canvas(surface->getCanvas(), 1.0f); | 3764 Canvas canvas(surface->getCanvas(), 1.0f); |
| 3765 RenderText* render_text = GetRenderText(); | 3765 RenderText* render_text = GetRenderText(); |
| 3766 render_text->SetHorizontalAlignment(ALIGN_LEFT); | 3766 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
| 3767 render_text->SetColor(SK_ColorBLACK); | 3767 render_text->SetColor(SK_ColorBLACK); |
| 3768 | 3768 |
| 3769 for (auto* string : kTestStrings) { | 3769 for (auto* string : kTestStrings) { |
| 3770 surface->getCanvas()->clear(SK_ColorWHITE); | 3770 surface->getCanvas()->clear(SK_ColorWHITE); |
| 3771 render_text->SetText(WideToUTF16(string)); | 3771 render_text->SetText(WideToUTF16(string)); |
| 3772 const Size string_size = render_text->GetStringSize(); | 3772 const Size string_size = render_text->GetStringSize(); |
| 3773 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); | 3773 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); |
| 3774 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4)); | 3774 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4)); |
| 3775 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6)); | 3775 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6)); |
| 3776 render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8)); | 3776 render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8)); |
| 3777 render_text->SetWeight(Font::Weight::BOLD); | 3777 render_text->SetWeight(Font::Weight::BOLD); |
| 3778 render_text->SetDisplayRect( | 3778 render_text->SetDisplayRect( |
| 3779 Rect(kTestSize, kTestSize, string_size.width(), string_size.height())); | 3779 Rect(kTestSize, kTestSize, string_size.width(), string_size.height())); |
| 3780 // Allow the RenderText to paint outside of its display rect. | 3780 // Allow the RenderText to paint outside of its display rect. |
| 3781 render_text->set_clip_to_display_rect(false); | 3781 render_text->set_clip_to_display_rect(false); |
| 3782 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width()); | 3782 ASSERT_LE(string_size.width() + kTestSize * 2, kCanvasSize.width()); |
| 3783 | 3783 |
| 3784 render_text->Draw(&canvas); | 3784 render_text->Draw(&canvas); |
| 3785 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); | 3785 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); |
| 3786 SkPixmap pixmap; | 3786 SkPixmap pixmap; |
| 3787 surface->peekPixels(&pixmap); | 3787 surface->getCanvas()->peekPixels(&pixmap); |
| 3788 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr()); | 3788 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr()); |
| 3789 ASSERT_NE(nullptr, buffer); | 3789 ASSERT_NE(nullptr, buffer); |
| 3790 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), | 3790 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), |
| 3791 kCanvasSize.height()); | 3791 kCanvasSize.height()); |
| 3792 { | 3792 { |
| 3793 #if !defined(OS_CHROMEOS) | 3793 #if !defined(OS_CHROMEOS) |
| 3794 int top_test_height = kTestSize; | 3794 int top_test_height = kTestSize; |
| 3795 #if defined(OS_WIN) | 3795 #if defined(OS_WIN) |
| 3796 // Windows 8+ draws 1 pixel above the display rect. | 3796 // Windows 8+ draws 1 pixel above the display rect. |
| 3797 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | 3797 if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3845 } | 3845 } |
| 3846 #endif // !defined(OS_WIN) | 3846 #endif // !defined(OS_WIN) |
| 3847 | 3847 |
| 3848 // Ensure that the text will clip to the display rect. Draws to a canvas and | 3848 // Ensure that the text will clip to the display rect. Draws to a canvas and |
| 3849 // checks whether any pixel beyond the bounding rectangle is colored. | 3849 // checks whether any pixel beyond the bounding rectangle is colored. |
| 3850 TEST_P(RenderTextTest, TextDoesClip) { | 3850 TEST_P(RenderTextTest, TextDoesClip) { |
| 3851 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; | 3851 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; |
| 3852 const Size kCanvasSize(300, 50); | 3852 const Size kCanvasSize(300, 50); |
| 3853 const int kTestSize = 10; | 3853 const int kTestSize = 10; |
| 3854 | 3854 |
| 3855 sk_sp<SkSurface> surface = | 3855 sk_sp<cc::PaintSurface> surface = cc::PaintSurface::MakeRasterN32Premul( |
| 3856 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); | 3856 kCanvasSize.width(), kCanvasSize.height()); |
| 3857 Canvas canvas(surface->getCanvas(), 1.0f); | 3857 Canvas canvas(surface->getCanvas(), 1.0f); |
| 3858 RenderText* render_text = GetRenderText(); | 3858 RenderText* render_text = GetRenderText(); |
| 3859 render_text->SetHorizontalAlignment(ALIGN_LEFT); | 3859 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
| 3860 render_text->SetColor(SK_ColorBLACK); | 3860 render_text->SetColor(SK_ColorBLACK); |
| 3861 | 3861 |
| 3862 for (auto* string : kTestStrings) { | 3862 for (auto* string : kTestStrings) { |
| 3863 surface->getCanvas()->clear(SK_ColorWHITE); | 3863 surface->getCanvas()->clear(SK_ColorWHITE); |
| 3864 render_text->SetText(WideToUTF16(string)); | 3864 render_text->SetText(WideToUTF16(string)); |
| 3865 const Size string_size = render_text->GetStringSize(); | 3865 const Size string_size = render_text->GetStringSize(); |
| 3866 int fake_width = string_size.width() / 2; | 3866 int fake_width = string_size.width() / 2; |
| 3867 int fake_height = string_size.height() / 2; | 3867 int fake_height = string_size.height() / 2; |
| 3868 render_text->SetDisplayRect( | 3868 render_text->SetDisplayRect( |
| 3869 Rect(kTestSize, kTestSize, fake_width, fake_height)); | 3869 Rect(kTestSize, kTestSize, fake_width, fake_height)); |
| 3870 render_text->set_clip_to_display_rect(true); | 3870 render_text->set_clip_to_display_rect(true); |
| 3871 render_text->Draw(&canvas); | 3871 render_text->Draw(&canvas); |
| 3872 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); | 3872 ASSERT_LT(string_size.width() + kTestSize, kCanvasSize.width()); |
| 3873 SkPixmap pixmap; | 3873 SkPixmap pixmap; |
| 3874 surface->peekPixels(&pixmap); | 3874 surface->getCanvas()->peekPixels(&pixmap); |
| 3875 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr()); | 3875 const uint32_t* buffer = static_cast<const uint32_t*>(pixmap.addr()); |
| 3876 ASSERT_NE(nullptr, buffer); | 3876 ASSERT_NE(nullptr, buffer); |
| 3877 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), | 3877 TestRectangleBuffer rect_buffer(string, buffer, kCanvasSize.width(), |
| 3878 kCanvasSize.height()); | 3878 kCanvasSize.height()); |
| 3879 { | 3879 { |
| 3880 SCOPED_TRACE("TextDoesClip Top Side"); | 3880 SCOPED_TRACE("TextDoesClip Top Side"); |
| 3881 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(), | 3881 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, 0, kCanvasSize.width(), |
| 3882 kTestSize); | 3882 kTestSize); |
| 3883 } | 3883 } |
| 3884 | 3884 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4367 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 4367 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
| 4368 PrintRenderTextBackend()); | 4368 PrintRenderTextBackend()); |
| 4369 #endif | 4369 #endif |
| 4370 | 4370 |
| 4371 INSTANTIATE_TEST_CASE_P(, | 4371 INSTANTIATE_TEST_CASE_P(, |
| 4372 RenderTextHarfBuzzTest, | 4372 RenderTextHarfBuzzTest, |
| 4373 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 4373 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
| 4374 PrintRenderTextBackend()); | 4374 PrintRenderTextBackend()); |
| 4375 | 4375 |
| 4376 } // namespace gfx | 4376 } // namespace gfx |
| OLD | NEW |