d0f1ab6a0f8680ff95ca75710a4de9751ce9a62c
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / layouts / layout-engine.h
1 #ifndef __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__
2 #define __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDE
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/math/vector2.h>
24
25 // INTERNAL INCLUDE
26 #include <dali-toolkit/internal/text/line-run.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Text
35 {
36
37 struct LayoutParameters;
38
39 /**
40  * @brief LayoutEngine is responsible for calculating the visual position of glyphs in layout.
41  */
42 class LayoutEngine
43 {
44 public:
45
46   enum Layout
47   {
48     SINGLE_LINE_BOX,
49     MULTI_LINE_BOX
50   };
51
52   enum HorizontalAlignment
53   {
54     HORIZONTAL_ALIGN_BEGIN,
55     HORIZONTAL_ALIGN_CENTER,
56     HORIZONTAL_ALIGN_END
57   };
58
59   enum VerticalAlignment
60   {
61     VERTICAL_ALIGN_TOP,
62     VERTICAL_ALIGN_CENTER,
63     VERTICAL_ALIGN_BOTTOM
64   };
65
66   /**
67    * @brief Create a new instance of a LayoutEngine.
68    */
69   LayoutEngine();
70
71   /**
72    * @brief Virtual destructor.
73    */
74   ~LayoutEngine();
75
76   /**
77    * @brief Choose the required layout.
78    *
79    * @param[in] layout The required layout.
80    */
81   void SetLayout( Layout layout );
82
83   /**
84    * @brief Query the required layout.
85    *
86    * @return The required layout.
87    */
88   unsigned int GetLayout() const;
89
90   /**
91    * @brief Enable or disable the text ellipsis.
92    *
93    * @param[in] enabled Whether to enable the text ellipsis.
94    */
95   void SetTextEllipsisEnabled( bool enabled );
96
97   /**
98    * @return Whether the text ellipsis is enabled.
99    */
100   bool GetTextEllipsisEnabled() const;
101
102   /**
103    * @brief Choose the required text horizontal alignment.
104    *
105    * @param[in] alignment The required alignment.
106    */
107   void SetHorizontalAlignment( HorizontalAlignment alignment );
108
109   /**
110    * @brief Query the required text horizontal alignment.
111    *
112    * @return The required alignment.
113    */
114   HorizontalAlignment GetHorizontalAlignment() const;
115
116   /**
117    * @brief Choose the required text vertical alignment.
118    *
119    * @param[in] alignment The required alignment.
120    */
121   void SetVerticalAlignment( VerticalAlignment alignment );
122
123   /**
124    * @brief Query the required text vertical alignment.
125    *
126    * @return The required alignment.
127    */
128   VerticalAlignment GetVerticalAlignment() const;
129
130   /**
131    * @brief Sets the width of the cursor.
132    *
133    * @param[in] width The width of the cursor in pixels.
134    */
135   void SetCursorWidth( int width );
136
137   /**
138    * @brief Retrieves the width of the cursor.
139    *
140    * @return The width of the cursor in pixels.
141    */
142   int GetCursorWidth() const;
143
144   /**
145    * @brief Store the visual position of glyphs in the VisualModel.
146    *
147    * @param[in] layoutParameters The parameters needed to layout the text.
148    * @param[out] glyphPositions The positions of all the glyphs.
149    * @param[out] lines The laid-out lines.
150    * @param[out] actualSize The size of the text after it has been laid-out.
151    *
152    * @return \e true if the text has been re-laid-out. \e false means the given width is too small to layout even a single character.
153    */
154   bool LayoutText( const LayoutParameters& layoutParameters,
155                    Vector<Vector2>& glyphPositions,
156                    Vector<LineRun>& lines,
157                    Size& actualSize );
158
159   /**
160    * @brief Re-lays out those lines with right to left characters.
161    *
162    * It doesn't change the phisical position of the glyphs in the model but sets their new position.
163    *
164    * @param[in] layoutParameters The parameters needed to layout the text.
165    * @param[in,out] glyphPositions The positions of all the glyphs.
166    */
167   void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
168                                  Vector<Vector2>& glyphPositions );
169
170   /**
171    * @brief Aligns the laid out lines.
172    *
173    * @param[in] layoutSize The size of the laid out the text.
174    * @param[in,out] lines The laid-out lines.
175    */
176   void Align( const Size& layoutSize,
177               Vector<LineRun>& lines );
178
179 private:
180
181   // Undefined
182   LayoutEngine( const LayoutEngine& handle );
183
184   // Undefined
185   LayoutEngine& operator=( const LayoutEngine& handle );
186
187 private:
188
189   struct Impl;
190   Impl* mImpl;
191 };
192 } // namespace Text
193
194 } // namespace Toolkit
195
196 } // namespace Dali
197
198 #endif // __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__