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