| 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/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "cc/paint/paint_canvas.h" | 20 #include "cc/paint/paint_canvas.h" |
| 21 #include "cc/paint/paint_shader.h" | 21 #include "cc/paint/paint_shader.h" |
| 22 #include "third_party/icu/source/common/unicode/rbbi.h" | 22 #include "third_party/icu/source/common/unicode/rbbi.h" |
| 23 #include "third_party/icu/source/common/unicode/utf16.h" | 23 #include "third_party/icu/source/common/unicode/utf16.h" |
| 24 #include "third_party/skia/include/core/SkDrawLooper.h" | 24 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 25 #include "third_party/skia/include/core/SkFontStyle.h" | 25 #include "third_party/skia/include/core/SkFontStyle.h" |
| 26 #include "third_party/skia/include/core/SkTypeface.h" | 26 #include "third_party/skia/include/core/SkTypeface.h" |
| 27 #include "third_party/skia/include/effects/SkGradientShader.h" | 27 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 28 #include "third_party/skia/include/effects/SkMorphologyImageFilter.h" | |
| 29 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
| 30 #include "ui/gfx/geometry/insets.h" | 29 #include "ui/gfx/geometry/insets.h" |
| 31 #include "ui/gfx/geometry/safe_integer_conversions.h" | 30 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 32 #include "ui/gfx/platform_font.h" | 31 #include "ui/gfx/platform_font.h" |
| 33 #include "ui/gfx/render_text_harfbuzz.h" | 32 #include "ui/gfx/render_text_harfbuzz.h" |
| 34 #include "ui/gfx/scoped_canvas.h" | 33 #include "ui/gfx/scoped_canvas.h" |
| 35 #include "ui/gfx/skia_paint_util.h" | 34 #include "ui/gfx/skia_paint_util.h" |
| 36 #include "ui/gfx/skia_util.h" | 35 #include "ui/gfx/skia_util.h" |
| 37 #include "ui/gfx/switches.h" | 36 #include "ui/gfx/switches.h" |
| 38 #include "ui/gfx/text_elider.h" | 37 #include "ui/gfx/text_elider.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 251 } |
| 253 | 252 |
| 254 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { | 253 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { |
| 255 flags_.setColor(foreground); | 254 flags_.setColor(foreground); |
| 256 } | 255 } |
| 257 | 256 |
| 258 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { | 257 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { |
| 259 flags_.setShader(cc::WrapSkShader(std::move(shader))); | 258 flags_.setShader(cc::WrapSkShader(std::move(shader))); |
| 260 } | 259 } |
| 261 | 260 |
| 262 void SkiaTextRenderer::SetHaloEffect() { | |
| 263 flags_.setImageFilter(SkDilateImageFilter::Make(1, 1, nullptr)); | |
| 264 } | |
| 265 | |
| 266 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, | 261 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, |
| 267 SkScalar position) { | 262 SkScalar position) { |
| 268 underline_thickness_ = thickness; | 263 underline_thickness_ = thickness; |
| 269 underline_position_ = position; | 264 underline_position_ = position; |
| 270 } | 265 } |
| 271 | 266 |
| 272 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, | 267 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, |
| 273 const uint16_t* glyphs, | 268 const uint16_t* glyphs, |
| 274 size_t glyph_count) { | 269 size_t glyph_count) { |
| 275 const size_t byte_length = glyph_count * sizeof(glyphs[0]); | 270 const size_t byte_length = glyph_count * sizeof(glyphs[0]); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 | 853 |
| 859 canvas->Save(); | 854 canvas->Save(); |
| 860 canvas->ClipRect(clip_rect); | 855 canvas->ClipRect(clip_rect); |
| 861 } | 856 } |
| 862 | 857 |
| 863 if (!text().empty() && focused()) | 858 if (!text().empty() && focused()) |
| 864 DrawSelection(canvas); | 859 DrawSelection(canvas); |
| 865 | 860 |
| 866 if (!text().empty()) { | 861 if (!text().empty()) { |
| 867 internal::SkiaTextRenderer renderer(canvas); | 862 internal::SkiaTextRenderer renderer(canvas); |
| 868 if (halo_effect()) | |
| 869 renderer.SetHaloEffect(); | |
| 870 DrawVisualText(&renderer); | 863 DrawVisualText(&renderer); |
| 871 } | 864 } |
| 872 | 865 |
| 873 if (clip_to_display_rect()) | 866 if (clip_to_display_rect()) |
| 874 canvas->Restore(); | 867 canvas->Restore(); |
| 875 } | 868 } |
| 876 | 869 |
| 877 bool RenderText::IsValidLogicalIndex(size_t index) const { | 870 bool RenderText::IsValidLogicalIndex(size_t index) const { |
| 878 // Check that the index is at a valid code point (not mid-surrgate-pair) and | 871 // Check that the index is at a valid code point (not mid-surrgate-pair) and |
| 879 // that it's not truncated from the display text (its glyph may be shown). | 872 // that it's not truncated from the display text (its glyph may be shown). |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 | 1695 |
| 1703 for (; range_max < length; ++range_max) | 1696 for (; range_max < length; ++range_max) |
| 1704 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) | 1697 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) |
| 1705 break; | 1698 break; |
| 1706 | 1699 |
| 1707 return range.is_reversed() ? Range(range_max, range_min) | 1700 return range.is_reversed() ? Range(range_max, range_min) |
| 1708 : Range(range_min, range_max); | 1701 : Range(range_min, range_max); |
| 1709 } | 1702 } |
| 1710 | 1703 |
| 1711 } // namespace gfx | 1704 } // namespace gfx |
| OLD | NEW |