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

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: 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 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 // Returns the index of the first glyph that corresponds to the character at
24 // |pos|.
25 size_t CharToGlyph(size_t pos) const;
26
27 // Returns the corresponding glyph range of the given character range.
28 // |range| is in text-space (0 corresponds to |GetLayoutText()[0]|). Returned
29 // value is in run-space (0 corresponds to the first glyph in the run).
30 Range CharRangeToGlyphRange(const Range& range) const;
31
32 // Returns whether the given shaped run contains any missing glyphs.
msw 2014/05/20 19:13:44 nit: indentation.
ckocagil 2014/05/21 14:34:39 Done.
33 bool HasMissingGlyphs() const;
34
35 int width;
36 int preceding_run_widths;
37 Range range;
38 UBiDiDirection direction;
39 UBiDiLevel level;
40 UScriptCode script;
41
42 scoped_ptr<uint16[]> glyphs;
43 scoped_ptr<SkPoint[]> positions;
44 scoped_ptr<uint32[]> glyph_to_char;
45 size_t glyph_count;
46
47 skia::RefPtr<SkTypeface> skia_face;
48 int font_size;
49 int font_style;
50 bool strike;
51 bool diagonal_strike;
52 bool underline;
53
54 private:
55 DISALLOW_COPY_AND_ASSIGN(TextRunHarfBuzz);
56 };
57
58 } // namespace internal
59
60 class RenderTextHarfBuzz : public RenderText {
61 public:
62 RenderTextHarfBuzz();
63 virtual ~RenderTextHarfBuzz();
64
65 // Overridden from RenderText.
66 virtual Size GetStringSize() OVERRIDE;
67 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
68 virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE;
69
70 protected:
71 // Overridden from RenderText.
72 virtual int GetLayoutTextBaseline() OVERRIDE;
73 virtual SelectionModel AdjacentCharSelectionModel(
74 const SelectionModel& selection,
75 VisualCursorDirection direction) OVERRIDE;
76 virtual SelectionModel AdjacentWordSelectionModel(
77 const SelectionModel& selection,
78 VisualCursorDirection direction) OVERRIDE;
79 virtual Range GetGlyphBounds(size_t index) OVERRIDE;
80 virtual std::vector<Rect> GetSubstringBounds(const Range& range) OVERRIDE;
81 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE;
82 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE;
83 virtual bool IsValidCursorIndex(size_t index) OVERRIDE;
84 virtual void ResetLayout() OVERRIDE;
85 virtual void EnsureLayout() OVERRIDE;
86 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
87
88 private:
89 // Return the run index that contains the argument; or the length of the
90 // |runs_| vector if argument exceeds the text length or width.
91 size_t GetRunContainingCaret(const SelectionModel& caret) const;
92 size_t GetRunContainingXCoord(int x, int* offset) const;
93
94 // Returns the X coordinate of the leading or |trailing| edge of the glyph
95 // starting at |index|, relative to the left of the text (not the view).
96 int GetGlyphXBoundary(size_t run_index, size_t text_index, bool trailing);
97
98 // Given a |run|, returns the SelectionModel that contains the logical first
99 // or last caret position inside (not at a boundary of) the run.
100 // The returned value represents a cursor/caret position without a selection.
101 SelectionModel RenderTextHarfBuzz::FirstSelectionModelInsideRun(
102 const internal::TextRunHarfBuzz* run);
103 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun(
104 const internal::TextRunHarfBuzz* run);
105
106 // Break the text into logical runs and populate the visual <-> logical maps.
107 void ItemizeText();
108
109 // Shape the glyphs needed for the text |run|.
110 void ShapeRun(internal::TextRunHarfBuzz* run);
111
112 // Text runs in logical order.
113 ScopedVector<internal::TextRunHarfBuzz> runs_;
114
115 // Maps visual run indices to logical run indices and vice versa.
116 std::vector<int32_t> visual_to_logical_;
117 std::vector<int32_t> logical_to_visual_;
118
119 bool needs_layout_;
120
121 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz);
122 };
123
124 } // namespace gfx
125
126 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698