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

Side by Side Diff: ui/gfx/render_text_harfbuzz.h

Issue 351963002: RenderTextHarfBuzz: Allow mid-glyph cursors in multi-grapheme clusters (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed Created 6 years, 4 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
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/i18n/break_iterator.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
10 #include "third_party/harfbuzz-ng/src/hb.h" 11 #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/ubidi.h"
12 #include "third_party/icu/source/common/unicode/uscript.h" 13 #include "third_party/icu/source/common/unicode/uscript.h"
13 #include "ui/gfx/render_text.h" 14 #include "ui/gfx/render_text.h"
14 15
15 namespace gfx { 16 namespace gfx {
16 17
17 namespace internal { 18 namespace internal {
18 19
19 struct GFX_EXPORT TextRunHarfBuzz { 20 struct GFX_EXPORT TextRunHarfBuzz {
20 TextRunHarfBuzz(); 21 TextRunHarfBuzz();
21 ~TextRunHarfBuzz(); 22 ~TextRunHarfBuzz();
22 23
23 // Returns the index of the first glyph that corresponds to the character at 24 // Returns the index of the first glyph that corresponds to the character at
24 // |pos|. 25 // |pos|.
25 size_t CharToGlyph(size_t pos) const; 26 size_t CharToGlyph(size_t pos) const;
26 27
27 // Returns the corresponding glyph range of the given character range. 28 // Returns the corresponding glyph range of the given character range.
28 // |range| is in text-space (0 corresponds to |GetLayoutText()[0]|). Returned 29 // |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 // value is in run-space (0 corresponds to the first glyph in the run).
30 Range CharRangeToGlyphRange(const Range& range) const; 31 Range CharRangeToGlyphRange(const Range& range) const;
31 32
32 // Returns the number of missing glyphs in the shaped text run. 33 // Returns the number of missing glyphs in the shaped text run.
33 size_t CountMissingGlyphs() const; 34 size_t CountMissingGlyphs() const;
34 35
35 // Returns the X coordinate of the leading or |trailing| edge of the glyph 36 // 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). 37 void GetClusterAt(size_t pos, Range* chars, Range* glyphs) const;
37 int GetGlyphXBoundary(size_t text_index, bool trailing) const; 38
39 // Returns the grapheme bounds at |text_index|. Handles multi-grapheme glyphs.
40 Range GetGraphemeBounds(const base::string16& text,
41 base::i18n::BreakIterator* grapheme_iterator,
42 size_t text_index);
43
44 // Returns whether the given shaped run contains any missing glyphs.
45 bool HasMissingGlyphs() const;
38 46
39 int width; 47 int width;
40 int preceding_run_widths; 48 int preceding_run_widths;
41 Range range; 49 Range range;
42 bool is_rtl; 50 bool is_rtl;
43 UBiDiLevel level; 51 UBiDiLevel level;
44 UScriptCode script; 52 UScriptCode script;
45 53
46 scoped_ptr<uint16[]> glyphs; 54 scoped_ptr<uint16[]> glyphs;
47 scoped_ptr<SkPoint[]> positions; 55 scoped_ptr<SkPoint[]> positions;
48 scoped_ptr<uint32[]> glyph_to_char; 56 std::vector<uint32> glyph_to_char;
49 size_t glyph_count; 57 size_t glyph_count;
50 58
51 skia::RefPtr<SkTypeface> skia_face; 59 skia::RefPtr<SkTypeface> skia_face;
52 int font_size; 60 int font_size;
53 int font_style; 61 int font_style;
54 bool strike; 62 bool strike;
55 bool diagonal_strike; 63 bool diagonal_strike;
56 bool underline; 64 bool underline;
57 65
58 private: 66 private:
(...skipping 27 matching lines...) Expand all
86 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE; 94 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE;
87 virtual bool IsValidCursorIndex(size_t index) OVERRIDE; 95 virtual bool IsValidCursorIndex(size_t index) OVERRIDE;
88 virtual void ResetLayout() OVERRIDE; 96 virtual void ResetLayout() OVERRIDE;
89 virtual void EnsureLayout() OVERRIDE; 97 virtual void EnsureLayout() OVERRIDE;
90 virtual void DrawVisualText(Canvas* canvas) OVERRIDE; 98 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
91 99
92 private: 100 private:
93 friend class RenderTextTest; 101 friend class RenderTextTest;
94 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_RunDirection); 102 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_RunDirection);
95 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_BreakRunsByUnicodeBlocks); 103 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_BreakRunsByUnicodeBlocks);
104 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_SubglyphGraphemeCases);
105 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_SubglyphGraphemePartition);
96 106
97 // Return the run index that contains the argument; or the length of the 107 // Return the run index that contains the argument; or the length of the
98 // |runs_| vector if argument exceeds the text length or width. 108 // |runs_| vector if argument exceeds the text length or width.
99 size_t GetRunContainingCaret(const SelectionModel& caret) const; 109 size_t GetRunContainingCaret(const SelectionModel& caret) const;
100 size_t GetRunContainingXCoord(int x, int* offset) const; 110 size_t GetRunContainingXCoord(int x, int* offset) const;
101 111
102 // Given a |run|, returns the SelectionModel that contains the logical first 112 // Given a |run|, returns the SelectionModel that contains the logical first
103 // or last caret position inside (not at a boundary of) the run. 113 // or last caret position inside (not at a boundary of) the run.
104 // The returned value represents a cursor/caret position without a selection. 114 // The returned value represents a cursor/caret position without a selection.
105 SelectionModel FirstSelectionModelInsideRun( 115 SelectionModel FirstSelectionModelInsideRun(
(...skipping 17 matching lines...) Expand all
123 std::vector<int32_t> logical_to_visual_; 133 std::vector<int32_t> logical_to_visual_;
124 134
125 bool needs_layout_; 135 bool needs_layout_;
126 136
127 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz); 137 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzz);
128 }; 138 };
129 139
130 } // namespace gfx 140 } // namespace gfx
131 141
132 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ 142 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698