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

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

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes for review issues. Created 4 years, 9 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 class GFX_EXPORT SkiaTextRenderer { 55 class GFX_EXPORT SkiaTextRenderer {
56 public: 56 public:
57 explicit SkiaTextRenderer(Canvas* canvas); 57 explicit SkiaTextRenderer(Canvas* canvas);
58 virtual ~SkiaTextRenderer(); 58 virtual ~SkiaTextRenderer();
59 59
60 void SetDrawLooper(SkDrawLooper* draw_looper); 60 void SetDrawLooper(SkDrawLooper* draw_looper);
61 void SetFontRenderParams(const FontRenderParams& params, 61 void SetFontRenderParams(const FontRenderParams& params,
62 bool subpixel_rendering_suppressed); 62 bool subpixel_rendering_suppressed);
63 void SetTypeface(SkTypeface* typeface); 63 void SetTypeface(SkTypeface* typeface);
64 void SetTextSize(SkScalar size); 64 void SetTextSize(SkScalar size);
65 void SetFontWithStyle(const Font& font, int font_style); 65 void SetFont(const Font& font, bool italic, gfx::Font::Weight weight);
66 void SetForegroundColor(SkColor foreground); 66 void SetForegroundColor(SkColor foreground);
67 void SetShader(SkShader* shader); 67 void SetShader(SkShader* shader);
68 // Sets underline metrics to use if the text will be drawn with an underline. 68 // Sets underline metrics to use if the text will be drawn with an underline.
69 // If not set, default values based on the size of the text will be used. The 69 // If not set, default values based on the size of the text will be used. The
70 // two metrics must be set together. 70 // two metrics must be set together.
71 void SetUnderlineMetrics(SkScalar thickness, SkScalar position); 71 void SetUnderlineMetrics(SkScalar thickness, SkScalar position);
72 void DrawSelection(const std::vector<Rect>& selection, SkColor color); 72 void DrawSelection(const std::vector<Rect>& selection, SkColor color);
73 virtual void DrawPosText(const SkPoint* pos, 73 virtual void DrawPosText(const SkPoint* pos,
74 const uint16_t* glyphs, 74 const uint16_t* glyphs,
75 size_t glyph_count); 75 size_t glyph_count);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 scoped_ptr<DiagonalStrike> diagonal_; 116 scoped_ptr<DiagonalStrike> diagonal_;
117 117
118 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); 118 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer);
119 }; 119 };
120 120
121 // Internal helper class used to iterate colors, baselines, and styles. 121 // Internal helper class used to iterate colors, baselines, and styles.
122 class StyleIterator { 122 class StyleIterator {
123 public: 123 public:
124 StyleIterator(const BreakList<SkColor>& colors, 124 StyleIterator(const BreakList<SkColor>& colors,
125 const BreakList<BaselineStyle>& baselines, 125 const BreakList<BaselineStyle>& baselines,
126 const BreakList<gfx::Font::Weight>& weights,
126 const std::vector<BreakList<bool>>& styles); 127 const std::vector<BreakList<bool>>& styles);
127 ~StyleIterator(); 128 ~StyleIterator();
128 129
129 // Get the colors and styles at the current iterator position. 130 // Get the colors and styles at the current iterator position.
130 SkColor color() const { return color_->second; } 131 SkColor color() const { return color_->second; }
131 BaselineStyle baseline() const { return baseline_->second; } 132 BaselineStyle baseline() const { return baseline_->second; }
132 bool style(TextStyle s) const { return style_[s]->second; } 133 bool style(TextStyle s) const { return style_[s]->second; }
134 gfx::Font::Weight weight() const { return weight_->second; }
133 135
134 // Get the intersecting range of the current iterator set. 136 // Get the intersecting range of the current iterator set.
135 Range GetRange() const; 137 Range GetRange() const;
136 138
137 // Update the iterator to point to colors and styles applicable at |position|. 139 // Update the iterator to point to colors and styles applicable at |position|.
138 void UpdatePosition(size_t position); 140 void UpdatePosition(size_t position);
139 141
140 private: 142 private:
141 BreakList<SkColor> colors_; 143 BreakList<SkColor> colors_;
142 BreakList<BaselineStyle> baselines_; 144 BreakList<BaselineStyle> baselines_;
145 BreakList<gfx::Font::Weight> weights_;
143 std::vector<BreakList<bool> > styles_; 146 std::vector<BreakList<bool> > styles_;
144 147
145 BreakList<SkColor>::const_iterator color_; 148 BreakList<SkColor>::const_iterator color_;
146 BreakList<BaselineStyle>::const_iterator baseline_; 149 BreakList<BaselineStyle>::const_iterator baseline_;
150 BreakList<gfx::Font::Weight>::const_iterator weight_;
147 std::vector<BreakList<bool>::const_iterator> style_; 151 std::vector<BreakList<bool>::const_iterator> style_;
148 152
149 DISALLOW_COPY_AND_ASSIGN(StyleIterator); 153 DISALLOW_COPY_AND_ASSIGN(StyleIterator);
150 }; 154 };
151 155
152 // Line segments are slices of the display text to be rendered on a single line. 156 // Line segments are slices of the display text to be rendered on a single line.
153 struct LineSegment { 157 struct LineSegment {
154 LineSegment(); 158 LineSegment();
155 ~LineSegment(); 159 ~LineSegment();
156 160
(...skipping 22 matching lines...) Expand all
179 // The sum of segment widths and the maximum of segment heights. 183 // The sum of segment widths and the maximum of segment heights.
180 SizeF size; 184 SizeF size;
181 185
182 // Sum of preceding lines' heights. 186 // Sum of preceding lines' heights.
183 int preceding_heights; 187 int preceding_heights;
184 188
185 // Maximum baseline of all segments on this line. 189 // Maximum baseline of all segments on this line.
186 int baseline; 190 int baseline;
187 }; 191 };
188 192
189 // Creates an SkTypeface from a font and a |gfx::Font::FontStyle|. 193 // Creates an SkTypeface from a font |gfx::Font::FontStyle| and weight.
msw 2016/03/22 18:24:11 nit: now it takes a bool for italic, not |gfx::Fon
Mikus 2016/03/23 17:53:22 Done.
190 // May return NULL. 194 // May return NULL.
191 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style); 195 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font,
196 bool italic,
197 gfx::Font::Weight weight);
192 198
193 // Applies the given FontRenderParams to a Skia |paint|. 199 // Applies the given FontRenderParams to a Skia |paint|.
194 void ApplyRenderParams(const FontRenderParams& params, 200 void ApplyRenderParams(const FontRenderParams& params,
195 bool subpixel_rendering_suppressed, 201 bool subpixel_rendering_suppressed,
196 SkPaint* paint); 202 SkPaint* paint);
197 203
198 } // namespace internal 204 } // namespace internal
199 205
200 // RenderText represents an abstract model of styled text and its corresponding 206 // RenderText represents an abstract model of styled text and its corresponding
201 // visual layout. Support is built in for a cursor, a selection, simple styling, 207 // visual layout. Support is built in for a cursor, a selection, simple styling,
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 // The |range| should be valid, non-reversed, and within [0, text().length()]. 362 // The |range| should be valid, non-reversed, and within [0, text().length()].
357 void SetBaselineStyle(BaselineStyle value); 363 void SetBaselineStyle(BaselineStyle value);
358 void ApplyBaselineStyle(BaselineStyle value, const Range& range); 364 void ApplyBaselineStyle(BaselineStyle value, const Range& range);
359 365
360 // Set various text styles over the entire text or a logical character range. 366 // Set various text styles over the entire text or a logical character range.
361 // The respective |style| is applied if |value| is true, or removed if false. 367 // The respective |style| is applied if |value| is true, or removed if false.
362 // The |range| should be valid, non-reversed, and within [0, text().length()]. 368 // The |range| should be valid, non-reversed, and within [0, text().length()].
363 void SetStyle(TextStyle style, bool value); 369 void SetStyle(TextStyle style, bool value);
364 void ApplyStyle(TextStyle style, bool value, const Range& range); 370 void ApplyStyle(TextStyle style, bool value, const Range& range);
365 371
372 void SetWeight(gfx::Font::Weight weight);
373 void ApplyWeight(gfx::Font::Weight weight, const Range& range);
374
366 // Returns whether this style is enabled consistently across the entire 375 // Returns whether this style is enabled consistently across the entire
367 // RenderText. 376 // RenderText.
368 bool GetStyle(TextStyle style) const; 377 bool GetStyle(TextStyle style) const;
369 378
370 // Set or get the text directionality mode and get the text direction yielded. 379 // Set or get the text directionality mode and get the text direction yielded.
371 void SetDirectionalityMode(DirectionalityMode mode); 380 void SetDirectionalityMode(DirectionalityMode mode);
372 DirectionalityMode directionality_mode() const { 381 DirectionalityMode directionality_mode() const {
373 return directionality_mode_; 382 return directionality_mode_;
374 } 383 }
375 base::i18n::TextDirection GetDisplayTextDirection(); 384 base::i18n::TextDirection GetDisplayTextDirection();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 RenderText(); 488 RenderText();
480 489
481 // NOTE: The value of these accessors may be stale. Please make sure 490 // NOTE: The value of these accessors may be stale. Please make sure
482 // that these fields are up-to-date before accessing them. 491 // that these fields are up-to-date before accessing them.
483 const base::string16& layout_text() const { return layout_text_; } 492 const base::string16& layout_text() const { return layout_text_; }
484 const base::string16& display_text() const { return display_text_; } 493 const base::string16& display_text() const { return display_text_; }
485 bool text_elided() const { return text_elided_; } 494 bool text_elided() const { return text_elided_; }
486 495
487 const BreakList<SkColor>& colors() const { return colors_; } 496 const BreakList<SkColor>& colors() const { return colors_; }
488 const BreakList<BaselineStyle>& baselines() const { return baselines_; } 497 const BreakList<BaselineStyle>& baselines() const { return baselines_; }
498 const BreakList<gfx::Font::Weight>& weights() const { return weights_; }
489 const std::vector<BreakList<bool> >& styles() const { return styles_; } 499 const std::vector<BreakList<bool> >& styles() const { return styles_; }
490 500
491 const std::vector<internal::Line>& lines() const { return lines_; } 501 const std::vector<internal::Line>& lines() const { return lines_; }
492 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 502 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
493 503
494 // Returns the baseline of the current text. The return value depends on 504 // Returns the baseline of the current text. The return value depends on
495 // the text and its layout while the return value of GetBaseline() doesn't. 505 // the text and its layout while the return value of GetBaseline() doesn't.
496 // GetAlignmentOffset() takes into account the difference between them. 506 // GetAlignmentOffset() takes into account the difference between them.
497 // 507 //
498 // We'd like a RenderText to show the text always on the same baseline 508 // We'd like a RenderText to show the text always on the same baseline
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 bool focused_; 744 bool focused_;
735 745
736 // Composition text range. 746 // Composition text range.
737 Range composition_range_; 747 Range composition_range_;
738 748
739 // Color, baseline, and style breaks, used to modify ranges of text. 749 // Color, baseline, and style breaks, used to modify ranges of text.
740 // BreakList positions are stored with text indices, not display indices. 750 // BreakList positions are stored with text indices, not display indices.
741 // TODO(msw): Expand to support cursor, selection, background, etc. colors. 751 // TODO(msw): Expand to support cursor, selection, background, etc. colors.
742 BreakList<SkColor> colors_; 752 BreakList<SkColor> colors_;
743 BreakList<BaselineStyle> baselines_; 753 BreakList<BaselineStyle> baselines_;
754 BreakList<gfx::Font::Weight> weights_;
744 std::vector<BreakList<bool> > styles_; 755 std::vector<BreakList<bool> > styles_;
745 756
746 // Breaks saved without temporary composition and selection styling. 757 // Breaks saved without temporary composition and selection styling.
747 BreakList<SkColor> saved_colors_; 758 BreakList<SkColor> saved_colors_;
748 BreakList<bool> saved_underlines_; 759 BreakList<bool> saved_underlines_;
749 bool composition_and_selection_styles_applied_; 760 bool composition_and_selection_styles_applied_;
750 761
751 // A flag to obscure actual text with asterisks for password fields. 762 // A flag to obscure actual text with asterisks for password fields.
752 bool obscured_; 763 bool obscured_;
753 // The index at which the char should be revealed in the obscured text. 764 // The index at which the char should be revealed in the obscured text.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 // Lines computed by EnsureLayout. These should be invalidated upon 832 // Lines computed by EnsureLayout. These should be invalidated upon
822 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. 833 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls.
823 std::vector<internal::Line> lines_; 834 std::vector<internal::Line> lines_;
824 835
825 DISALLOW_COPY_AND_ASSIGN(RenderText); 836 DISALLOW_COPY_AND_ASSIGN(RenderText);
826 }; 837 };
827 838
828 } // namespace gfx 839 } // namespace gfx
829 840
830 #endif // UI_GFX_RENDER_TEXT_H_ 841 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698