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_PANGO_H_
6 #define UI_GFX_RENDER_TEXT_PANGO_H_
8 #include <pango/pango.h>
11 #include "ui/gfx/render_text.h"
15 // RenderTextPango is the Linux implementation of RenderText using Pango.
16 class RenderTextPango
: public RenderText
{
19 virtual ~RenderTextPango();
21 // Overridden from RenderText:
22 virtual Size
GetStringSize() OVERRIDE
;
23 virtual SelectionModel
FindCursorPosition(const Point
& point
) OVERRIDE
;
24 virtual std::vector
<FontSpan
> GetFontSpansForTesting() OVERRIDE
;
27 // Overridden from RenderText:
28 virtual int GetLayoutTextBaseline() OVERRIDE
;
29 virtual SelectionModel
AdjacentCharSelectionModel(
30 const SelectionModel
& selection
,
31 VisualCursorDirection direction
) OVERRIDE
;
32 virtual SelectionModel
AdjacentWordSelectionModel(
33 const SelectionModel
& selection
,
34 VisualCursorDirection direction
) OVERRIDE
;
35 virtual Range
GetGlyphBounds(size_t index
) OVERRIDE
;
36 virtual std::vector
<Rect
> GetSubstringBounds(const Range
& range
) OVERRIDE
;
37 virtual size_t TextIndexToLayoutIndex(size_t index
) const OVERRIDE
;
38 virtual size_t LayoutIndexToTextIndex(size_t index
) const OVERRIDE
;
39 virtual bool IsValidCursorIndex(size_t index
) OVERRIDE
;
40 virtual void ResetLayout() OVERRIDE
;
41 virtual void EnsureLayout() OVERRIDE
;
42 virtual void DrawVisualText(Canvas
* canvas
) OVERRIDE
;
45 friend class RenderTextTest
;
46 FRIEND_TEST_ALL_PREFIXES(RenderTextTest
, PangoAttributes
);
48 // Returns the run that contains the character attached to the caret in the
49 // given selection model. Return NULL if not found.
50 GSList
* GetRunContainingCaret(const SelectionModel
& caret
) const;
52 // Given a |run|, returns the SelectionModel that contains the logical first
53 // or last caret position inside (not at a boundary of) the run.
54 // The returned value represents a cursor/caret position without a selection.
55 SelectionModel
FirstSelectionModelInsideRun(const PangoItem
* run
);
56 SelectionModel
LastSelectionModelInsideRun(const PangoItem
* run
);
58 // Setup pango attribute: foreground, background, font, strike.
59 void SetupPangoAttributes(PangoLayout
* layout
);
61 // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
62 void AppendPangoAttribute(size_t start
,
64 PangoAttribute
* pango_attr
,
65 PangoAttrList
* attrs
);
67 // Get the text index corresponding to the |run|'s |glyph_index|.
68 size_t GetGlyphTextIndex(PangoLayoutRun
* run
, int glyph_index
) const;
72 // A single line layout resulting from laying out via |layout_|.
73 PangoLayoutLine
* current_line_
;
75 // Information about character attributes.
76 PangoLogAttr
* log_attrs_
;
77 // Number of attributes in |log_attrs_|.
80 // The text in the |layout_|.
81 const char* layout_text_
;
83 DISALLOW_COPY_AND_ASSIGN(RenderTextPango
);
88 #endif // UI_GFX_RENDER_TEXT_PANGO_H_