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

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

Issue 2969623004: RenderText: Allow strike-through line thickness to be customized. (Closed)
Patch Set: Created 3 years, 5 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
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 #ifndef UI_GFX_RENDER_TEXT_H_ 5 #ifndef UI_GFX_RENDER_TEXT_H_
6 #define UI_GFX_RENDER_TEXT_H_ 6 #define UI_GFX_RENDER_TEXT_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 explicit SkiaTextRenderer(Canvas* canvas); 56 explicit SkiaTextRenderer(Canvas* canvas);
57 virtual ~SkiaTextRenderer(); 57 virtual ~SkiaTextRenderer();
58 58
59 void SetDrawLooper(sk_sp<SkDrawLooper> draw_looper); 59 void SetDrawLooper(sk_sp<SkDrawLooper> draw_looper);
60 void SetFontRenderParams(const FontRenderParams& params, 60 void SetFontRenderParams(const FontRenderParams& params,
61 bool subpixel_rendering_suppressed); 61 bool subpixel_rendering_suppressed);
62 void SetTypeface(sk_sp<SkTypeface> typeface); 62 void SetTypeface(sk_sp<SkTypeface> typeface);
63 void SetTextSize(SkScalar size); 63 void SetTextSize(SkScalar size);
64 void SetForegroundColor(SkColor foreground); 64 void SetForegroundColor(SkColor foreground);
65 void SetShader(std::unique_ptr<cc::PaintShader> shader); 65 void SetShader(std::unique_ptr<cc::PaintShader> shader);
66 // Sets underline metrics to use if the text will be drawn with an underline. 66 // Sets the ratio of strike-through line thickness to text height.
67 // If not set, default values based on the size of the text will be used. The 67 void SetStrikeThicknessFactor(SkScalar factor);
68 // two metrics must be set together.
69 void SetUnderlineMetrics(SkScalar thickness, SkScalar position);
70 void DrawSelection(const std::vector<Rect>& selection, SkColor color); 68 void DrawSelection(const std::vector<Rect>& selection, SkColor color);
71 virtual void DrawPosText(const SkPoint* pos, 69 virtual void DrawPosText(const SkPoint* pos,
72 const uint16_t* glyphs, 70 const uint16_t* glyphs,
73 size_t glyph_count); 71 size_t glyph_count);
74 // Draw underline and strike-through text decorations. 72 // Draw underline and strike-through text decorations.
75 // Based on |SkCanvas::DrawTextDecorations()| and constants from: 73 // Based on |SkCanvas::DrawTextDecorations()| and constants from:
76 // third_party/skia/src/core/SkTextFormatParams.h 74 // third_party/skia/src/core/SkTextFormatParams.h
77 virtual void DrawDecorations(int x, 75 virtual void DrawDecorations(int x,
78 int y, 76 int y,
79 int width, 77 int width,
80 bool underline, 78 bool underline,
81 bool strike); 79 bool strike);
82 void DrawUnderline(int x, int y, int width); 80 void DrawUnderline(int x, int y, int width);
83 void DrawStrike(int x, int y, int width) const; 81 void DrawStrike(int x, int y, int width) const;
84 82
85 private: 83 private:
86 friend class test::RenderTextTestApi; 84 friend class test::RenderTextTestApi;
87 85
88 Canvas* canvas_; 86 Canvas* canvas_;
89 cc::PaintCanvas* canvas_skia_; 87 cc::PaintCanvas* canvas_skia_;
90 cc::PaintFlags flags_; 88 cc::PaintFlags flags_;
91 SkScalar underline_thickness_; 89 SkScalar underline_thickness_;
msw 2017/06/30 20:51:23 Please also remove these two underline_* customiza
cjgrant 2017/07/05 16:16:48 Done.
92 SkScalar underline_position_; 90 SkScalar underline_position_;
91 SkScalar strike_thickness_factor_;
93 92
94 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); 93 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer);
95 }; 94 };
96 95
97 // Internal helper class used to iterate colors, baselines, and styles. 96 // Internal helper class used to iterate colors, baselines, and styles.
98 class StyleIterator { 97 class StyleIterator {
99 public: 98 public:
100 StyleIterator(const BreakList<SkColor>& colors, 99 StyleIterator(const BreakList<SkColor>& colors,
101 const BreakList<BaselineStyle>& baselines, 100 const BreakList<BaselineStyle>& baselines,
102 const BreakList<Font::Weight>& weights, 101 const BreakList<Font::Weight>& weights,
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // at the point, returns a nearby word. |baseline_point| should correspond to 492 // at the point, returns a nearby word. |baseline_point| should correspond to
494 // the baseline point of the leftmost glyph of the |word| in the view's 493 // the baseline point of the leftmost glyph of the |word| in the view's
495 // coordinates. Returns false, if no word can be retrieved. 494 // coordinates. Returns false, if no word can be retrieved.
496 bool GetDecoratedWordAtPoint(const Point& point, 495 bool GetDecoratedWordAtPoint(const Point& point,
497 DecoratedText* decorated_word, 496 DecoratedText* decorated_word,
498 Point* baseline_point); 497 Point* baseline_point);
499 498
500 // Retrieves the text in the given |range|. 499 // Retrieves the text in the given |range|.
501 base::string16 GetTextFromRange(const Range& range) const; 500 base::string16 GetTextFromRange(const Range& range) const;
502 501
502 // Sets the ratio of strike-through line thickness to text height.
503 void SetStrikeThicknessFactor(SkScalar factor);
504
503 protected: 505 protected:
504 RenderText(); 506 RenderText();
505 507
506 // NOTE: The value of these accessors may be stale. Please make sure 508 // NOTE: The value of these accessors may be stale. Please make sure
507 // that these fields are up to date before accessing them. 509 // that these fields are up to date before accessing them.
508 const base::string16& layout_text() const { return layout_text_; } 510 const base::string16& layout_text() const { return layout_text_; }
509 const base::string16& display_text() const { return display_text_; } 511 const base::string16& display_text() const { return display_text_; }
510 bool text_elided() const { return text_elided_; } 512 bool text_elided() const { return text_elided_; }
511 513
512 const BreakList<SkColor>& colors() const { return colors_; } 514 const BreakList<SkColor>& colors() const { return colors_; }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // Text shadows to be drawn. 830 // Text shadows to be drawn.
829 ShadowValues shadows_; 831 ShadowValues shadows_;
830 832
831 // A list of valid display text line break positions. 833 // A list of valid display text line break positions.
832 BreakList<size_t> line_breaks_; 834 BreakList<size_t> line_breaks_;
833 835
834 // Lines computed by EnsureLayout. These should be invalidated upon 836 // Lines computed by EnsureLayout. These should be invalidated upon
835 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. 837 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls.
836 std::vector<internal::Line> lines_; 838 std::vector<internal::Line> lines_;
837 839
840 SkScalar strike_thickness_factor_;
msw 2017/06/30 20:51:23 nit: comment like "The ratio of strike-through lin
cjgrant 2017/07/05 16:16:48 Done. Agreed.
841
838 DISALLOW_COPY_AND_ASSIGN(RenderText); 842 DISALLOW_COPY_AND_ASSIGN(RenderText);
839 }; 843 };
840 844
841 } // namespace gfx 845 } // namespace gfx
842 846
843 #endif // UI_GFX_RENDER_TEXT_H_ 847 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698