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

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

Issue 152473008: More or less implement RenderTextHarfBuzz (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more comments Created 6 years, 7 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
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_GFX_RENDER_TEXT_HARFBUZZ_H_
6 #define UI_GFX_RENDER_TEXT_HARFBUZZ_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h"
10 #include "third_party/harfbuzz-ng/src/hb.h"
11 #include "third_party/icu/source/common/unicode/ubidi.h"
12 #include "third_party/icu/source/common/unicode/uscript.h"
13 #include "ui/gfx/render_text.h"
14
15 namespace gfx {
16
17 namespace internal {
18
19 struct TextRunHarfBuzz {
20 TextRunHarfBuzz();
21 ~TextRunHarfBuzz();
22
23 int width;
24 int preceding_run_widths;
25 Range range;
26 UBiDiDirection direction;
27 UBiDiLevel level;
28 UScriptCode script;
29
30 scoped_ptr<uint16[]> glyphs;
31 scoped_ptr<SkPoint[]> positions;
32 scoped_ptr<uint32[]> glyph_to_char;
33 size_t glyph_count;
34
35 skia::RefPtr<SkTypeface> skia_face;
36 int font_size;
37 int font_style;
38 bool strike;
39 bool diagonal_strike;
40 bool underline;
41 };
42
43 } // namespace internal
44
45 class RenderTextHarfBuzz : public RenderText {
46 public:
47 RenderTextHarfBuzz();
48 virtual ~RenderTextHarfBuzz();
49
50 // Overridden from RenderText.
51 virtual Size GetStringSize() OVERRIDE;
52 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
53 virtual bool IsCursorablePosition(size_t position) OVERRIDE;
54 virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE;
55
56 protected:
57 // Overridden from RenderText.
58 virtual int GetLayoutTextBaseline() OVERRIDE;
59 virtual SelectionModel AdjacentCharSelectionModel(
60 const SelectionModel& selection,
61 VisualCursorDirection direction) OVERRIDE;
62 virtual SelectionModel AdjacentWordSelectionModel(
63 const SelectionModel& selection,
64 VisualCursorDirection direction) OVERRIDE;
65 virtual Range GetGlyphBounds(size_t index) OVERRIDE;
66 virtual std::vector<Rect> GetSubstringBounds(const Range& range) OVERRIDE;
67 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE;
68 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE;
69 virtual void ResetLayout() OVERRIDE;
70 virtual void EnsureLayout() OVERRIDE;
71 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
72
73 private:
74 // Return the run index that contains the argument; or the length of the
75 // |runs_| vector if argument exceeds the text length or width.
76 size_t GetRunContainingCaret(const SelectionModel& caret) const;
77 size_t GetRunContainingXCoord(int x, int* offset) const;
78
79 // Returns the X coordinate of the leading or |trailing| edge of the glyph
80 // starting at |index|, relative to the left of the text (not the view).
81 int GetGlyphXBoundary(size_t run_index, size_t text_index, bool trailing);
82
83 // Given a |run|, returns the SelectionModel that contains the logical first
84 // or last caret position inside (not at a boundary of) the run.
85 // The returned value represents a cursor/caret position without a selection.
86 SelectionModel RenderTextHarfBuzz::FirstSelectionModelInsideRun(
87 const internal::TextRunHarfBuzz* run);
88 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun(
89 const internal::TextRunHarfBuzz* run);
90
91 void ItemizeText();
msw 2014/05/09 22:55:19 nit: Add a comment like "Break the text into lines
ckocagil 2014/05/12 09:53:29 Done.
92
93 // Shape the glyphs needed for the text |run|.
94 void ShapeRun(internal::TextRunHarfBuzz* run);
95
96 // Text runs in logical order.
97 ScopedVector<internal::TextRunHarfBuzz> runs_;
98
99 // Maps visual run indices to logical run indices and vice versa.
100 std::vector<int32_t> visual_to_logical_;
101 std::vector<int32_t> logical_to_visual_;
102
103 bool needs_layout_;
104 };
105
106 } // namespace gfx
107
108 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698