OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_RENDER_TEXT_HARFBUZZ_H_ | 5 #ifndef UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
6 #define UI_GFX_RENDER_TEXT_HARFBUZZ_H_ | 6 #define UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "third_party/harfbuzz-ng/src/hb.h" | 15 #include "third_party/harfbuzz-ng/src/hb.h" |
16 #include "third_party/icu/source/common/unicode/ubidi.h" | 16 #include "third_party/icu/source/common/unicode/ubidi.h" |
17 #include "third_party/icu/source/common/unicode/uscript.h" | 17 #include "third_party/icu/source/common/unicode/uscript.h" |
18 #include "ui/gfx/render_text.h" | 18 #include "ui/gfx/render_text.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 namespace i18n { | 21 namespace i18n { |
22 class BreakIterator; | 22 class BreakIterator; |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 namespace gfx { | 26 namespace gfx { |
27 | 27 |
28 class Range; | 28 class Range; |
29 class RangeF; | 29 class RangeF; |
| 30 class RenderTextHarfBuzz; |
30 | 31 |
31 namespace internal { | 32 namespace internal { |
32 | 33 |
33 struct GFX_EXPORT TextRunHarfBuzz { | 34 struct GFX_EXPORT TextRunHarfBuzz { |
34 // Construct the run with |template_font| since determining the details of a | 35 // Construct the run with |template_font| since determining the details of a |
35 // default-constructed gfx::Font is expensive, but it will always be replaced. | 36 // default-constructed gfx::Font is expensive, but it will always be replaced. |
36 explicit TextRunHarfBuzz(const Font& template_font); | 37 explicit TextRunHarfBuzz(const Font& template_font); |
37 ~TextRunHarfBuzz(); | 38 ~TextRunHarfBuzz(); |
38 | 39 |
39 // Returns the index of the first glyph that corresponds to the character at | 40 // Returns the index of the first glyph that corresponds to the character at |
40 // |pos|. | 41 // |pos|. |
41 size_t CharToGlyph(size_t pos) const; | 42 size_t CharToGlyph(size_t pos) const; |
42 | 43 |
43 // Returns the corresponding glyph range of the given character range. | 44 // Returns the corresponding glyph range of the given character range. |
44 // |range| is in text-space (0 corresponds to |GetDisplayText()[0]|). Returned | 45 // |range| is in text-space (0 corresponds to |GetDisplayText()[0]|). Returned |
45 // value is in run-space (0 corresponds to the first glyph in the run). | 46 // value is in run-space (0 corresponds to the first glyph in the run). |
46 Range CharRangeToGlyphRange(const Range& range) const; | 47 Range CharRangeToGlyphRange(const Range& range) const; |
47 | 48 |
48 // Returns the number of missing glyphs in the shaped text run. | 49 // Returns the number of missing glyphs in the shaped text run. |
49 size_t CountMissingGlyphs() const; | 50 size_t CountMissingGlyphs() const; |
50 | 51 |
51 // Writes the character and glyph ranges of the cluster containing |pos|. | 52 // Writes the character and glyph ranges of the cluster containing |pos|. |
52 void GetClusterAt(size_t pos, Range* chars, Range* glyphs) const; | 53 void GetClusterAt(size_t pos, Range* chars, Range* glyphs) const; |
53 | 54 |
54 // Returns the grapheme bounds at |text_index|. Handles multi-grapheme glyphs. | 55 // Returns the grapheme bounds at |text_index|. Handles multi-grapheme glyphs. |
55 RangeF GetGraphemeBounds(base::i18n::BreakIterator* grapheme_iterator, | 56 RangeF GetGraphemeBounds(RenderTextHarfBuzz* render_text, size_t text_index); |
56 size_t text_index); | |
57 | 57 |
58 // Returns whether the given shaped run contains any missing glyphs. | 58 // Returns whether the given shaped run contains any missing glyphs. |
59 bool HasMissingGlyphs() const; | 59 bool HasMissingGlyphs() const; |
60 | 60 |
61 // Returns the glyph width for the given character range. |char_range| is in | 61 // Returns the glyph width for the given character range. |char_range| is in |
62 // text-space (0 corresponds to |GetDisplayText()[0]|). | 62 // text-space (0 corresponds to |GetDisplayText()[0]|). |
63 SkScalar GetGlyphWidthForCharRange(const Range& char_range) const; | 63 SkScalar GetGlyphWidthForCharRange(const Range& char_range) const; |
64 | 64 |
65 float width; | 65 float width; |
66 float preceding_run_widths; | 66 float preceding_run_widths; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // RenderText: | 150 // RenderText: |
151 std::unique_ptr<RenderText> CreateInstanceOfSameType() const override; | 151 std::unique_ptr<RenderText> CreateInstanceOfSameType() const override; |
152 bool MultilineSupported() const override; | 152 bool MultilineSupported() const override; |
153 const base::string16& GetDisplayText() override; | 153 const base::string16& GetDisplayText() override; |
154 Size GetStringSize() override; | 154 Size GetStringSize() override; |
155 SizeF GetStringSizeF() override; | 155 SizeF GetStringSizeF() override; |
156 SelectionModel FindCursorPosition(const Point& point) override; | 156 SelectionModel FindCursorPosition(const Point& point) override; |
157 std::vector<FontSpan> GetFontSpansForTesting() override; | 157 std::vector<FontSpan> GetFontSpansForTesting() override; |
158 Range GetGlyphBounds(size_t index) override; | 158 Range GetGlyphBounds(size_t index) override; |
159 | 159 |
| 160 // ICU grapheme iterator for the layout text. Can be null in case of an error. |
| 161 base::i18n::BreakIterator* GetGraphemeIterator(); |
| 162 |
160 protected: | 163 protected: |
161 // RenderText: | 164 // RenderText: |
162 int GetDisplayTextBaseline() override; | 165 int GetDisplayTextBaseline() override; |
163 SelectionModel AdjacentCharSelectionModel( | 166 SelectionModel AdjacentCharSelectionModel( |
164 const SelectionModel& selection, | 167 const SelectionModel& selection, |
165 VisualCursorDirection direction) override; | 168 VisualCursorDirection direction) override; |
166 SelectionModel AdjacentWordSelectionModel( | 169 SelectionModel AdjacentWordSelectionModel( |
167 const SelectionModel& selection, | 170 const SelectionModel& selection, |
168 VisualCursorDirection direction) override; | 171 VisualCursorDirection direction) override; |
169 std::vector<Rect> GetSubstringBounds(const Range& range) override; | 172 std::vector<Rect> GetSubstringBounds(const Range& range) override; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 void ShapeRun(const base::string16& text, | 228 void ShapeRun(const base::string16& text, |
226 internal::TextRunHarfBuzz* run); | 229 internal::TextRunHarfBuzz* run); |
227 bool ShapeRunWithFont(const base::string16& text, | 230 bool ShapeRunWithFont(const base::string16& text, |
228 const Font& font, | 231 const Font& font, |
229 const FontRenderParams& params, | 232 const FontRenderParams& params, |
230 internal::TextRunHarfBuzz* run); | 233 internal::TextRunHarfBuzz* run); |
231 | 234 |
232 // Makes sure that text runs for layout text are shaped. | 235 // Makes sure that text runs for layout text are shaped. |
233 void EnsureLayoutRunList(); | 236 void EnsureLayoutRunList(); |
234 | 237 |
235 // ICU grapheme iterator for the layout text. Can be NULL in case of an error. | |
236 base::i18n::BreakIterator* GetGraphemeIterator(); | |
237 | |
238 // Returns the current run list, |display_run_list_| if the text is | 238 // Returns the current run list, |display_run_list_| if the text is |
239 // elided, or |layout_run_list_| otherwise. | 239 // elided, or |layout_run_list_| otherwise. |
240 internal::TextRunList* GetRunList(); | 240 internal::TextRunList* GetRunList(); |
241 const internal::TextRunList* GetRunList() const; | 241 const internal::TextRunList* GetRunList() const; |
242 | 242 |
243 // Text run list for |layout_text_| and |display_text_|. | 243 // Text run list for |layout_text_| and |display_text_|. |
244 // |display_run_list_| is created only when the text is elided. | 244 // |display_run_list_| is created only when the text is elided. |
245 internal::TextRunList layout_run_list_; | 245 internal::TextRunList layout_run_list_; |
246 std::unique_ptr<internal::TextRunList> display_run_list_; | 246 std::unique_ptr<internal::TextRunList> display_run_list_; |
247 | 247 |
(...skipping 11 matching lines...) Expand all Loading... |
259 | 259 |
260 // Fixed width of glyphs. This should only be set in test environments. | 260 // Fixed width of glyphs. This should only be set in test environments. |
261 float glyph_width_for_test_; | 261 float glyph_width_for_test_; |
262 | 262 |
263 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz); | 263 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz); |
264 }; | 264 }; |
265 | 265 |
266 } // namespace gfx | 266 } // namespace gfx |
267 | 267 |
268 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ | 268 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
OLD | NEW |