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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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, italic flag and weight. May return NULL. |
190 // May return NULL. | 194 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, |
191 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style); | 195 bool italic, |
| 196 gfx::Font::Weight weight); |
192 | 197 |
193 // Applies the given FontRenderParams to a Skia |paint|. | 198 // Applies the given FontRenderParams to a Skia |paint|. |
194 void ApplyRenderParams(const FontRenderParams& params, | 199 void ApplyRenderParams(const FontRenderParams& params, |
195 bool subpixel_rendering_suppressed, | 200 bool subpixel_rendering_suppressed, |
196 SkPaint* paint); | 201 SkPaint* paint); |
197 | 202 |
198 } // namespace internal | 203 } // namespace internal |
199 | 204 |
200 // RenderText represents an abstract model of styled text and its corresponding | 205 // 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, | 206 // 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 Loading... |
356 // The |range| should be valid, non-reversed, and within [0, text().length()]. | 361 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
357 void SetBaselineStyle(BaselineStyle value); | 362 void SetBaselineStyle(BaselineStyle value); |
358 void ApplyBaselineStyle(BaselineStyle value, const Range& range); | 363 void ApplyBaselineStyle(BaselineStyle value, const Range& range); |
359 | 364 |
360 // Set various text styles over the entire text or a logical character range. | 365 // 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. | 366 // 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()]. | 367 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
363 void SetStyle(TextStyle style, bool value); | 368 void SetStyle(TextStyle style, bool value); |
364 void ApplyStyle(TextStyle style, bool value, const Range& range); | 369 void ApplyStyle(TextStyle style, bool value, const Range& range); |
365 | 370 |
| 371 void SetWeight(gfx::Font::Weight weight); |
| 372 void ApplyWeight(gfx::Font::Weight weight, const Range& range); |
| 373 |
366 // Returns whether this style is enabled consistently across the entire | 374 // Returns whether this style is enabled consistently across the entire |
367 // RenderText. | 375 // RenderText. |
368 bool GetStyle(TextStyle style) const; | 376 bool GetStyle(TextStyle style) const; |
369 | 377 |
370 // Set or get the text directionality mode and get the text direction yielded. | 378 // Set or get the text directionality mode and get the text direction yielded. |
371 void SetDirectionalityMode(DirectionalityMode mode); | 379 void SetDirectionalityMode(DirectionalityMode mode); |
372 DirectionalityMode directionality_mode() const { | 380 DirectionalityMode directionality_mode() const { |
373 return directionality_mode_; | 381 return directionality_mode_; |
374 } | 382 } |
375 base::i18n::TextDirection GetDisplayTextDirection(); | 383 base::i18n::TextDirection GetDisplayTextDirection(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 RenderText(); | 487 RenderText(); |
480 | 488 |
481 // NOTE: The value of these accessors may be stale. Please make sure | 489 // NOTE: The value of these accessors may be stale. Please make sure |
482 // that these fields are up-to-date before accessing them. | 490 // that these fields are up-to-date before accessing them. |
483 const base::string16& layout_text() const { return layout_text_; } | 491 const base::string16& layout_text() const { return layout_text_; } |
484 const base::string16& display_text() const { return display_text_; } | 492 const base::string16& display_text() const { return display_text_; } |
485 bool text_elided() const { return text_elided_; } | 493 bool text_elided() const { return text_elided_; } |
486 | 494 |
487 const BreakList<SkColor>& colors() const { return colors_; } | 495 const BreakList<SkColor>& colors() const { return colors_; } |
488 const BreakList<BaselineStyle>& baselines() const { return baselines_; } | 496 const BreakList<BaselineStyle>& baselines() const { return baselines_; } |
| 497 const BreakList<gfx::Font::Weight>& weights() const { return weights_; } |
489 const std::vector<BreakList<bool> >& styles() const { return styles_; } | 498 const std::vector<BreakList<bool> >& styles() const { return styles_; } |
490 | 499 |
491 const std::vector<internal::Line>& lines() const { return lines_; } | 500 const std::vector<internal::Line>& lines() const { return lines_; } |
492 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } | 501 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } |
493 | 502 |
494 // Returns the baseline of the current text. The return value depends on | 503 // 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. | 504 // the text and its layout while the return value of GetBaseline() doesn't. |
496 // GetAlignmentOffset() takes into account the difference between them. | 505 // GetAlignmentOffset() takes into account the difference between them. |
497 // | 506 // |
498 // We'd like a RenderText to show the text always on the same baseline | 507 // 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... |
734 bool focused_; | 743 bool focused_; |
735 | 744 |
736 // Composition text range. | 745 // Composition text range. |
737 Range composition_range_; | 746 Range composition_range_; |
738 | 747 |
739 // Color, baseline, and style breaks, used to modify ranges of text. | 748 // Color, baseline, and style breaks, used to modify ranges of text. |
740 // BreakList positions are stored with text indices, not display indices. | 749 // BreakList positions are stored with text indices, not display indices. |
741 // TODO(msw): Expand to support cursor, selection, background, etc. colors. | 750 // TODO(msw): Expand to support cursor, selection, background, etc. colors. |
742 BreakList<SkColor> colors_; | 751 BreakList<SkColor> colors_; |
743 BreakList<BaselineStyle> baselines_; | 752 BreakList<BaselineStyle> baselines_; |
| 753 BreakList<gfx::Font::Weight> weights_; |
744 std::vector<BreakList<bool> > styles_; | 754 std::vector<BreakList<bool> > styles_; |
745 | 755 |
746 // Breaks saved without temporary composition and selection styling. | 756 // Breaks saved without temporary composition and selection styling. |
747 BreakList<SkColor> saved_colors_; | 757 BreakList<SkColor> saved_colors_; |
748 BreakList<bool> saved_underlines_; | 758 BreakList<bool> saved_underlines_; |
749 bool composition_and_selection_styles_applied_; | 759 bool composition_and_selection_styles_applied_; |
750 | 760 |
751 // A flag to obscure actual text with asterisks for password fields. | 761 // A flag to obscure actual text with asterisks for password fields. |
752 bool obscured_; | 762 bool obscured_; |
753 // The index at which the char should be revealed in the obscured text. | 763 // 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 Loading... |
821 // Lines computed by EnsureLayout. These should be invalidated upon | 831 // Lines computed by EnsureLayout. These should be invalidated upon |
822 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 832 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
823 std::vector<internal::Line> lines_; | 833 std::vector<internal::Line> lines_; |
824 | 834 |
825 DISALLOW_COPY_AND_ASSIGN(RenderText); | 835 DISALLOW_COPY_AND_ASSIGN(RenderText); |
826 }; | 836 }; |
827 | 837 |
828 } // namespace gfx | 838 } // namespace gfx |
829 | 839 |
830 #endif // UI_GFX_RENDER_TEXT_H_ | 840 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |