Merge "Fix for object loader not handling flags correctly." into devel/master
[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 #include <dali-toolkit/internal/text/metrics.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Text
36 {
37
38 struct LayoutParameters;
39
40 /**
41  * @brief LayoutEngine is responsible for calculating the visual position of glyphs in layout.
42  */
43 class LayoutEngine
44 {
45 public:
46
47   enum Layout
48   {
49     SINGLE_LINE_BOX,
50     MULTI_LINE_BOX
51   };
52
53   enum HorizontalAlignment
54   {
55     HORIZONTAL_ALIGN_BEGIN,
56     HORIZONTAL_ALIGN_CENTER,
57     HORIZONTAL_ALIGN_END
58   };
59
60   enum VerticalAlignment
61   {
62     VERTICAL_ALIGN_TOP,
63     VERTICAL_ALIGN_CENTER,
64     VERTICAL_ALIGN_BOTTOM
65   };
66
67   /**
68    * @brief Create a new instance of a LayoutEngine.
69    */
70   LayoutEngine();
71
72   /**
73    * @brief Virtual destructor.
74    */
75   ~LayoutEngine();
76
77   /**
78    * @brief Provide the wrapper around FontClient used to get metrics
79    *
80    * @param[in] metrics Used to get metrics
81    */
82   void SetMetrics( MetricsPtr& metrics );
83
84   /**
85    * @brief Choose the required layout.
86    *
87    * @param[in] layout The required layout.
88    */
89   void SetLayout( Layout layout );
90
91   /**
92    * @brief Query the required layout.
93    *
94    * @return The required layout.
95    */
96   Layout GetLayout() const;
97
98   /**
99    * @brief Enable or disable the text ellipsis.
100    *
101    * @param[in] enabled Whether to enable the text ellipsis.
102    */
103   void SetTextEllipsisEnabled( bool enabled );
104
105   /**
106    * @return Whether the text ellipsis is enabled.
107    */
108   bool GetTextEllipsisEnabled() const;
109
110   /**
111    * @brief Choose the required text horizontal alignment.
112    *
113    * @param[in] alignment The required alignment.
114    */
115   void SetHorizontalAlignment( HorizontalAlignment alignment );
116
117   /**
118    * @brief Query the required text horizontal alignment.
119    *
120    * @return The required alignment.
121    */
122   HorizontalAlignment GetHorizontalAlignment() const;
123
124   /**
125    * @brief Choose the required text vertical alignment.
126    *
127    * @param[in] alignment The required alignment.
128    */
129   void SetVerticalAlignment( VerticalAlignment alignment );
130
131   /**
132    * @brief Query the required text vertical alignment.
133    *
134    * @return The required alignment.
135    */
136   VerticalAlignment GetVerticalAlignment() const;
137
138   /**
139    * @brief Sets the width of the cursor.
140    *
141    * @param[in] width The width of the cursor in pixels.
142    */
143   void SetCursorWidth( int width );
144
145   /**
146    * @brief Retrieves the width of the cursor.
147    *
148    * @return The width of the cursor in pixels.
149    */
150   int GetCursorWidth() const;
151
152   /**
153    * @brief Store the visual position of glyphs in the VisualModel.
154    *
155    * @param[in] layoutParameters The parameters needed to layout the text.
156    * @param[out] glyphPositions The positions of all the glyphs.
157    * @param[out] lines The laid-out lines.
158    * @param[out] layoutSize The size of the text after it has been laid-out.
159    *
160    * @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.
161    */
162   bool LayoutText( const LayoutParameters& layoutParameters,
163                    Vector<Vector2>& glyphPositions,
164                    Vector<LineRun>& lines,
165                    Size& layoutSize );
166
167   /**
168    * @brief Re-lays out those lines with right to left characters.
169    *
170    * It doesn't change the phisical position of the glyphs in the model but sets their new position.
171    *
172    * @param[in] layoutParameters The parameters needed to layout the text.
173    * @param[in] startIndex Character index of the line from where the lines are reordered.
174    * @param[in] numberOfCharacters The number of characters.
175    * @param[in,out] glyphPositions The positions of all the glyphs.
176    */
177   void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
178                                  CharacterIndex startIndex,
179                                  Length numberOfCharacters,
180                                  Vector<Vector2>& glyphPositions );
181
182   /**
183    * @brief Aligns the laid out lines.
184    *
185    * @param[in] size The size of the container where the text is laid-out.
186    * @param[in] startIndex Character index of the line from where the lines are aligned.
187    * @param[in] numberOfCharacters The number of characters.
188    * @param[in,out] lines The laid-out lines.
189    */
190   void Align( const Size& size,
191               CharacterIndex startIndex,
192               Length numberOfCharacters,
193               Vector<LineRun>& lines );
194
195   /**
196    * @brief Sets the default line spacing.
197    *
198    * @param[in] lineSpacing The line spacing.
199    */
200   void SetDefaultLineSpacing( float lineSpacing );
201
202   /**
203    * @brief Retrieves the default line spacing.
204    *
205    * @return The line spacing.
206    */
207   float GetDefaultLineSpacing() const;
208
209 private:
210
211   // Undefined
212   LayoutEngine( const LayoutEngine& handle );
213
214   // Undefined
215   LayoutEngine& operator=( const LayoutEngine& handle );
216
217 private:
218
219   struct Impl;
220   Impl* mImpl;
221 };
222 } // namespace Text
223
224 } // namespace Toolkit
225
226 } // namespace Dali
227
228 #endif // __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__