Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: ui/gfx/render_text.cc

Issue 1634103003: Fix gfx::Canvas::DrawStringRectWithHalo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: check halo pixels Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/render_text.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/SkTypeface.h" 23 #include "third_party/skia/include/core/SkTypeface.h"
24 #include "third_party/skia/include/effects/SkGradientShader.h" 24 #include "third_party/skia/include/effects/SkGradientShader.h"
25 #include "third_party/skia/include/effects/SkMorphologyImageFilter.h"
25 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/geometry/insets.h" 27 #include "ui/gfx/geometry/insets.h"
27 #include "ui/gfx/geometry/safe_integer_conversions.h" 28 #include "ui/gfx/geometry/safe_integer_conversions.h"
28 #include "ui/gfx/platform_font.h" 29 #include "ui/gfx/platform_font.h"
29 #include "ui/gfx/render_text_harfbuzz.h" 30 #include "ui/gfx/render_text_harfbuzz.h"
30 #include "ui/gfx/scoped_canvas.h" 31 #include "ui/gfx/scoped_canvas.h"
31 #include "ui/gfx/skia_util.h" 32 #include "ui/gfx/skia_util.h"
32 #include "ui/gfx/switches.h" 33 #include "ui/gfx/switches.h"
33 #include "ui/gfx/text_elider.h" 34 #include "ui/gfx/text_elider.h"
34 #include "ui/gfx/text_utils.h" 35 #include "ui/gfx/text_utils.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 267 }
267 268
268 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { 269 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) {
269 paint_.setColor(foreground); 270 paint_.setColor(foreground);
270 } 271 }
271 272
272 void SkiaTextRenderer::SetShader(SkShader* shader) { 273 void SkiaTextRenderer::SetShader(SkShader* shader) {
273 paint_.setShader(shader); 274 paint_.setShader(shader);
274 } 275 }
275 276
277 void SkiaTextRenderer::SetHaloEffect() {
278 paint_.setImageFilter(SkDilateImageFilter::Create(1, 1));
Stephen White 2016/02/08 16:24:51 I think there's a memory leak here. Objects in Sk
Stephen White 2016/02/08 16:27:10 (Or auto filter = skia::AdoptRef(SkDilateImageFil
279 }
280
276 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, 281 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness,
277 SkScalar position) { 282 SkScalar position) {
278 underline_thickness_ = thickness; 283 underline_thickness_ = thickness;
279 underline_position_ = position; 284 underline_position_ = position;
280 } 285 }
281 286
282 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, 287 void SkiaTextRenderer::DrawPosText(const SkPoint* pos,
283 const uint16_t* glyphs, 288 const uint16_t* glyphs,
284 size_t glyph_count) { 289 size_t glyph_count) {
285 const size_t byte_length = glyph_count * sizeof(glyphs[0]); 290 const size_t byte_length = glyph_count * sizeof(glyphs[0]);
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 } 826 }
822 827
823 if (!text().empty() && focused()) 828 if (!text().empty() && focused())
824 DrawSelection(canvas); 829 DrawSelection(canvas);
825 830
826 if (cursor_enabled() && cursor_visible() && focused()) 831 if (cursor_enabled() && cursor_visible() && focused())
827 DrawCursor(canvas, selection_model_); 832 DrawCursor(canvas, selection_model_);
828 833
829 if (!text().empty()) { 834 if (!text().empty()) {
830 internal::SkiaTextRenderer renderer(canvas); 835 internal::SkiaTextRenderer renderer(canvas);
836 if (halo_effect())
837 renderer.SetHaloEffect();
831 DrawVisualText(&renderer); 838 DrawVisualText(&renderer);
832 } 839 }
833 840
834 if (clip_to_display_rect()) 841 if (clip_to_display_rect())
835 canvas->Restore(); 842 canvas->Restore();
836 } 843 }
837 844
838 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { 845 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) {
839 // Paint cursor. Replace cursor is drawn as rectangle for now. 846 // Paint cursor. Replace cursor is drawn as rectangle for now.
840 // TODO(msw): Draw a better cursor with a better indication of association. 847 // TODO(msw): Draw a better cursor with a better indication of association.
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 1547
1541 SetDisplayOffset(display_offset_.x() + delta_x); 1548 SetDisplayOffset(display_offset_.x() + delta_x);
1542 } 1549 }
1543 1550
1544 void RenderText::DrawSelection(Canvas* canvas) { 1551 void RenderText::DrawSelection(Canvas* canvas) {
1545 for (const Rect& s : GetSubstringBounds(selection())) 1552 for (const Rect& s : GetSubstringBounds(selection()))
1546 canvas->FillRect(s, selection_background_focused_color_); 1553 canvas->FillRect(s, selection_background_focused_color_);
1547 } 1554 }
1548 1555
1549 } // namespace gfx 1556 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698