| 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 { |
| 16 namespace i18n { |
| 17 class BreakIterator; |
| 18 } |
| 19 } |
| 20 |
| 15 namespace gfx { | 21 namespace gfx { |
| 16 | 22 |
| 17 namespace internal { | 23 namespace internal { |
| 18 | 24 |
| 19 struct GFX_EXPORT TextRunHarfBuzz { | 25 struct GFX_EXPORT TextRunHarfBuzz { |
| 20 TextRunHarfBuzz(); | 26 TextRunHarfBuzz(); |
| 21 ~TextRunHarfBuzz(); | 27 ~TextRunHarfBuzz(); |
| 22 | 28 |
| 23 // Returns the index of the first glyph that corresponds to the character at | 29 // Returns the index of the first glyph that corresponds to the character at |
| 24 // |pos|. | 30 // |pos|. |
| 25 size_t CharToGlyph(size_t pos) const; | 31 size_t CharToGlyph(size_t pos) const; |
| 26 | 32 |
| 27 // Returns the corresponding glyph range of the given character range. | 33 // Returns the corresponding glyph range of the given character range. |
| 28 // |range| is in text-space (0 corresponds to |GetLayoutText()[0]|). Returned | 34 // |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). | 35 // value is in run-space (0 corresponds to the first glyph in the run). |
| 30 Range CharRangeToGlyphRange(const Range& range) const; | 36 Range CharRangeToGlyphRange(const Range& range) const; |
| 31 | 37 |
| 32 // Returns the number of missing glyphs in the shaped text run. | 38 // Returns the number of missing glyphs in the shaped text run. |
| 33 size_t CountMissingGlyphs() const; | 39 size_t CountMissingGlyphs() const; |
| 34 | 40 |
| 35 // Returns the X coordinate of the leading or |trailing| edge of the glyph | 41 // Writes the character and glyph ranges of the cluster containing |pos|. |
| 36 // starting at |text_index|, relative to the left of the text (not the view). | 42 void GetClusterAt(size_t pos, Range* chars, Range* glyphs) const; |
| 37 int GetGlyphXBoundary(size_t text_index, bool trailing) const; | 43 |
| 44 // Returns the grapheme bounds at |text_index|. Handles multi-grapheme glyphs. |
| 45 Range GetGraphemeBounds(base::i18n::BreakIterator* grapheme_iterator, |
| 46 size_t text_index); |
| 47 |
| 48 // Returns whether the given shaped run contains any missing glyphs. |
| 49 bool HasMissingGlyphs() const; |
| 38 | 50 |
| 39 int width; | 51 int width; |
| 40 int preceding_run_widths; | 52 int preceding_run_widths; |
| 41 Range range; | 53 Range range; |
| 42 bool is_rtl; | 54 bool is_rtl; |
| 43 UBiDiLevel level; | 55 UBiDiLevel level; |
| 44 UScriptCode script; | 56 UScriptCode script; |
| 45 | 57 |
| 46 scoped_ptr<uint16[]> glyphs; | 58 scoped_ptr<uint16[]> glyphs; |
| 47 scoped_ptr<SkPoint[]> positions; | 59 scoped_ptr<SkPoint[]> positions; |
| 48 scoped_ptr<uint32[]> glyph_to_char; | 60 std::vector<uint32> glyph_to_char; |
| 49 size_t glyph_count; | 61 size_t glyph_count; |
| 50 | 62 |
| 51 skia::RefPtr<SkTypeface> skia_face; | 63 skia::RefPtr<SkTypeface> skia_face; |
| 52 int font_size; | 64 int font_size; |
| 53 int font_style; | 65 int font_style; |
| 54 bool strike; | 66 bool strike; |
| 55 bool diagonal_strike; | 67 bool diagonal_strike; |
| 56 bool underline; | 68 bool underline; |
| 57 | 69 |
| 58 private: | 70 private: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 86 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE; | 98 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE; |
| 87 virtual bool IsValidCursorIndex(size_t index) OVERRIDE; | 99 virtual bool IsValidCursorIndex(size_t index) OVERRIDE; |
| 88 virtual void ResetLayout() OVERRIDE; | 100 virtual void ResetLayout() OVERRIDE; |
| 89 virtual void EnsureLayout() OVERRIDE; | 101 virtual void EnsureLayout() OVERRIDE; |
| 90 virtual void DrawVisualText(Canvas* canvas) OVERRIDE; | 102 virtual void DrawVisualText(Canvas* canvas) OVERRIDE; |
| 91 | 103 |
| 92 private: | 104 private: |
| 93 friend class RenderTextTest; | 105 friend class RenderTextTest; |
| 94 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_RunDirection); | 106 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_RunDirection); |
| 95 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_BreakRunsByUnicodeBlocks); | 107 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_BreakRunsByUnicodeBlocks); |
| 108 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_SubglyphGraphemeCases); |
| 109 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_SubglyphGraphemePartition); |
| 96 | 110 |
| 97 // Return the run index that contains the argument; or the length of the | 111 // Return the run index that contains the argument; or the length of the |
| 98 // |runs_| vector if argument exceeds the text length or width. | 112 // |runs_| vector if argument exceeds the text length or width. |
| 99 size_t GetRunContainingCaret(const SelectionModel& caret) const; | 113 size_t GetRunContainingCaret(const SelectionModel& caret) const; |
| 100 size_t GetRunContainingXCoord(int x, int* offset) const; | 114 size_t GetRunContainingXCoord(int x, int* offset) const; |
| 101 | 115 |
| 102 // Given a |run|, returns the SelectionModel that contains the logical first | 116 // Given a |run|, returns the SelectionModel that contains the logical first |
| 103 // or last caret position inside (not at a boundary of) the run. | 117 // or last caret position inside (not at a boundary of) the run. |
| 104 // The returned value represents a cursor/caret position without a selection. | 118 // The returned value represents a cursor/caret position without a selection. |
| 105 SelectionModel FirstSelectionModelInsideRun( | 119 SelectionModel FirstSelectionModelInsideRun( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 117 | 131 |
| 118 // Text runs in logical order. | 132 // Text runs in logical order. |
| 119 ScopedVector<internal::TextRunHarfBuzz> runs_; | 133 ScopedVector<internal::TextRunHarfBuzz> runs_; |
| 120 | 134 |
| 121 // Maps visual run indices to logical run indices and vice versa. | 135 // Maps visual run indices to logical run indices and vice versa. |
| 122 std::vector<int32_t> visual_to_logical_; | 136 std::vector<int32_t> visual_to_logical_; |
| 123 std::vector<int32_t> logical_to_visual_; | 137 std::vector<int32_t> logical_to_visual_; |
| 124 | 138 |
| 125 bool needs_layout_; | 139 bool needs_layout_; |
| 126 | 140 |
| 141 // ICU grapheme iterator for the layout text. Valid when |!needs_layout_|. Can |
| 142 // be NULL in case of an error. |
| 143 scoped_ptr<base::i18n::BreakIterator> grapheme_iterator_; |
| 144 |
| 127 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz); | 145 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz); |
| 128 }; | 146 }; |
| 129 | 147 |
| 130 } // namespace gfx | 148 } // namespace gfx |
| 131 | 149 |
| 132 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ | 150 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
| OLD | NEW |