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.
5 #ifndef UI_GFX_RENDER_TEXT_WIN_H_
6 #define UI_GFX_RENDER_TEXT_WIN_H_
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "ui/gfx/render_text.h"
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.
38 // The cumulative widths of preceding runs.
39 int preceding_run_widths
;
41 SCRIPT_ANALYSIS script_analysis
;
43 scoped_ptr
<WORD
[]> glyphs
;
44 scoped_ptr
<WORD
[]> logical_clusters
;
45 scoped_ptr
<SCRIPT_VISATTR
[]> visible_attributes
;
48 scoped_ptr
<int[]> advance_widths
;
49 scoped_ptr
<GOFFSET
[]> offsets
;
51 SCRIPT_CACHE script_cache
;
54 DISALLOW_COPY_AND_ASSIGN(TextRun
);
57 } // namespace internal
59 // RenderTextWin is the Windows implementation of RenderText using Uniscribe.
60 class RenderTextWin
: public RenderText
{
63 virtual ~RenderTextWin();
65 // Overridden from RenderText:
66 virtual Size
GetStringSize() OVERRIDE
;
67 virtual SelectionModel
FindCursorPosition(const Point
& point
) OVERRIDE
;
68 virtual std::vector
<FontSpan
> GetFontSpansForTesting() OVERRIDE
;
71 // Overridden from RenderText:
72 virtual int GetLayoutTextBaseline() OVERRIDE
;
73 virtual SelectionModel
AdjacentCharSelectionModel(
74 const SelectionModel
& selection
,
75 VisualCursorDirection direction
) OVERRIDE
;
76 virtual SelectionModel
AdjacentWordSelectionModel(
77 const SelectionModel
& selection
,
78 VisualCursorDirection direction
) OVERRIDE
;
79 virtual Range
GetGlyphBounds(size_t index
) OVERRIDE
;
80 virtual std::vector
<Rect
> GetSubstringBounds(const Range
& range
) OVERRIDE
;
81 virtual size_t TextIndexToLayoutIndex(size_t index
) const OVERRIDE
;
82 virtual size_t LayoutIndexToTextIndex(size_t index
) const OVERRIDE
;
83 virtual bool IsValidCursorIndex(size_t index
) OVERRIDE
;
84 virtual void ResetLayout() OVERRIDE
;
85 virtual void EnsureLayout() OVERRIDE
;
86 virtual void DrawVisualText(Canvas
* canvas
) OVERRIDE
;
89 FRIEND_TEST_ALL_PREFIXES(RenderTextTest
, Win_BreakRunsByUnicodeBlocks
);
90 FRIEND_TEST_ALL_PREFIXES(RenderTextTest
, Win_LogicalClusters
);
91 FRIEND_TEST_ALL_PREFIXES(RenderTextTest
, Multiline_MinWidth
);
92 FRIEND_TEST_ALL_PREFIXES(RenderTextTest
, Multiline_NormalWidth
);
94 void ItemizeLogicalText();
95 void LayoutVisualText();
96 void LayoutTextRun(internal::TextRun
* run
);
98 // Helper function that calls |ScriptShape()| on the run, which has logic to
99 // handle E_OUTOFMEMORY return codes.
100 HRESULT
ShapeTextRunWithFont(internal::TextRun
* run
, const Font
& font
);
102 // Returns the number of characters in |run| that have missing glyphs.
103 int CountCharsWithMissingGlyphs(internal::TextRun
* run
,
104 HRESULT shaping_result
) const;
106 // Return the run index that contains the argument; or the length of the
107 // |runs_| vector if argument exceeds the text length or width.
108 size_t GetRunContainingCaret(const SelectionModel
& caret
) const;
109 size_t GetRunContainingXCoord(int x
) const;
111 // Given a |run|, returns the SelectionModel that contains the logical first
112 // or last caret position inside (not at a boundary of) the run.
113 // The returned value represents a cursor/caret position without a selection.
114 SelectionModel
FirstSelectionModelInsideRun(const internal::TextRun
* run
);
115 SelectionModel
LastSelectionModelInsideRun(const internal::TextRun
* run
);
117 // Cached HDC for performing Uniscribe API calls.
118 static HDC cached_hdc_
;
120 // Cached map from font name to the last successful substitute font used.
121 // TODO(asvitkine): Move the caching logic to font_fallback_win.cc.
122 static std::map
<std::string
, Font
> successful_substitute_fonts_
;
124 SCRIPT_CONTROL script_control_
;
125 SCRIPT_STATE script_state_
;
127 ScopedVector
<internal::TextRun
> runs_
;
129 // Single line width of the layout text.
132 // Wrapped multiline size of the layout text.
133 Size multiline_string_size_
;
135 scoped_ptr
<int[]> visual_to_logical_
;
136 scoped_ptr
<int[]> logical_to_visual_
;
140 DISALLOW_COPY_AND_ASSIGN(RenderTextWin
);
145 #endif // UI_GFX_RENDER_TEXT_WIN_H_