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 "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "third_party/harfbuzz-ng/src/hb.h" | 10 #include "third_party/harfbuzz-ng/src/hb.h" |
11 #include "third_party/icu/source/common/unicode/ubidi.h" | 11 #include "third_party/icu/source/common/unicode/ubidi.h" |
12 #include "third_party/icu/source/common/unicode/uscript.h" | 12 #include "third_party/icu/source/common/unicode/uscript.h" |
13 #include "ui/gfx/render_text.h" | 13 #include "ui/gfx/render_text.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 namespace i18n { | 16 namespace i18n { |
17 class BreakIterator; | 17 class BreakIterator; |
18 } | 18 } |
19 } | 19 } |
20 | 20 |
21 namespace gfx { | 21 namespace gfx { |
22 | 22 |
23 namespace internal { | 23 namespace internal { |
24 | 24 |
| 25 // TODO(ckocagil): Make Range a template class and RangeF an instance of it. |
| 26 typedef std::pair<float, float> RangeF; |
| 27 |
| 28 // Applies std::round to the start and end values of the given RangeF. |
| 29 Range GFX_EXPORT RoundRangeF(const RangeF& range_f); |
| 30 |
25 struct GFX_EXPORT TextRunHarfBuzz { | 31 struct GFX_EXPORT TextRunHarfBuzz { |
26 TextRunHarfBuzz(); | 32 TextRunHarfBuzz(); |
27 ~TextRunHarfBuzz(); | 33 ~TextRunHarfBuzz(); |
28 | 34 |
29 // Returns the index of the first glyph that corresponds to the character at | 35 // Returns the index of the first glyph that corresponds to the character at |
30 // |pos|. | 36 // |pos|. |
31 size_t CharToGlyph(size_t pos) const; | 37 size_t CharToGlyph(size_t pos) const; |
32 | 38 |
33 // Returns the corresponding glyph range of the given character range. | 39 // Returns the corresponding glyph range of the given character range. |
34 // |range| is in text-space (0 corresponds to |GetLayoutText()[0]|). Returned | 40 // |range| is in text-space (0 corresponds to |GetLayoutText()[0]|). Returned |
35 // value is in run-space (0 corresponds to the first glyph in the run). | 41 // value is in run-space (0 corresponds to the first glyph in the run). |
36 Range CharRangeToGlyphRange(const Range& range) const; | 42 Range CharRangeToGlyphRange(const Range& range) const; |
37 | 43 |
38 // Returns the number of missing glyphs in the shaped text run. | 44 // Returns the number of missing glyphs in the shaped text run. |
39 size_t CountMissingGlyphs() const; | 45 size_t CountMissingGlyphs() const; |
40 | 46 |
41 // Writes the character and glyph ranges of the cluster containing |pos|. | 47 // Writes the character and glyph ranges of the cluster containing |pos|. |
42 void GetClusterAt(size_t pos, Range* chars, Range* glyphs) const; | 48 void GetClusterAt(size_t pos, Range* chars, Range* glyphs) const; |
43 | 49 |
44 // Returns the grapheme bounds at |text_index|. Handles multi-grapheme glyphs. | 50 // Returns the grapheme bounds at |text_index|. Handles multi-grapheme glyphs. |
45 Range GetGraphemeBounds(base::i18n::BreakIterator* grapheme_iterator, | 51 RangeF GetGraphemeBounds(base::i18n::BreakIterator* grapheme_iterator, |
46 size_t text_index); | 52 size_t text_index); |
47 | 53 |
48 // Returns whether the given shaped run contains any missing glyphs. | 54 // Returns whether the given shaped run contains any missing glyphs. |
49 bool HasMissingGlyphs() const; | 55 bool HasMissingGlyphs() const; |
50 | 56 |
51 float width; | 57 float width; |
52 float preceding_run_widths; | 58 float preceding_run_widths; |
53 Range range; | 59 Range range; |
54 bool is_rtl; | 60 bool is_rtl; |
55 UBiDiLevel level; | 61 UBiDiLevel level; |
56 UScriptCode script; | 62 UScriptCode script; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_RunDirection); | 115 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_RunDirection); |
110 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_BreakRunsByUnicodeBlocks); | 116 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_BreakRunsByUnicodeBlocks); |
111 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_SubglyphGraphemeCases); | 117 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_SubglyphGraphemeCases); |
112 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_SubglyphGraphemePartition); | 118 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_SubglyphGraphemePartition); |
113 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_NonExistentFont); | 119 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_NonExistentFont); |
114 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_UniscribeFallback); | 120 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_UniscribeFallback); |
115 | 121 |
116 // Return the run index that contains the argument; or the length of the | 122 // Return the run index that contains the argument; or the length of the |
117 // |runs_| vector if argument exceeds the text length or width. | 123 // |runs_| vector if argument exceeds the text length or width. |
118 size_t GetRunContainingCaret(const SelectionModel& caret) const; | 124 size_t GetRunContainingCaret(const SelectionModel& caret) const; |
119 size_t GetRunContainingXCoord(int x, int* offset) const; | 125 size_t GetRunContainingXCoord(float x, float* offset) const; |
120 | 126 |
121 // Given a |run|, returns the SelectionModel that contains the logical first | 127 // Given a |run|, returns the SelectionModel that contains the logical first |
122 // or last caret position inside (not at a boundary of) the run. | 128 // or last caret position inside (not at a boundary of) the run. |
123 // The returned value represents a cursor/caret position without a selection. | 129 // The returned value represents a cursor/caret position without a selection. |
124 SelectionModel FirstSelectionModelInsideRun( | 130 SelectionModel FirstSelectionModelInsideRun( |
125 const internal::TextRunHarfBuzz* run); | 131 const internal::TextRunHarfBuzz* run); |
126 SelectionModel LastSelectionModelInsideRun( | 132 SelectionModel LastSelectionModelInsideRun( |
127 const internal::TextRunHarfBuzz* run); | 133 const internal::TextRunHarfBuzz* run); |
128 | 134 |
129 // Break the text into logical runs and populate the visual <-> logical maps. | 135 // Break the text into logical runs and populate the visual <-> logical maps. |
(...skipping 29 matching lines...) Expand all Loading... |
159 // ICU grapheme iterator for the layout text. Valid when |!needs_layout_|. Can | 165 // ICU grapheme iterator for the layout text. Valid when |!needs_layout_|. Can |
160 // be NULL in case of an error. | 166 // be NULL in case of an error. |
161 scoped_ptr<base::i18n::BreakIterator> grapheme_iterator_; | 167 scoped_ptr<base::i18n::BreakIterator> grapheme_iterator_; |
162 | 168 |
163 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz); | 169 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz); |
164 }; | 170 }; |
165 | 171 |
166 } // namespace gfx | 172 } // namespace gfx |
167 | 173 |
168 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ | 174 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
OLD | NEW |