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 #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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 std::unique_ptr<DiagonalStrike> diagonal_; | 114 std::unique_ptr<DiagonalStrike> diagonal_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); | 116 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); |
117 }; | 117 }; |
118 | 118 |
119 // Internal helper class used to iterate colors, baselines, and styles. | 119 // Internal helper class used to iterate colors, baselines, and styles. |
120 class StyleIterator { | 120 class StyleIterator { |
121 public: | 121 public: |
122 StyleIterator(const BreakList<SkColor>& colors, | 122 StyleIterator(const BreakList<SkColor>& colors, |
123 const BreakList<BaselineStyle>& baselines, | 123 const BreakList<BaselineStyle>& baselines, |
| 124 const BreakList<Font::Weight>& weights, |
124 const std::vector<BreakList<bool>>& styles); | 125 const std::vector<BreakList<bool>>& styles); |
125 ~StyleIterator(); | 126 ~StyleIterator(); |
126 | 127 |
127 // Get the colors and styles at the current iterator position. | 128 // Get the colors and styles at the current iterator position. |
128 SkColor color() const { return color_->second; } | 129 SkColor color() const { return color_->second; } |
129 BaselineStyle baseline() const { return baseline_->second; } | 130 BaselineStyle baseline() const { return baseline_->second; } |
130 bool style(TextStyle s) const { return style_[s]->second; } | 131 bool style(TextStyle s) const { return style_[s]->second; } |
| 132 Font::Weight weight() const { return weight_->second; } |
131 | 133 |
132 // Get the intersecting range of the current iterator set. | 134 // Get the intersecting range of the current iterator set. |
133 Range GetRange() const; | 135 Range GetRange() const; |
134 | 136 |
135 // Update the iterator to point to colors and styles applicable at |position|. | 137 // Update the iterator to point to colors and styles applicable at |position|. |
136 void UpdatePosition(size_t position); | 138 void UpdatePosition(size_t position); |
137 | 139 |
138 private: | 140 private: |
139 BreakList<SkColor> colors_; | 141 BreakList<SkColor> colors_; |
140 BreakList<BaselineStyle> baselines_; | 142 BreakList<BaselineStyle> baselines_; |
| 143 BreakList<Font::Weight> weights_; |
141 std::vector<BreakList<bool> > styles_; | 144 std::vector<BreakList<bool> > styles_; |
142 | 145 |
143 BreakList<SkColor>::const_iterator color_; | 146 BreakList<SkColor>::const_iterator color_; |
144 BreakList<BaselineStyle>::const_iterator baseline_; | 147 BreakList<BaselineStyle>::const_iterator baseline_; |
| 148 BreakList<Font::Weight>::const_iterator weight_; |
145 std::vector<BreakList<bool>::const_iterator> style_; | 149 std::vector<BreakList<bool>::const_iterator> style_; |
146 | 150 |
147 DISALLOW_COPY_AND_ASSIGN(StyleIterator); | 151 DISALLOW_COPY_AND_ASSIGN(StyleIterator); |
148 }; | 152 }; |
149 | 153 |
150 // Line segments are slices of the display text to be rendered on a single line. | 154 // Line segments are slices of the display text to be rendered on a single line. |
151 struct LineSegment { | 155 struct LineSegment { |
152 LineSegment(); | 156 LineSegment(); |
153 ~LineSegment(); | 157 ~LineSegment(); |
154 | 158 |
(...skipping 22 matching lines...) Expand all Loading... |
177 // The sum of segment widths and the maximum of segment heights. | 181 // The sum of segment widths and the maximum of segment heights. |
178 SizeF size; | 182 SizeF size; |
179 | 183 |
180 // Sum of preceding lines' heights. | 184 // Sum of preceding lines' heights. |
181 int preceding_heights; | 185 int preceding_heights; |
182 | 186 |
183 // Maximum baseline of all segments on this line. | 187 // Maximum baseline of all segments on this line. |
184 int baseline; | 188 int baseline; |
185 }; | 189 }; |
186 | 190 |
187 // Creates an SkTypeface from a font and a |gfx::Font::FontStyle|. | 191 // Creates an SkTypeface from a font, |italic| and a desired |weight|. |
188 // May return null. | 192 // May return null. |
189 sk_sp<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style); | 193 sk_sp<SkTypeface> CreateSkiaTypeface(const Font& font, |
| 194 bool italic, |
| 195 Font::Weight weight); |
190 | 196 |
191 // Applies the given FontRenderParams to a Skia |paint|. | 197 // Applies the given FontRenderParams to a Skia |paint|. |
192 void ApplyRenderParams(const FontRenderParams& params, | 198 void ApplyRenderParams(const FontRenderParams& params, |
193 bool subpixel_rendering_suppressed, | 199 bool subpixel_rendering_suppressed, |
194 SkPaint* paint); | 200 SkPaint* paint); |
195 | 201 |
196 } // namespace internal | 202 } // namespace internal |
197 | 203 |
198 // RenderText represents an abstract model of styled text and its corresponding | 204 // RenderText represents an abstract model of styled text and its corresponding |
199 // visual layout. Support is built in for a cursor, a selection, simple styling, | 205 // visual layout. Support is built in for a cursor, a selection, simple styling, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 // The |range| should be valid, non-reversed, and within [0, text().length()]. | 372 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
367 void SetBaselineStyle(BaselineStyle value); | 373 void SetBaselineStyle(BaselineStyle value); |
368 void ApplyBaselineStyle(BaselineStyle value, const Range& range); | 374 void ApplyBaselineStyle(BaselineStyle value, const Range& range); |
369 | 375 |
370 // Set various text styles over the entire text or a logical character range. | 376 // Set various text styles over the entire text or a logical character range. |
371 // The respective |style| is applied if |value| is true, or removed if false. | 377 // The respective |style| is applied if |value| is true, or removed if false. |
372 // The |range| should be valid, non-reversed, and within [0, text().length()]. | 378 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
373 void SetStyle(TextStyle style, bool value); | 379 void SetStyle(TextStyle style, bool value); |
374 void ApplyStyle(TextStyle style, bool value, const Range& range); | 380 void ApplyStyle(TextStyle style, bool value, const Range& range); |
375 | 381 |
| 382 void SetWeight(Font::Weight weight); |
| 383 void ApplyWeight(Font::Weight weight, const Range& range); |
| 384 |
376 // Returns whether this style is enabled consistently across the entire | 385 // Returns whether this style is enabled consistently across the entire |
377 // RenderText. | 386 // RenderText. |
378 bool GetStyle(TextStyle style) const; | 387 bool GetStyle(TextStyle style) const; |
379 | 388 |
380 // Set or get the text directionality mode and get the text direction yielded. | 389 // Set or get the text directionality mode and get the text direction yielded. |
381 void SetDirectionalityMode(DirectionalityMode mode); | 390 void SetDirectionalityMode(DirectionalityMode mode); |
382 DirectionalityMode directionality_mode() const { | 391 DirectionalityMode directionality_mode() const { |
383 return directionality_mode_; | 392 return directionality_mode_; |
384 } | 393 } |
385 base::i18n::TextDirection GetDisplayTextDirection(); | 394 base::i18n::TextDirection GetDisplayTextDirection(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 RenderText(); | 498 RenderText(); |
490 | 499 |
491 // NOTE: The value of these accessors may be stale. Please make sure | 500 // NOTE: The value of these accessors may be stale. Please make sure |
492 // that these fields are up-to-date before accessing them. | 501 // that these fields are up-to-date before accessing them. |
493 const base::string16& layout_text() const { return layout_text_; } | 502 const base::string16& layout_text() const { return layout_text_; } |
494 const base::string16& display_text() const { return display_text_; } | 503 const base::string16& display_text() const { return display_text_; } |
495 bool text_elided() const { return text_elided_; } | 504 bool text_elided() const { return text_elided_; } |
496 | 505 |
497 const BreakList<SkColor>& colors() const { return colors_; } | 506 const BreakList<SkColor>& colors() const { return colors_; } |
498 const BreakList<BaselineStyle>& baselines() const { return baselines_; } | 507 const BreakList<BaselineStyle>& baselines() const { return baselines_; } |
| 508 const BreakList<Font::Weight>& weights() const { return weights_; } |
499 const std::vector<BreakList<bool> >& styles() const { return styles_; } | 509 const std::vector<BreakList<bool> >& styles() const { return styles_; } |
500 | 510 |
501 const std::vector<internal::Line>& lines() const { return lines_; } | 511 const std::vector<internal::Line>& lines() const { return lines_; } |
502 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } | 512 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } |
503 | 513 |
504 // Returns the baseline of the current text. The return value depends on | 514 // Returns the baseline of the current text. The return value depends on |
505 // the text and its layout while the return value of GetBaseline() doesn't. | 515 // the text and its layout while the return value of GetBaseline() doesn't. |
506 // GetAlignmentOffset() takes into account the difference between them. | 516 // GetAlignmentOffset() takes into account the difference between them. |
507 // | 517 // |
508 // We'd like a RenderText to show the text always on the same baseline | 518 // 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 Loading... |
744 bool focused_; | 754 bool focused_; |
745 | 755 |
746 // Composition text range. | 756 // Composition text range. |
747 Range composition_range_; | 757 Range composition_range_; |
748 | 758 |
749 // Color, baseline, and style breaks, used to modify ranges of text. | 759 // Color, baseline, and style breaks, used to modify ranges of text. |
750 // BreakList positions are stored with text indices, not display indices. | 760 // BreakList positions are stored with text indices, not display indices. |
751 // TODO(msw): Expand to support cursor, selection, background, etc. colors. | 761 // TODO(msw): Expand to support cursor, selection, background, etc. colors. |
752 BreakList<SkColor> colors_; | 762 BreakList<SkColor> colors_; |
753 BreakList<BaselineStyle> baselines_; | 763 BreakList<BaselineStyle> baselines_; |
| 764 BreakList<Font::Weight> weights_; |
754 std::vector<BreakList<bool> > styles_; | 765 std::vector<BreakList<bool> > styles_; |
755 | 766 |
756 // Breaks saved without temporary composition and selection styling. | 767 // Breaks saved without temporary composition and selection styling. |
757 BreakList<SkColor> saved_colors_; | 768 BreakList<SkColor> saved_colors_; |
758 BreakList<bool> saved_underlines_; | 769 BreakList<bool> saved_underlines_; |
759 bool composition_and_selection_styles_applied_; | 770 bool composition_and_selection_styles_applied_; |
760 | 771 |
761 // A flag to obscure actual text with asterisks for password fields. | 772 // A flag to obscure actual text with asterisks for password fields. |
762 bool obscured_; | 773 bool obscured_; |
763 // The index at which the char should be revealed in the obscured text. | 774 // The index at which the char should be revealed in the obscured text. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 // Lines computed by EnsureLayout. These should be invalidated upon | 845 // Lines computed by EnsureLayout. These should be invalidated upon |
835 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 846 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
836 std::vector<internal::Line> lines_; | 847 std::vector<internal::Line> lines_; |
837 | 848 |
838 DISALLOW_COPY_AND_ASSIGN(RenderText); | 849 DISALLOW_COPY_AND_ASSIGN(RenderText); |
839 }; | 850 }; |
840 | 851 |
841 } // namespace gfx | 852 } // namespace gfx |
842 | 853 |
843 #endif // UI_GFX_RENDER_TEXT_H_ | 854 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |