Scaling feature for fixed-size fonts
[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   unsigned int 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] actualSize 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& actualSize );
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,out] glyphPositions The positions of all the glyphs.
174    */
175   void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
176                                  Vector<Vector2>& glyphPositions );
177
178   /**
179    * @brief Aligns the laid out lines.
180    *
181    * @param[in] layoutSize The size of the laid out the text.
182    * @param[in,out] lines The laid-out lines.
183    */
184   void Align( const Size& layoutSize,
185               Vector<LineRun>& lines );
186
187 private:
188
189   // Undefined
190   LayoutEngine( const LayoutEngine& handle );
191
192   // Undefined
193   LayoutEngine& operator=( const LayoutEngine& handle );
194
195 private:
196
197   struct Impl;
198   Impl* mImpl;
199 };
200 } // namespace Text
201
202 } // namespace Toolkit
203
204 } // namespace Dali
205
206 #endif // __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__