OLD | NEW |
---|---|
(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 "ui/gfx/render_text.h" | |
13 | |
14 namespace gfx { | |
15 | |
16 namespace internal { | |
17 | |
18 struct TextRunHarfBuzz { | |
19 TextRunHarfBuzz(); | |
20 ~TextRunHarfBuzz(); | |
21 | |
22 int width; | |
23 Range range; | |
24 UBiDiDirection direction; | |
25 UBiDiLevel level; | |
26 | |
27 scoped_ptr<uint16[]> glyphs; | |
28 scoped_ptr<SkPoint[]> positions; | |
29 scoped_ptr<uint32[]> glyph_to_char; | |
30 size_t glyph_count; | |
31 | |
32 skia::RefPtr<SkTypeface> skia_face; | |
33 int font_size; | |
34 int font_style; | |
35 bool strike; | |
36 bool diagonal_strike; | |
37 bool underline; | |
38 }; | |
39 | |
40 } // namespace internal | |
41 | |
42 class RenderTextHarfBuzz : public RenderText { | |
43 public: | |
44 RenderTextHarfBuzz(); | |
45 virtual ~RenderTextHarfBuzz(); | |
46 | |
47 // Overridden from RenderText. | |
48 virtual Size GetStringSize() OVERRIDE; | |
49 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; | |
50 virtual bool IsCursorablePosition(size_t position) OVERRIDE; | |
51 virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE; | |
52 | |
53 protected: | |
54 // Overridden from RenderText. | |
55 virtual int GetLayoutTextBaseline() OVERRIDE; | |
56 virtual SelectionModel AdjacentCharSelectionModel( | |
57 const SelectionModel& selection, | |
58 VisualCursorDirection direction) OVERRIDE; | |
59 virtual SelectionModel AdjacentWordSelectionModel( | |
60 const SelectionModel& selection, | |
61 VisualCursorDirection direction) OVERRIDE; | |
62 virtual Range GetGlyphBounds(size_t index) OVERRIDE; | |
63 virtual std::vector<Rect> GetSubstringBounds(const Range& range) OVERRIDE; | |
64 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE; | |
65 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE; | |
66 virtual void ResetLayout() OVERRIDE; | |
67 virtual void EnsureLayout() OVERRIDE; | |
68 virtual void DrawVisualText(Canvas* canvas) OVERRIDE; | |
69 | |
70 void ShapeRun(internal::TextRunHarfBuzz* run); | |
msw
2014/04/29 06:24:45
nit: comment like "Shape the glyphs needed for the
ckocagil
2014/05/01 22:02:01
Done.
| |
71 | |
72 size_t GetRunContainingCaret(const SelectionModel& caret) const; | |
msw
2014/04/29 06:24:45
nit: copy/adapt the comments from RenderTextWin fo
ckocagil
2014/05/01 22:02:01
Done.
| |
73 | |
74 // Returns the X coordinate of the leading or |trailing| edge of the glyph | |
75 // starting at |index|, relative to the left of the text (not the view). | |
76 int GetGlyphXBoundary(size_t run_index, size_t text_index, bool trailing); | |
77 | |
78 SelectionModel RenderTextHarfBuzz::FirstSelectionModelInsideRun( | |
79 const internal::TextRunHarfBuzz* run); | |
80 | |
81 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun( | |
82 const internal::TextRunHarfBuzz* run); | |
83 | |
84 size_t GetRunContainingXCoord(int x, int* offset) const; | |
85 | |
86 private: | |
87 // Text runs in logical order. | |
88 ScopedVector<internal::TextRunHarfBuzz> runs_; | |
89 | |
90 // Maps visual run indices to logical run indices and vice versa. | |
91 std::vector<int32_t> visual_to_logical_; | |
92 std::vector<int32_t> logical_to_visual_; | |
93 | |
94 bool needs_layout_; | |
95 }; | |
96 | |
97 } // namespace gfx | |
98 | |
99 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ | |
OLD | NEW |