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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 // is cleared and only the last set index will be revealed. If |index| is -1 | 249 // is cleared and only the last set index will be revealed. If |index| is -1 |
250 // or out of range, no char will be revealed. The revealed index is also | 250 // or out of range, no char will be revealed. The revealed index is also |
251 // cleared when SetText or SetObscured is called. | 251 // cleared when SetText or SetObscured is called. |
252 void SetObscuredRevealIndex(int index); | 252 void SetObscuredRevealIndex(int index); |
253 | 253 |
254 // TODO(ckocagil): Multiline text rendering is currently only supported on | 254 // TODO(ckocagil): Multiline text rendering is currently only supported on |
255 // Windows. Support other platforms. | 255 // Windows. Support other platforms. |
256 bool multiline() const { return multiline_; } | 256 bool multiline() const { return multiline_; } |
257 void SetMultiline(bool multiline); | 257 void SetMultiline(bool multiline); |
258 | 258 |
259 // Returns true if this supports multiline rendering. | |
260 virtual bool MultilineSupported() const = 0; | |
261 | |
259 // TODO(ckocagil): Add vertical alignment and line spacing support instead. | 262 // TODO(ckocagil): Add vertical alignment and line spacing support instead. |
260 int min_line_height() const { return min_line_height_; } | 263 int min_line_height() const { return min_line_height_; } |
261 void SetMinLineHeight(int line_height); | 264 void SetMinLineHeight(int line_height); |
262 | 265 |
263 // Set the maximum length of the layout text, not the actual text. | 266 // Set the maximum length of the layout text, not the actual text. |
264 // A |length| of 0 forgoes a hard limit, but does not guarantee proper | 267 // A |length| of 0 forgoes a hard limit, but does not guarantee proper |
265 // functionality of very long strings. Applies to subsequent SetText calls. | 268 // functionality of very long strings. Applies to subsequent SetText calls. |
266 // WARNING: Only use this for system limits, it lacks complex text support. | 269 // WARNING: Only use this for system limits, it lacks complex text support. |
267 void set_truncate_length(size_t length) { truncate_length_ = length; } | 270 void set_truncate_length(size_t length) { truncate_length_ = length; } |
268 | 271 |
269 // The layout text will be elided to fit |display_rect| using this behavior. | 272 // The layout text will be elided to fit |display_rect| using this behavior. |
270 void SetElideBehavior(ElideBehavior elide_behavior); | 273 void SetElideBehavior(ElideBehavior elide_behavior); |
271 ElideBehavior elide_behavior() const { return elide_behavior_; } | 274 ElideBehavior elide_behavior() const { return elide_behavior_; } |
272 | 275 |
273 const Rect& display_rect() const { return display_rect_; } | 276 const Rect& display_rect() const { return display_rect_; } |
274 void SetDisplayRect(const Rect& r); | 277 void SetDisplayRect(const Rect& r); |
275 | 278 |
276 bool background_is_transparent() const { return background_is_transparent_; } | 279 bool subpixel_rendering_enabled() const { |
277 void set_background_is_transparent(bool transparent) { | 280 return subpixel_rendering_enabled_; |
278 background_is_transparent_ = transparent; | 281 } |
282 void set_subpixel_rendering_enabled(bool enabled) { | |
283 subpixel_rendering_enabled_ = enabled; | |
279 } | 284 } |
280 | 285 |
281 const SelectionModel& selection_model() const { return selection_model_; } | 286 const SelectionModel& selection_model() const { return selection_model_; } |
282 | 287 |
283 const Range& selection() const { return selection_model_.selection(); } | 288 const Range& selection() const { return selection_model_.selection(); } |
284 | 289 |
285 size_t cursor_position() const { return selection_model_.caret_pos(); } | 290 size_t cursor_position() const { return selection_model_.caret_pos(); } |
286 void SetCursorPosition(size_t position); | 291 void SetCursorPosition(size_t position); |
287 | 292 |
288 // Moves the cursor left or right. Cursor movement is visual, meaning that | 293 // Moves the cursor left or right. Cursor movement is visual, meaning that |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 // supplied index is already at the boundary of the string. | 424 // supplied index is already at the boundary of the string. |
420 size_t IndexOfAdjacentGrapheme(size_t index, | 425 size_t IndexOfAdjacentGrapheme(size_t index, |
421 LogicalCursorDirection direction); | 426 LogicalCursorDirection direction); |
422 | 427 |
423 // Return a SelectionModel with the cursor at the current selection's start. | 428 // Return a SelectionModel with the cursor at the current selection's start. |
424 // The returned value represents a cursor/caret position without a selection. | 429 // The returned value represents a cursor/caret position without a selection. |
425 SelectionModel GetSelectionModelForSelectionStart(); | 430 SelectionModel GetSelectionModelForSelectionStart(); |
426 | 431 |
427 // Sets shadows to drawn with text. | 432 // Sets shadows to drawn with text. |
428 void set_shadows(const ShadowValues& shadows) { shadows_ = shadows; } | 433 void set_shadows(const ShadowValues& shadows) { shadows_ = shadows; } |
429 const ShadowValues& shadows() { return shadows_; } | 434 const ShadowValues& shadows() const { return shadows_; } |
430 | 435 |
431 typedef std::pair<Font, Range> FontSpan; | 436 typedef std::pair<Font, Range> FontSpan; |
432 // For testing purposes, returns which fonts were chosen for which parts of | 437 // For testing purposes, returns which fonts were chosen for which parts of |
433 // the text by returning a vector of Font and Range pairs, where each range | 438 // the text by returning a vector of Font and Range pairs, where each range |
434 // specifies the character range for which the corresponding font has been | 439 // specifies the character range for which the corresponding font has been |
435 // chosen. | 440 // chosen. |
436 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; | 441 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; |
437 | 442 |
438 // Gets the horizontal bounds (relative to the left of the text, not the view) | 443 // Gets the horizontal bounds (relative to the left of the text, not the view) |
439 // of the glyph starting at |index|. If the glyph is RTL then the returned | 444 // of the glyph starting at |index|. If the glyph is RTL then the returned |
(...skipping 285 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. | 730 // True if the text is elided given the current behavior and display area. |
726 bool text_elided_; | 731 bool text_elided_; |
727 | 732 |
728 // The minimum height a line should have. | 733 // The minimum height a line should have. |
729 int min_line_height_; | 734 int min_line_height_; |
730 | 735 |
731 // Whether the text should be broken into multiple lines. Uses the width of | 736 // Whether the text should be broken into multiple lines. Uses the width of |
732 // |display_rect_| as the width cap. | 737 // |display_rect_| as the width cap. |
733 bool multiline_; | 738 bool multiline_; |
734 | 739 |
735 // Is the background transparent (either partially or fully)? | 740 // Is the background transparent (either partially or fully)? |
msw
2015/02/17 22:16:45
nit: update comment.
| |
736 bool background_is_transparent_; | 741 bool subpixel_rendering_enabled_; |
737 | 742 |
738 // The local display area for rendering the text. | 743 // The local display area for rendering the text. |
739 Rect display_rect_; | 744 Rect display_rect_; |
740 | 745 |
741 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) | 746 // 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. | 747 // that results in incorrect clipping when drawing to the document margins. |
743 // This field allows disabling clipping to work around the issue. | 748 // This field allows disabling clipping to work around the issue. |
744 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. | 749 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. |
745 bool clip_to_display_rect_; | 750 bool clip_to_display_rect_; |
746 | 751 |
(...skipping 19 matching lines...) Expand all Loading... | |
766 // Lines computed by EnsureLayout. These should be invalidated upon | 771 // Lines computed by EnsureLayout. These should be invalidated upon |
767 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 772 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
768 std::vector<internal::Line> lines_; | 773 std::vector<internal::Line> lines_; |
769 | 774 |
770 DISALLOW_COPY_AND_ASSIGN(RenderText); | 775 DISALLOW_COPY_AND_ASSIGN(RenderText); |
771 }; | 776 }; |
772 | 777 |
773 } // namespace gfx | 778 } // namespace gfx |
774 | 779 |
775 #endif // UI_GFX_RENDER_TEXT_H_ | 780 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |