OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
Alexei Svitkine (slow)
2014/05/12 15:58:31
Nit: Remove (c)
ckocagil
2014/05/13 15:03:48
Done (and done for .cc too)
| |
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 std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE; | |
54 | |
55 protected: | |
56 // Overridden from RenderText. | |
57 virtual int GetLayoutTextBaseline() OVERRIDE; | |
58 virtual SelectionModel AdjacentCharSelectionModel( | |
59 const SelectionModel& selection, | |
60 VisualCursorDirection direction) OVERRIDE; | |
61 virtual SelectionModel AdjacentWordSelectionModel( | |
62 const SelectionModel& selection, | |
63 VisualCursorDirection direction) OVERRIDE; | |
64 virtual Range GetGlyphBounds(size_t index) OVERRIDE; | |
65 virtual std::vector<Rect> GetSubstringBounds(const Range& range) OVERRIDE; | |
66 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE; | |
67 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE; | |
68 virtual bool IsValidCursorIndex(size_t index) 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 // Break the text into logical runs and populate the visual <-> logical maps. | |
92 void ItemizeText(); | |
93 | |
94 // Shape the glyphs needed for the text |run|. | |
95 void ShapeRun(internal::TextRunHarfBuzz* run); | |
96 | |
97 // Text runs in logical order. | |
98 ScopedVector<internal::TextRunHarfBuzz> runs_; | |
99 | |
100 // Maps visual run indices to logical run indices and vice versa. | |
101 std::vector<int32_t> visual_to_logical_; | |
102 std::vector<int32_t> logical_to_visual_; | |
103 | |
104 bool needs_layout_; | |
105 }; | |
Alexei Svitkine (slow)
2014/05/12 15:58:31
DISALLOW_COPY_AND_ASSIGN()?
ckocagil
2014/05/13 15:03:48
Done.
| |
106 | |
107 } // namespace gfx | |
108 | |
109 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ | |
OLD | NEW |