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

Side by Side Diff: ui/gfx/render_text.h

Issue 152473008: More or less implement RenderTextHarfBuzz (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased; decorations Created 6 years, 8 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 | Annotate | Revision Log
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 <algorithm> 8 #include <algorithm>
9 #include <cstring> 9 #include <cstring>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/command_line.h"
14 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
15 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
18 #include "skia/ext/refptr.h" 19 #include "skia/ext/refptr.h"
19 #include "third_party/skia/include/core/SkColor.h" 20 #include "third_party/skia/include/core/SkColor.h"
20 #include "third_party/skia/include/core/SkPaint.h" 21 #include "third_party/skia/include/core/SkPaint.h"
21 #include "third_party/skia/include/core/SkRect.h" 22 #include "third_party/skia/include/core/SkRect.h"
22 #include "ui/gfx/break_list.h" 23 #include "ui/gfx/break_list.h"
23 #include "ui/gfx/font_list.h" 24 #include "ui/gfx/font_list.h"
(...skipping 11 matching lines...) Expand all
35 class SkDrawLooper; 36 class SkDrawLooper;
36 struct SkPoint; 37 struct SkPoint;
37 class SkShader; 38 class SkShader;
38 class SkTypeface; 39 class SkTypeface;
39 40
40 namespace gfx { 41 namespace gfx {
41 42
42 class Canvas; 43 class Canvas;
43 class Font; 44 class Font;
44 class RenderTextTest; 45 class RenderTextTest;
46 class RenderTextHarfBuzz; // REMOVE
msw 2014/04/29 06:24:45 Move this to where it's needed, if anywhere.
ckocagil 2014/05/01 22:02:01 Done.
45 47
46 namespace internal { 48 namespace internal {
47 49
48 // Internal helper class used by derived classes to draw text through Skia. 50 // Internal helper class used by derived classes to draw text through Skia.
49 class SkiaTextRenderer { 51 class SkiaTextRenderer {
50 public: 52 public:
51 explicit SkiaTextRenderer(Canvas* canvas); 53 explicit SkiaTextRenderer(Canvas* canvas);
52 ~SkiaTextRenderer(); 54 ~SkiaTextRenderer();
53 55
54 void SetDrawLooper(SkDrawLooper* draw_looper); 56 void SetDrawLooper(SkDrawLooper* draw_looper);
(...skipping 17 matching lines...) Expand all
72 // Draw underline and strike-through text decorations. 74 // Draw underline and strike-through text decorations.
73 // Based on |SkCanvas::DrawTextDecorations()| and constants from: 75 // Based on |SkCanvas::DrawTextDecorations()| and constants from:
74 // third_party/skia/src/core/SkTextFormatParams.h 76 // third_party/skia/src/core/SkTextFormatParams.h
75 void DrawDecorations(int x, int y, int width, bool underline, bool strike, 77 void DrawDecorations(int x, int y, int width, bool underline, bool strike,
76 bool diagonal_strike); 78 bool diagonal_strike);
77 // Finishes any ongoing diagonal strike run. 79 // Finishes any ongoing diagonal strike run.
78 void EndDiagonalStrike(); 80 void EndDiagonalStrike();
79 void DrawUnderline(int x, int y, int width); 81 void DrawUnderline(int x, int y, int width);
80 void DrawStrike(int x, int y, int width) const; 82 void DrawStrike(int x, int y, int width) const;
81 83
84 SkPaint paint() const { return paint_; }
85
82 private: 86 private:
83 // Helper class to draw a diagonal line with multiple pieces of different 87 // Helper class to draw a diagonal line with multiple pieces of different
84 // lengths and colors; to support text selection appearances. 88 // lengths and colors; to support text selection appearances.
85 class DiagonalStrike { 89 class DiagonalStrike {
86 public: 90 public:
87 DiagonalStrike(Canvas* canvas, Point start, const SkPaint& paint); 91 DiagonalStrike(Canvas* canvas, Point start, const SkPaint& paint);
88 ~DiagonalStrike(); 92 ~DiagonalStrike();
89 93
90 void AddPiece(int length, SkColor color); 94 void AddPiece(int length, SkColor color);
91 void Draw(); 95 void Draw();
92 96
93 private: 97 private:
94 typedef std::pair<int, SkColor> Piece; 98 typedef std::pair<int, SkColor> Piece;
95 99
96 Canvas* canvas_; 100 Canvas* canvas_;
101 SkMatrix matrix_;
97 const Point start_; 102 const Point start_;
98 SkPaint paint_; 103 SkPaint paint_;
99 int total_length_; 104 int total_length_;
100 std::vector<Piece> pieces_; 105 std::vector<Piece> pieces_;
101 106
102 DISALLOW_COPY_AND_ASSIGN(DiagonalStrike); 107 DISALLOW_COPY_AND_ASSIGN(DiagonalStrike);
103 }; 108 };
104 109
105 Canvas* canvas_; 110 Canvas* canvas_;
106 SkCanvas* canvas_skia_; 111 SkCanvas* canvas_skia_;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // heights. 174 // heights.
170 Size size; 175 Size size;
171 176
172 // Sum of preceding lines' heights. 177 // Sum of preceding lines' heights.
173 int preceding_heights; 178 int preceding_heights;
174 179
175 // Maximum baseline of all segments on this line. 180 // Maximum baseline of all segments on this line.
176 int baseline; 181 int baseline;
177 }; 182 };
178 183
184 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const std::string& family,
185 int style);
msw 2014/04/29 06:24:45 nit: document that this is a gfx::Font::FontStyle
ckocagil 2014/05/01 22:02:01 Done.
186
179 } // namespace internal 187 } // namespace internal
180 188
181 // RenderText represents an abstract model of styled text and its corresponding 189 // RenderText represents an abstract model of styled text and its corresponding
182 // 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,
183 // complex scripts, and bi-directional text. Implementations provide mechanisms 191 // complex scripts, and bi-directional text. Implementations provide mechanisms
184 // for rendering and translation between logical and visual data. 192 // for rendering and translation between logical and visual data.
185 class GFX_EXPORT RenderText { 193 class GFX_EXPORT RenderText {
186 public: 194 public:
187 virtual ~RenderText(); 195 virtual ~RenderText();
188 196
189 // Creates a platform-specific RenderText instance. 197 // Creates a platform-specific or cross-platform RenderText instance.
190 static RenderText* CreateInstance(); 198 static RenderText* CreateInstance();
191 199
192 const base::string16& text() const { return text_; } 200 const base::string16& text() const { return text_; }
193 void SetText(const base::string16& text); 201 void SetText(const base::string16& text);
194 202
195 HorizontalAlignment horizontal_alignment() const { 203 HorizontalAlignment horizontal_alignment() const {
196 return horizontal_alignment_; 204 return horizontal_alignment_;
197 } 205 }
198 void SetHorizontalAlignment(HorizontalAlignment alignment); 206 void SetHorizontalAlignment(HorizontalAlignment alignment);
199 207
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 430
423 // Gets the horizontal bounds (relative to the left of the text, not the view) 431 // Gets the horizontal bounds (relative to the left of the text, not the view)
424 // of the glyph starting at |index|. If the glyph is RTL then the returned 432 // of the glyph starting at |index|. If the glyph is RTL then the returned
425 // Range will have is_reversed() true. (This does not return a Rect because a 433 // Range will have is_reversed() true. (This does not return a Rect because a
426 // Rect can't have a negative width.) 434 // Rect can't have a negative width.)
427 virtual Range GetGlyphBounds(size_t index) = 0; 435 virtual Range GetGlyphBounds(size_t index) = 0;
428 436
429 protected: 437 protected:
430 RenderText(); 438 RenderText();
431 439
440 // Creates a platform-specific RenderText instance.
441 static RenderText* CreateNativeInstance();
msw 2014/04/29 06:24:45 Make this private.
ckocagil 2014/05/01 22:02:01 Done.
442
432 const BreakList<SkColor>& colors() const { return colors_; } 443 const BreakList<SkColor>& colors() const { return colors_; }
433 const std::vector<BreakList<bool> >& styles() const { return styles_; } 444 const std::vector<BreakList<bool> >& styles() const { return styles_; }
434 445
435 const std::vector<internal::Line>& lines() const { return lines_; } 446 const std::vector<internal::Line>& lines() const { return lines_; }
436 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 447 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
437 448
438 // Returns the baseline of the current text. The return value depends on 449 // Returns the baseline of the current text. The return value depends on
439 // the text and its layout while the return value of GetBaseline() doesn't. 450 // the text and its layout while the return value of GetBaseline() doesn't.
440 // GetAlignmentOffset() takes into account the difference between them. 451 // GetAlignmentOffset() takes into account the difference between them.
441 // 452 //
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 // Lines computed by EnsureLayout. These should be invalidated with 717 // Lines computed by EnsureLayout. These should be invalidated with
707 // ResetLayout and on |display_rect_| changes. 718 // ResetLayout and on |display_rect_| changes.
708 std::vector<internal::Line> lines_; 719 std::vector<internal::Line> lines_;
709 720
710 DISALLOW_COPY_AND_ASSIGN(RenderText); 721 DISALLOW_COPY_AND_ASSIGN(RenderText);
711 }; 722 };
712 723
713 } // namespace gfx 724 } // namespace gfx
714 725
715 #endif // UI_GFX_RENDER_TEXT_H_ 726 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « ui/gfx/gfx.gyp ('k') | ui/gfx/render_text.cc » ('j') | ui/gfx/render_text.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698