121b2400b4ba08a756866afbca66b17696621094
[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 Store the visual position of glyphs in the VisualModel.
132    *
133    * @param[in] layoutParameters The parameters needed to layout the text.
134    * @param[out] glyphPositions The positions of all the glyphs.
135    * @param[out] lines The laid-out lines.
136    * @param[out] actualSize The size of the text after it has been laid-out.
137    *
138    * @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.
139    */
140   bool LayoutText( const LayoutParameters& layoutParameters,
141                    Vector<Vector2>& glyphPositions,
142                    Vector<LineRun>& lines,
143                    Size& actualSize );
144
145   /**
146    * @brief Re-lays out those lines with right to left characters.
147    *
148    * It doesn't change the phisical position of the glyphs in the model but sets their new position.
149    *
150    * @param[in] layoutParameters The parameters needed to layout the text.
151    * @param[in,out] glyphPositions The positions of all the glyphs.
152    */
153   void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
154                                  Vector<Vector2>& glyphPositions );
155
156   /**
157    * @brief Aligns the laid out lines.
158    *
159    * @param[in] layoutSize The size of the laid out the text.
160    * @param[in,out] lines The laid-out lines.
161    */
162   void Align( const Size& layoutSize,
163               Vector<LineRun>& lines );
164
165 private:
166
167   // Undefined
168   LayoutEngine( const LayoutEngine& handle );
169
170   // Undefined
171   LayoutEngine& operator=( const LayoutEngine& handle );
172
173 private:
174
175   struct Impl;
176   Impl* mImpl;
177 };
178 } // namespace Text
179
180 } // namespace Toolkit
181
182 } // namespace Dali
183
184 #endif // __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__