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 2999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3010 L"TEST some stuff", | 3010 L"TEST some stuff", |
3011 L"WWWWWWWWWW", | 3011 L"WWWWWWWWWW", |
3012 L"gAXAXAXAXAXAXA", | 3012 L"gAXAXAXAXAXAXA", |
3013 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. | 3013 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. |
3014 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", | 3014 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", |
3015 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" | 3015 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" |
3016 L"\x0628\x0627"}; | 3016 L"\x0628\x0627"}; |
3017 const Size kCanvasSize(300, 50); | 3017 const Size kCanvasSize(300, 50); |
3018 const int kTestSize = 10; | 3018 const int kTestSize = 10; |
3019 | 3019 |
3020 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 3020 sk_sp<SkSurface> surface = |
3021 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); | 3021 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); |
3022 Canvas canvas(skia::SharePtr(surface->getCanvas()), 1.0f); | 3022 Canvas canvas(skia::SharePtr(surface->getCanvas()), 1.0f); |
3023 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 3023 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
3024 render_text->SetHorizontalAlignment(ALIGN_LEFT); | 3024 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
3025 render_text->SetColor(SK_ColorBLACK); | 3025 render_text->SetColor(SK_ColorBLACK); |
3026 | 3026 |
3027 for (auto string : kTestStrings) { | 3027 for (auto string : kTestStrings) { |
3028 surface->getCanvas()->clear(SK_ColorWHITE); | 3028 surface->getCanvas()->clear(SK_ColorWHITE); |
3029 render_text->SetText(WideToUTF16(string)); | 3029 render_text->SetText(WideToUTF16(string)); |
3030 const Size string_size = render_text->GetStringSize(); | 3030 const Size string_size = render_text->GetStringSize(); |
3031 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); | 3031 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3101 } | 3101 } |
3102 } | 3102 } |
3103 | 3103 |
3104 // Ensure that the text will clip to the display rect. Draws to a canvas and | 3104 // Ensure that the text will clip to the display rect. Draws to a canvas and |
3105 // checks whether any pixel beyond the bounding rectangle is colored. | 3105 // checks whether any pixel beyond the bounding rectangle is colored. |
3106 TEST_F(RenderTextTest, TextDoesClip) { | 3106 TEST_F(RenderTextTest, TextDoesClip) { |
3107 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; | 3107 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; |
3108 const Size kCanvasSize(300, 50); | 3108 const Size kCanvasSize(300, 50); |
3109 const int kTestSize = 10; | 3109 const int kTestSize = 10; |
3110 | 3110 |
3111 skia::RefPtr<SkSurface> surface = skia::AdoptRef( | 3111 sk_sp<SkSurface> surface = |
3112 SkSurface::NewRasterN32Premul(kCanvasSize.width(), kCanvasSize.height())); | 3112 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); |
3113 Canvas canvas(skia::SharePtr(surface->getCanvas()), 1.0f); | 3113 Canvas canvas(skia::SharePtr(surface->getCanvas()), 1.0f); |
3114 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 3114 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
3115 render_text->SetHorizontalAlignment(ALIGN_LEFT); | 3115 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
3116 render_text->SetColor(SK_ColorBLACK); | 3116 render_text->SetColor(SK_ColorBLACK); |
3117 | 3117 |
3118 for (auto string : kTestStrings) { | 3118 for (auto string : kTestStrings) { |
3119 surface->getCanvas()->clear(SK_ColorWHITE); | 3119 surface->getCanvas()->clear(SK_ColorWHITE); |
3120 render_text->SetText(WideToUTF16(string)); | 3120 render_text->SetText(WideToUTF16(string)); |
3121 const Size string_size = render_text->GetStringSize(); | 3121 const Size string_size = render_text->GetStringSize(); |
3122 int fake_width = string_size.width() / 2; | 3122 int fake_width = string_size.width() / 2; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3209 backend[i]->SetColor(SK_ColorRED); | 3209 backend[i]->SetColor(SK_ColorRED); |
3210 test_api.DrawVisualText(&renderer); | 3210 test_api.DrawVisualText(&renderer); |
3211 | 3211 |
3212 renderer.GetTextLogAndReset(&text_log); | 3212 renderer.GetTextLogAndReset(&text_log); |
3213 EXPECT_EQ(1u, text_log.size()); | 3213 EXPECT_EQ(1u, text_log.size()); |
3214 EXPECT_EQ(SK_ColorRED, text_log[0].color); | 3214 EXPECT_EQ(SK_ColorRED, text_log[0].color); |
3215 } | 3215 } |
3216 } | 3216 } |
3217 | 3217 |
3218 } // namespace gfx | 3218 } // namespace gfx |
OLD | NEW |