OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_WIN_H_ | |
6 #define UI_GFX_RENDER_TEXT_WIN_H_ | |
7 | |
8 #include <usp10.h> | |
9 | |
10 #include <map> | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/scoped_vector.h" | |
16 #include "ui/gfx/render_text.h" | |
17 | |
18 namespace gfx { | |
19 | |
20 namespace internal { | |
21 | |
22 struct TextRun { | |
23 TextRun(); | |
24 ~TextRun(); | |
25 | |
26 Range range; | |
27 Font font; | |
28 // A gfx::Font::FontStyle flag to specify bold and italic styles. | |
29 // Supersedes |font.GetFontStyle()|. Stored separately to avoid calling | |
30 // |font.DeriveFont()|, which is expensive on Windows. | |
31 int font_style; | |
32 | |
33 bool strike; | |
34 bool diagonal_strike; | |
35 bool underline; | |
36 | |
37 int width; | |
38 // The cumulative widths of preceding runs. | |
39 int preceding_run_widths; | |
40 | |
41 SCRIPT_ANALYSIS script_analysis; | |
42 | |
43 scoped_ptr<WORD[]> glyphs; | |
44 scoped_ptr<WORD[]> logical_clusters; | |
45 scoped_ptr<SCRIPT_VISATTR[]> visible_attributes; | |
46 int glyph_count; | |
47 | |
48 scoped_ptr<int[]> advance_widths; | |
49 scoped_ptr<GOFFSET[]> offsets; | |
50 ABC abc_widths; | |
51 SCRIPT_CACHE script_cache; | |
52 | |
53 private: | |
54 DISALLOW_COPY_AND_ASSIGN(TextRun); | |
55 }; | |
56 | |
57 } // namespace internal | |
58 | |
59 // RenderTextWin is the Windows implementation of RenderText using Uniscribe. | |
60 class RenderTextWin : public RenderText { | |
61 public: | |
62 RenderTextWin(); | |
63 virtual ~RenderTextWin(); | |
64 | |
65 // Overridden from RenderText: | |
66 virtual scoped_ptr<RenderText> CreateInstanceOfSameType() const override; | |
67 virtual Size GetStringSize() override; | |
68 virtual SelectionModel FindCursorPosition(const Point& point) override; | |
69 virtual std::vector<FontSpan> GetFontSpansForTesting() override; | |
70 | |
71 protected: | |
72 // Overridden from RenderText: | |
73 virtual int GetLayoutTextBaseline() override; | |
74 virtual SelectionModel AdjacentCharSelectionModel( | |
75 const SelectionModel& selection, | |
76 VisualCursorDirection direction) override; | |
77 virtual SelectionModel AdjacentWordSelectionModel( | |
78 const SelectionModel& selection, | |
79 VisualCursorDirection direction) override; | |
80 virtual Range GetGlyphBounds(size_t index) override; | |
81 virtual std::vector<Rect> GetSubstringBounds(const Range& range) override; | |
82 virtual size_t TextIndexToLayoutIndex(size_t index) const override; | |
83 virtual size_t LayoutIndexToTextIndex(size_t index) const override; | |
84 virtual bool IsValidCursorIndex(size_t index) override; | |
85 virtual void ResetLayout() override; | |
86 virtual void EnsureLayout() override; | |
87 virtual void DrawVisualText(Canvas* canvas) override; | |
88 | |
89 private: | |
90 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Win_BreakRunsByUnicodeBlocks); | |
91 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Win_LogicalClusters); | |
92 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); | |
93 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); | |
94 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, BreakRunsByUnicodeBlocks); | |
95 | |
96 void ItemizeLogicalText(); | |
97 void LayoutVisualText(); | |
98 void LayoutTextRun(internal::TextRun* run); | |
99 | |
100 // Helper function that calls |ScriptShape()| on the run, which has logic to | |
101 // handle E_OUTOFMEMORY return codes. | |
102 HRESULT ShapeTextRunWithFont(internal::TextRun* run, const Font& font); | |
103 | |
104 // Returns the number of characters in |run| that have missing glyphs. | |
105 int CountCharsWithMissingGlyphs(internal::TextRun* run, | |
106 HRESULT shaping_result) const; | |
107 | |
108 // Return the run index that contains the argument; or the length of the | |
109 // |runs_| vector if argument exceeds the text length or width. | |
110 size_t GetRunContainingCaret(const SelectionModel& caret) const; | |
111 size_t GetRunContainingXCoord(int x) const; | |
112 | |
113 // Given a |run|, returns the SelectionModel that contains the logical first | |
114 // or last caret position inside (not at a boundary of) the run. | |
115 // The returned value represents a cursor/caret position without a selection. | |
116 SelectionModel FirstSelectionModelInsideRun(const internal::TextRun* run); | |
117 SelectionModel LastSelectionModelInsideRun(const internal::TextRun* run); | |
118 | |
119 // Cached HDC for performing Uniscribe API calls. | |
120 static HDC cached_hdc_; | |
121 | |
122 // Cached map from font name to the last successful substitute font used. | |
123 // TODO(asvitkine): Move the caching logic to font_fallback_win.cc. | |
124 static std::map<std::string, Font> successful_substitute_fonts_; | |
125 | |
126 SCRIPT_CONTROL script_control_; | |
127 SCRIPT_STATE script_state_; | |
128 | |
129 ScopedVector<internal::TextRun> runs_; | |
130 | |
131 // Single line width of the layout text. | |
132 int string_width_; | |
133 | |
134 // Wrapped multiline size of the layout text. | |
135 Size multiline_string_size_; | |
136 | |
137 scoped_ptr<int[]> visual_to_logical_; | |
138 scoped_ptr<int[]> logical_to_visual_; | |
139 | |
140 bool needs_layout_; | |
141 | |
142 DISALLOW_COPY_AND_ASSIGN(RenderTextWin); | |
143 }; | |
144 | |
145 } // namespace gfx | |
146 | |
147 #endif // UI_GFX_RENDER_TEXT_WIN_H_ | |
OLD | NEW |