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 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
15 #include "base/i18n/break_iterator.h" | 15 #include "base/i18n/break_iterator.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/skia/include/core/SkRefCnt.h" |
23 #include "third_party/skia/include/core/SkSurface.h" | 24 #include "third_party/skia/include/core/SkSurface.h" |
24 #include "third_party/skia/include/core/SkTypeface.h" | 25 #include "third_party/skia/include/core/SkTypeface.h" |
25 #include "ui/gfx/break_list.h" | 26 #include "ui/gfx/break_list.h" |
26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/color_utils.h" | 28 #include "ui/gfx/color_utils.h" |
28 #include "ui/gfx/font.h" | 29 #include "ui/gfx/font.h" |
29 #include "ui/gfx/geometry/point.h" | 30 #include "ui/gfx/geometry/point.h" |
30 #include "ui/gfx/geometry/point_f.h" | 31 #include "ui/gfx/geometry/point_f.h" |
31 #include "ui/gfx/range/range.h" | 32 #include "ui/gfx/range/range.h" |
32 #include "ui/gfx/range/range_f.h" | 33 #include "ui/gfx/range/range_f.h" |
(...skipping 3045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3078 L"gAXAXAXAXAXAXA", | 3079 L"gAXAXAXAXAXAXA", |
3079 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. | 3080 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. |
3080 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", | 3081 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", |
3081 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" | 3082 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" |
3082 L"\x0628\x0627"}; | 3083 L"\x0628\x0627"}; |
3083 const Size kCanvasSize(300, 50); | 3084 const Size kCanvasSize(300, 50); |
3084 const int kTestSize = 10; | 3085 const int kTestSize = 10; |
3085 | 3086 |
3086 sk_sp<SkSurface> surface = | 3087 sk_sp<SkSurface> surface = |
3087 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); | 3088 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); |
3088 Canvas canvas(skia::SharePtr(surface->getCanvas()), 1.0f); | 3089 Canvas canvas(sk_ref_sp(surface->getCanvas()), 1.0f); |
3089 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 3090 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
3090 render_text->SetHorizontalAlignment(ALIGN_LEFT); | 3091 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
3091 render_text->SetColor(SK_ColorBLACK); | 3092 render_text->SetColor(SK_ColorBLACK); |
3092 | 3093 |
3093 for (auto string : kTestStrings) { | 3094 for (auto string : kTestStrings) { |
3094 surface->getCanvas()->clear(SK_ColorWHITE); | 3095 surface->getCanvas()->clear(SK_ColorWHITE); |
3095 render_text->SetText(WideToUTF16(string)); | 3096 render_text->SetText(WideToUTF16(string)); |
3096 const Size string_size = render_text->GetStringSize(); | 3097 const Size string_size = render_text->GetStringSize(); |
3097 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); | 3098 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); |
3098 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4)); | 3099 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4)); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3170 | 3171 |
3171 // Ensure that the text will clip to the display rect. Draws to a canvas and | 3172 // Ensure that the text will clip to the display rect. Draws to a canvas and |
3172 // checks whether any pixel beyond the bounding rectangle is colored. | 3173 // checks whether any pixel beyond the bounding rectangle is colored. |
3173 TEST_F(RenderTextTest, TextDoesClip) { | 3174 TEST_F(RenderTextTest, TextDoesClip) { |
3174 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; | 3175 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; |
3175 const Size kCanvasSize(300, 50); | 3176 const Size kCanvasSize(300, 50); |
3176 const int kTestSize = 10; | 3177 const int kTestSize = 10; |
3177 | 3178 |
3178 sk_sp<SkSurface> surface = | 3179 sk_sp<SkSurface> surface = |
3179 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); | 3180 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); |
3180 Canvas canvas(skia::SharePtr(surface->getCanvas()), 1.0f); | 3181 Canvas canvas(sk_ref_sp(surface->getCanvas()), 1.0f); |
3181 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); | 3182 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); |
3182 render_text->SetHorizontalAlignment(ALIGN_LEFT); | 3183 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
3183 render_text->SetColor(SK_ColorBLACK); | 3184 render_text->SetColor(SK_ColorBLACK); |
3184 | 3185 |
3185 for (auto string : kTestStrings) { | 3186 for (auto string : kTestStrings) { |
3186 surface->getCanvas()->clear(SK_ColorWHITE); | 3187 surface->getCanvas()->clear(SK_ColorWHITE); |
3187 render_text->SetText(WideToUTF16(string)); | 3188 render_text->SetText(WideToUTF16(string)); |
3188 const Size string_size = render_text->GetStringSize(); | 3189 const Size string_size = render_text->GetStringSize(); |
3189 int fake_width = string_size.width() / 2; | 3190 int fake_width = string_size.width() / 2; |
3190 int fake_height = string_size.height() / 2; | 3191 int fake_height = string_size.height() / 2; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3328 EXPECT_FALSE(backend.paint().isLCDRenderText()); | 3329 EXPECT_FALSE(backend.paint().isLCDRenderText()); |
3329 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering = | 3330 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering = |
3330 FontRenderParams::SUBPIXEL_RENDERING_RGB; | 3331 FontRenderParams::SUBPIXEL_RENDERING_RGB; |
3331 backend.DrawVisualText(); | 3332 backend.DrawVisualText(); |
3332 #endif | 3333 #endif |
3333 EXPECT_FALSE(backend.paint().isLCDRenderText()); | 3334 EXPECT_FALSE(backend.paint().isLCDRenderText()); |
3334 } | 3335 } |
3335 } | 3336 } |
3336 | 3337 |
3337 } // namespace gfx | 3338 } // namespace gfx |
OLD | NEW |