| 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 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <climits> | 10 #include <climits> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/i18n/break_iterator.h" | 13 #include "base/i18n/break_iterator.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | |
| 16 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 17 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 20 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 21 #include "cc/paint/paint_canvas.h" | 20 #include "cc/paint/paint_canvas.h" |
| 22 #include "cc/paint/paint_shader.h" | 21 #include "cc/paint/paint_shader.h" |
| 23 #include "third_party/icu/source/common/unicode/rbbi.h" | 22 #include "third_party/icu/source/common/unicode/rbbi.h" |
| 24 #include "third_party/icu/source/common/unicode/utf16.h" | 23 #include "third_party/icu/source/common/unicode/utf16.h" |
| 25 #include "third_party/skia/include/core/SkDrawLooper.h" | 24 #include "third_party/skia/include/core/SkDrawLooper.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 colors->push_back(c0); | 98 colors->push_back(c0); |
| 100 } | 99 } |
| 101 positions->push_back(p0); | 100 positions->push_back(p0); |
| 102 colors->push_back(c0); | 101 colors->push_back(c0); |
| 103 positions->push_back(p1); | 102 positions->push_back(p1); |
| 104 colors->push_back(c1); | 103 colors->push_back(c1); |
| 105 } | 104 } |
| 106 | 105 |
| 107 // Creates a SkShader to fade the text, with |left_part| specifying the left | 106 // Creates a SkShader to fade the text, with |left_part| specifying the left |
| 108 // fade effect, if any, and |right_part| specifying the right fade effect. | 107 // fade effect, if any, and |right_part| specifying the right fade effect. |
| 109 std::unique_ptr<cc::PaintShader> CreateFadeShader(const FontList& font_list, | 108 sk_sp<SkShader> CreateFadeShader(const FontList& font_list, |
| 110 const Rect& text_rect, | 109 const Rect& text_rect, |
| 111 const Rect& left_part, | 110 const Rect& left_part, |
| 112 const Rect& right_part, | 111 const Rect& right_part, |
| 113 SkColor color) { | 112 SkColor color) { |
| 114 // The shader should only specify transparency of the fade itself, not the | 113 // The shader should only specify transparency of the fade itself, not the |
| 115 // original transparency, which will be applied by the actual renderer. | 114 // original transparency, which will be applied by the actual renderer. |
| 116 DCHECK_EQ(SkColorGetA(color), static_cast<uint8_t>(0xff)); | 115 DCHECK_EQ(SkColorGetA(color), static_cast<uint8_t>(0xff)); |
| 117 | 116 |
| 118 // In general, fade down to 0 alpha. But when the available width is less | 117 // In general, fade down to 0 alpha. But when the available width is less |
| 119 // than four characters, linearly ramp up the fade target alpha to as high as | 118 // than four characters, linearly ramp up the fade target alpha to as high as |
| 120 // 20% at zero width. This allows the user to see the last faded characters a | 119 // 20% at zero width. This allows the user to see the last faded characters a |
| 121 // little better when there are only a few characters shown. | 120 // little better when there are only a few characters shown. |
| 122 const float width_fraction = | 121 const float width_fraction = |
| 123 text_rect.width() / static_cast<float>(font_list.GetExpectedTextWidth(4)); | 122 text_rect.width() / static_cast<float>(font_list.GetExpectedTextWidth(4)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 DCHECK(!positions.empty()); | 137 DCHECK(!positions.empty()); |
| 139 | 138 |
| 140 // Terminate |positions| with 1.0, as required by Skia. | 139 // Terminate |positions| with 1.0, as required by Skia. |
| 141 if (positions.back() != 1.0) { | 140 if (positions.back() != 1.0) { |
| 142 positions.push_back(1.0); | 141 positions.push_back(1.0); |
| 143 colors.push_back(colors.back()); | 142 colors.push_back(colors.back()); |
| 144 } | 143 } |
| 145 | 144 |
| 146 const SkPoint points[2] = { PointToSkPoint(text_rect.origin()), | 145 const SkPoint points[2] = { PointToSkPoint(text_rect.origin()), |
| 147 PointToSkPoint(text_rect.top_right()) }; | 146 PointToSkPoint(text_rect.top_right()) }; |
| 148 return cc::PaintShader::MakeLinearGradient(&points[0], &colors[0], | 147 return |
| 149 &positions[0], colors.size(), | 148 SkGradientShader::MakeLinear(&points[0], &colors[0], &positions[0], |
| 150 SkShader::kClamp_TileMode); | 149 colors.size(), SkShader::kClamp_TileMode); |
| 151 } | 150 } |
| 152 | 151 |
| 153 // Converts a FontRenderParams::Hinting value to the corresponding | 152 // Converts a FontRenderParams::Hinting value to the corresponding |
| 154 // cc::PaintFlags::Hinting value. | 153 // cc::PaintFlags::Hinting value. |
| 155 cc::PaintFlags::Hinting FontRenderParamsHintingToPaintFlagsHinting( | 154 cc::PaintFlags::Hinting FontRenderParamsHintingToPaintFlagsHinting( |
| 156 FontRenderParams::Hinting params_hinting) { | 155 FontRenderParams::Hinting params_hinting) { |
| 157 switch (params_hinting) { | 156 switch (params_hinting) { |
| 158 case FontRenderParams::HINTING_NONE: | 157 case FontRenderParams::HINTING_NONE: |
| 159 return cc::PaintFlags::kNo_Hinting; | 158 return cc::PaintFlags::kNo_Hinting; |
| 160 case FontRenderParams::HINTING_SLIGHT: | 159 case FontRenderParams::HINTING_SLIGHT: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 224 } |
| 226 | 225 |
| 227 void SkiaTextRenderer::SetTextSize(SkScalar size) { | 226 void SkiaTextRenderer::SetTextSize(SkScalar size) { |
| 228 flags_.setTextSize(size); | 227 flags_.setTextSize(size); |
| 229 } | 228 } |
| 230 | 229 |
| 231 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { | 230 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { |
| 232 flags_.setColor(foreground); | 231 flags_.setColor(foreground); |
| 233 } | 232 } |
| 234 | 233 |
| 235 void SkiaTextRenderer::SetShader(std::unique_ptr<cc::PaintShader> shader) { | 234 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { |
| 236 flags_.setShader(std::move(shader)); | 235 flags_.setShader(cc::WrapSkShader(std::move(shader))); |
| 237 } | 236 } |
| 238 | 237 |
| 239 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, | 238 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, |
| 240 SkScalar position) { | 239 SkScalar position) { |
| 241 underline_thickness_ = thickness; | 240 underline_thickness_ = thickness; |
| 242 underline_position_ = position; | 241 underline_position_ = position; |
| 243 } | 242 } |
| 244 | 243 |
| 245 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, | 244 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, |
| 246 const uint16_t* glyphs, | 245 const uint16_t* glyphs, |
| (...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1697 | 1696 |
| 1698 for (; range_max < length; ++range_max) | 1697 for (; range_max < length; ++range_max) |
| 1699 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) | 1698 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) |
| 1700 break; | 1699 break; |
| 1701 | 1700 |
| 1702 return range.is_reversed() ? Range(range_max, range_min) | 1701 return range.is_reversed() ? Range(range_max, range_min) |
| 1703 : Range(range_min, range_max); | 1702 : Range(range_min, range_max); |
| 1704 } | 1703 } |
| 1705 | 1704 |
| 1706 } // namespace gfx | 1705 } // namespace gfx |
| OLD | NEW |