| 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 "third_party/icu/source/common/unicode/rbbi.h" | 20 #include "third_party/icu/source/common/unicode/rbbi.h" |
| 21 #include "third_party/icu/source/common/unicode/utf16.h" | 21 #include "third_party/icu/source/common/unicode/utf16.h" |
| 22 #include "third_party/skia/include/core/SkDrawLooper.h" | 22 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 23 #include "third_party/skia/include/core/SkFontStyle.h" | 23 #include "third_party/skia/include/core/SkFontStyle.h" |
| 24 #include "third_party/skia/include/core/SkTypeface.h" | 24 #include "third_party/skia/include/core/SkTypeface.h" |
| 25 #include "third_party/skia/include/effects/SkGradientShader.h" | 25 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 26 #include "third_party/skia/include/effects/SkMorphologyImageFilter.h" | |
| 27 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/geometry/insets.h" | 27 #include "ui/gfx/geometry/insets.h" |
| 29 #include "ui/gfx/geometry/safe_integer_conversions.h" | 28 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 30 #include "ui/gfx/platform_font.h" | 29 #include "ui/gfx/platform_font.h" |
| 31 #include "ui/gfx/render_text_harfbuzz.h" | 30 #include "ui/gfx/render_text_harfbuzz.h" |
| 32 #include "ui/gfx/scoped_canvas.h" | 31 #include "ui/gfx/scoped_canvas.h" |
| 33 #include "ui/gfx/skia_util.h" | 32 #include "ui/gfx/skia_util.h" |
| 34 #include "ui/gfx/switches.h" | 33 #include "ui/gfx/switches.h" |
| 35 #include "ui/gfx/text_elider.h" | 34 #include "ui/gfx/text_elider.h" |
| 36 #include "ui/gfx/text_utils.h" | 35 #include "ui/gfx/text_utils.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 244 } |
| 246 | 245 |
| 247 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { | 246 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { |
| 248 paint_.setColor(foreground); | 247 paint_.setColor(foreground); |
| 249 } | 248 } |
| 250 | 249 |
| 251 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { | 250 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { |
| 252 paint_.setShader(std::move(shader)); | 251 paint_.setShader(std::move(shader)); |
| 253 } | 252 } |
| 254 | 253 |
| 255 void SkiaTextRenderer::SetHaloEffect() { | |
| 256 paint_.setImageFilter(SkDilateImageFilter::Make(1, 1, nullptr)); | |
| 257 } | |
| 258 | |
| 259 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, | 254 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, |
| 260 SkScalar position) { | 255 SkScalar position) { |
| 261 underline_thickness_ = thickness; | 256 underline_thickness_ = thickness; |
| 262 underline_position_ = position; | 257 underline_position_ = position; |
| 263 } | 258 } |
| 264 | 259 |
| 265 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, | 260 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, |
| 266 const uint16_t* glyphs, | 261 const uint16_t* glyphs, |
| 267 size_t glyph_count) { | 262 size_t glyph_count) { |
| 268 const size_t byte_length = glyph_count * sizeof(glyphs[0]); | 263 const size_t byte_length = glyph_count * sizeof(glyphs[0]); |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 } | 853 } |
| 859 | 854 |
| 860 if (!text().empty() && focused()) | 855 if (!text().empty() && focused()) |
| 861 DrawSelection(canvas); | 856 DrawSelection(canvas); |
| 862 | 857 |
| 863 if (cursor_enabled() && cursor_visible() && focused()) | 858 if (cursor_enabled() && cursor_visible() && focused()) |
| 864 DrawCursor(canvas, selection_model_); | 859 DrawCursor(canvas, selection_model_); |
| 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 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { | 870 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { |
| 878 // Paint cursor. Replace cursor is drawn as rectangle for now. | 871 // Paint cursor. Replace cursor is drawn as rectangle for now. |
| 879 // TODO(msw): Draw a better cursor with a better indication of association. | 872 // TODO(msw): Draw a better cursor with a better indication of association. |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1710 | 1703 |
| 1711 for (; range_max < length; ++range_max) | 1704 for (; range_max < length; ++range_max) |
| 1712 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) | 1705 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) |
| 1713 break; | 1706 break; |
| 1714 | 1707 |
| 1715 return range.is_reversed() ? Range(range_max, range_min) | 1708 return range.is_reversed() ? Range(range_max, range_min) |
| 1716 : Range(range_min, range_max); | 1709 : Range(range_min, range_max); |
| 1717 } | 1710 } |
| 1718 | 1711 |
| 1719 } // namespace gfx | 1712 } // namespace gfx |
| OLD | NEW |