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

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

Powered by Google App Engine
This is Rietveld 408576698