OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 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 private: | |
43 DISALLOW_COPY_AND_ASSIGN(TextRunHarfBuzz); | |
44 }; | |
45 | |
46 } // namespace internal | |
47 | |
48 class RenderTextHarfBuzz : public RenderText { | |
49 public: | |
50 RenderTextHarfBuzz(); | |
51 virtual ~RenderTextHarfBuzz(); | |
52 | |
53 // Overridden from RenderText. | |
54 virtual Size GetStringSize() OVERRIDE; | |
55 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; | |
56 virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE; | |
57 | |
58 protected: | |
59 // Overridden from RenderText. | |
60 virtual int GetLayoutTextBaseline() OVERRIDE; | |
61 virtual SelectionModel AdjacentCharSelectionModel( | |
62 const SelectionModel& selection, | |
63 VisualCursorDirection direction) OVERRIDE; | |
64 virtual SelectionModel AdjacentWordSelectionModel( | |
65 const SelectionModel& selection, | |
66 VisualCursorDirection direction) OVERRIDE; | |
67 virtual Range GetGlyphBounds(size_t index) OVERRIDE; | |
68 virtual std::vector<Rect> GetSubstringBounds(const Range& range) OVERRIDE; | |
69 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE; | |
70 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE; | |
71 virtual bool IsValidCursorIndex(size_t index) OVERRIDE; | |
72 virtual void ResetLayout() OVERRIDE; | |
73 virtual void EnsureLayout() OVERRIDE; | |
74 virtual void DrawVisualText(Canvas* canvas) OVERRIDE; | |
75 | |
76 private: | |
77 // Return the run index that contains the argument; or the length of the | |
78 // |runs_| vector if argument exceeds the text length or width. | |
79 size_t GetRunContainingCaret(const SelectionModel& caret) const; | |
80 size_t GetRunContainingXCoord(int x, int* offset) const; | |
81 | |
82 // Returns the X coordinate of the leading or |trailing| edge of the glyph | |
83 // starting at |index|, relative to the left of the text (not the view). | |
84 int GetGlyphXBoundary(size_t run_index, size_t text_index, bool trailing); | |
85 | |
86 // Given a |run|, returns the SelectionModel that contains the logical first | |
87 // or last caret position inside (not at a boundary of) the run. | |
88 // The returned value represents a cursor/caret position without a selection. | |
89 SelectionModel RenderTextHarfBuzz::FirstSelectionModelInsideRun( | |
90 const internal::TextRunHarfBuzz* run); | |
91 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun( | |
92 const internal::TextRunHarfBuzz* run); | |
93 | |
94 // Break the text into logical runs and populate the visual <-> logical maps. | |
95 void ItemizeText(); | |
96 | |
97 // Shape the glyphs needed for the text |run|. | |
98 void ShapeRun(internal::TextRunHarfBuzz* run); | |
99 | |
100 // Text runs in logical order. | |
101 ScopedVector<internal::TextRunHarfBuzz> runs_; | |
102 | |
103 // Maps visual run indices to logical run indices and vice versa. | |
104 std::vector<int32_t> visual_to_logical_; | |
105 std::vector<int32_t> logical_to_visual_; | |
106 | |
107 bool needs_layout_; | |
Alexei Svitkine (slow)
2014/05/13 15:23:27
Nit: DISALLOW_COPY_AND_ASSIGN() on RenderTextHarfB
ckocagil
2014/05/16 13:47:25
Oops... Done.
| |
108 }; | |
109 | |
110 } // namespace gfx | |
111 | |
112 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ | |
OLD | NEW |