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 <algorithm> | 8 #include <algorithm> |
9 #include <cstring> | 9 #include <cstring> |
10 #include <string> | 10 #include <string> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 namespace internal { | 45 namespace internal { |
46 | 46 |
47 // Internal helper class used by derived classes to draw text through Skia. | 47 // Internal helper class used by derived classes to draw text through Skia. |
48 class SkiaTextRenderer { | 48 class SkiaTextRenderer { |
49 public: | 49 public: |
50 explicit SkiaTextRenderer(Canvas* canvas); | 50 explicit SkiaTextRenderer(Canvas* canvas); |
51 ~SkiaTextRenderer(); | 51 ~SkiaTextRenderer(); |
52 | 52 |
53 void SetDrawLooper(SkDrawLooper* draw_looper); | 53 void SetDrawLooper(SkDrawLooper* draw_looper); |
54 void SetFontRenderParams(const FontRenderParams& params, | 54 void SetFontRenderParams(const FontRenderParams& params, |
55 bool background_is_transparent); | 55 bool subpixel_rendering_enabled); |
56 void SetTypeface(SkTypeface* typeface); | 56 void SetTypeface(SkTypeface* typeface); |
57 void SetTextSize(SkScalar size); | 57 void SetTextSize(SkScalar size); |
58 void SetFontFamilyWithStyle(const std::string& family, int font_style); | 58 void SetFontFamilyWithStyle(const std::string& family, int font_style); |
59 void SetForegroundColor(SkColor foreground); | 59 void SetForegroundColor(SkColor foreground); |
60 void SetShader(SkShader* shader); | 60 void SetShader(SkShader* shader); |
61 // Sets underline metrics to use if the text will be drawn with an underline. | 61 // Sets underline metrics to use if the text will be drawn with an underline. |
62 // If not set, default values based on the size of the text will be used. The | 62 // If not set, default values based on the size of the text will be used. The |
63 // two metrics must be set together. | 63 // two metrics must be set together. |
64 void SetUnderlineMetrics(SkScalar thickness, SkScalar position); | 64 void SetUnderlineMetrics(SkScalar thickness, SkScalar position); |
65 void DrawSelection(const std::vector<Rect>& selection, SkColor color); | 65 void DrawSelection(const std::vector<Rect>& selection, SkColor color); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 int baseline; | 174 int baseline; |
175 }; | 175 }; |
176 | 176 |
177 // Creates an SkTypeface from a font |family| name and a |gfx::Font::FontStyle|. | 177 // Creates an SkTypeface from a font |family| name and a |gfx::Font::FontStyle|. |
178 // May return NULL. | 178 // May return NULL. |
179 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const std::string& family, | 179 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const std::string& family, |
180 int style); | 180 int style); |
181 | 181 |
182 // Applies the given FontRenderParams to a Skia |paint|. | 182 // Applies the given FontRenderParams to a Skia |paint|. |
183 void ApplyRenderParams(const FontRenderParams& params, | 183 void ApplyRenderParams(const FontRenderParams& params, |
184 bool background_is_transparent, | 184 bool subpixel_rendering_enabled, |
185 SkPaint* paint); | 185 SkPaint* paint); |
186 | 186 |
187 } // namespace internal | 187 } // namespace internal |
188 | 188 |
189 // RenderText represents an abstract model of styled text and its corresponding | 189 // RenderText represents an abstract model of styled text and its corresponding |
190 // visual layout. Support is built in for a cursor, a selection, simple styling, | 190 // visual layout. Support is built in for a cursor, a selection, simple styling, |
191 // complex scripts, and bi-directional text. Implementations provide mechanisms | 191 // complex scripts, and bi-directional text. Implementations provide mechanisms |
192 // for rendering and translation between logical and visual data. | 192 // for rendering and translation between logical and visual data. |
193 class GFX_EXPORT RenderText { | 193 class GFX_EXPORT RenderText { |
194 public: | 194 public: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 // WARNING: Only use this for system limits, it lacks complex text support. | 266 // WARNING: Only use this for system limits, it lacks complex text support. |
267 void set_truncate_length(size_t length) { truncate_length_ = length; } | 267 void set_truncate_length(size_t length) { truncate_length_ = length; } |
268 | 268 |
269 // The layout text will be elided to fit |display_rect| using this behavior. | 269 // The layout text will be elided to fit |display_rect| using this behavior. |
270 void SetElideBehavior(ElideBehavior elide_behavior); | 270 void SetElideBehavior(ElideBehavior elide_behavior); |
271 ElideBehavior elide_behavior() const { return elide_behavior_; } | 271 ElideBehavior elide_behavior() const { return elide_behavior_; } |
272 | 272 |
273 const Rect& display_rect() const { return display_rect_; } | 273 const Rect& display_rect() const { return display_rect_; } |
274 void SetDisplayRect(const Rect& r); | 274 void SetDisplayRect(const Rect& r); |
275 | 275 |
276 bool background_is_transparent() const { return background_is_transparent_; } | 276 bool subpixel_rendering_enabled() const { |
277 void set_background_is_transparent(bool transparent) { | 277 return subpixel_rendering_enabled_; |
278 background_is_transparent_ = transparent; | 278 } |
279 void set_subpixel_rendering_enabled(bool enabled) { | |
280 subpixel_rendering_enabled_ = enabled; | |
279 } | 281 } |
280 | 282 |
281 const SelectionModel& selection_model() const { return selection_model_; } | 283 const SelectionModel& selection_model() const { return selection_model_; } |
282 | 284 |
283 const Range& selection() const { return selection_model_.selection(); } | 285 const Range& selection() const { return selection_model_.selection(); } |
284 | 286 |
285 size_t cursor_position() const { return selection_model_.caret_pos(); } | 287 size_t cursor_position() const { return selection_model_.caret_pos(); } |
286 void SetCursorPosition(size_t position); | 288 void SetCursorPosition(size_t position); |
287 | 289 |
288 // Moves the cursor left or right. Cursor movement is visual, meaning that | 290 // Moves the cursor left or right. Cursor movement is visual, meaning that |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 // True if the text is elided given the current behavior and display area. | 727 // True if the text is elided given the current behavior and display area. |
726 bool text_elided_; | 728 bool text_elided_; |
727 | 729 |
728 // The minimum height a line should have. | 730 // The minimum height a line should have. |
729 int min_line_height_; | 731 int min_line_height_; |
730 | 732 |
731 // Whether the text should be broken into multiple lines. Uses the width of | 733 // Whether the text should be broken into multiple lines. Uses the width of |
732 // |display_rect_| as the width cap. | 734 // |display_rect_| as the width cap. |
733 bool multiline_; | 735 bool multiline_; |
734 | 736 |
735 // Is the background transparent (either partially or fully)? | 737 // Set to false to suppress subpixel rendering due to non-font reasons (such |
msw
2015/02/19 00:56:25
nit: "(eg. if the background is transparent)"
Jun Mukai
2015/02/19 02:07:48
Done.
| |
736 bool background_is_transparent_; | 738 // like background is transparent). The default value is true. |
739 bool subpixel_rendering_enabled_; | |
737 | 740 |
738 // The local display area for rendering the text. | 741 // The local display area for rendering the text. |
739 Rect display_rect_; | 742 Rect display_rect_; |
740 | 743 |
741 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) | 744 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) |
742 // that results in incorrect clipping when drawing to the document margins. | 745 // that results in incorrect clipping when drawing to the document margins. |
743 // This field allows disabling clipping to work around the issue. | 746 // This field allows disabling clipping to work around the issue. |
744 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. | 747 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. |
745 bool clip_to_display_rect_; | 748 bool clip_to_display_rect_; |
746 | 749 |
(...skipping 19 matching lines...) Expand all Loading... | |
766 // Lines computed by EnsureLayout. These should be invalidated upon | 769 // Lines computed by EnsureLayout. These should be invalidated upon |
767 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 770 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
768 std::vector<internal::Line> lines_; | 771 std::vector<internal::Line> lines_; |
769 | 772 |
770 DISALLOW_COPY_AND_ASSIGN(RenderText); | 773 DISALLOW_COPY_AND_ASSIGN(RenderText); |
771 }; | 774 }; |
772 | 775 |
773 } // namespace gfx | 776 } // namespace gfx |
774 | 777 |
775 #endif // UI_GFX_RENDER_TEXT_H_ | 778 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |