Merge "Change LayoutItem::SetParent to set LayoutItem::Impl::PRIVATE_FLAG_FORCE_SET_F...
[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) 2016 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 #include <dali/public-api/actors/actor-enumerations.h>
25
26 // INTERNAL INCLUDE
27 #include <dali-toolkit/public-api/text/text-enumerations.h>
28 #include <dali-toolkit/internal/text/line-run.h>
29 #include <dali-toolkit/internal/text/metrics.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Text
38 {
39
40 namespace Layout
41 {
42
43 struct Parameters;
44
45 /**
46  * @brief LayoutEngine is responsible for calculating the visual position of glyphs in layout.
47  */
48 class Engine
49 {
50 public:
51
52   enum Type
53   {
54     SINGLE_LINE_BOX,
55     MULTI_LINE_BOX
56   };
57
58   /**
59    * @brief Create a new instance of a LayoutEngine.
60    */
61   Engine();
62
63   /**
64    * @brief Virtual destructor.
65    */
66   ~Engine();
67
68   /**
69    * @brief Provide the wrapper around FontClient used to get metrics
70    *
71    * @param[in] metrics Used to get metrics
72    */
73   void SetMetrics( MetricsPtr& metrics );
74
75   /**
76    * @brief Choose the required layout.
77    *
78    * @param[in] layout The required layout.
79    */
80   void SetLayout( Type layout );
81
82   /**
83    * @brief Query the required layout.
84    *
85    * @return The required layout.
86    */
87   Type GetLayout() const;
88
89   /**
90    * @brief Sets the width of the cursor.
91    *
92    * @param[in] width The width of the cursor in pixels.
93    */
94   void SetCursorWidth( int width );
95
96   /**
97    * @brief Retrieves the width of the cursor.
98    *
99    * @return The width of the cursor in pixels.
100    */
101   int GetCursorWidth() const;
102
103   /**
104    * @brief Store the visual position of glyphs in the VisualModel.
105    *
106    * @param[in] layoutParameters The parameters needed to layout the text.
107    * @param[out] glyphPositions The positions of all the glyphs.
108    * @param[out] lines The laid-out lines.
109    * @param[out] layoutSize The size of the text after it has been laid-out.
110    * @param[in] elideTextEnabled Whether the text elide is enabled.
111    *
112    * @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.
113    */
114   bool LayoutText( const Parameters& layoutParameters,
115                    Vector<Vector2>& glyphPositions,
116                    Vector<LineRun>& lines,
117                    Size& layoutSize,
118                    bool elideTextEnabled );
119
120   /**
121    * @brief Re-lays out those lines with right to left characters.
122    *
123    * It doesn't change the phisical position of the glyphs in the model but sets their new position.
124    *
125    * @param[in] layoutParameters The parameters needed to layout the text.
126    * @param[in] startIndex Character index of the line from where the lines are reordered.
127    * @param[in] numberOfCharacters The number of characters.
128    * @param[in,out] glyphPositions The positions of all the glyphs.
129    */
130   void ReLayoutRightToLeftLines( const Parameters& layoutParameters,
131                                  CharacterIndex startIndex,
132                                  Length numberOfCharacters,
133                                  Vector<Vector2>& glyphPositions );
134
135   /**
136    * @brief Aligns the laid out lines.
137    *
138    * @param[in] size The size of the container where the text is laid-out.
139    * @param[in] startIndex Character index of the line from where the lines are aligned.
140    * @param[in] numberOfCharacters The number of characters.
141    * @param[in] horizontalAlignment The horizontal alignment.
142    * @param[in,out] lines The laid-out lines.
143    * @param[out] alignmentOffset The alignment offset.
144    * @param[in] layoutDirection The direction of the system language.
145    * @param[in] matchSystemLanguageDirection Whether match align for system language direction or not.
146    */
147   void Align( const Size& size,
148               CharacterIndex startIndex,
149               Length numberOfCharacters,
150               Text::HorizontalAlignment::Type horizontalAlignment,
151               Vector<LineRun>& lines,
152               float& alignmentOffset,
153               Dali::LayoutDirection::Type layoutDirection,
154               bool matchSystemLanguageDirection );
155
156   /**
157    * @brief Sets the default line spacing.
158    *
159    * @param[in] lineSpacing The line spacing.
160    */
161   void SetDefaultLineSpacing( float lineSpacing );
162
163   /**
164    * @brief Retrieves the default line spacing.
165    *
166    * @return The line spacing.
167    */
168   float GetDefaultLineSpacing() const;
169
170 private:
171
172   // Undefined
173   Engine( const Engine& handle );
174
175   // Undefined
176   Engine& operator=( const Engine& handle );
177
178 private:
179
180   struct Impl;
181   Impl* mImpl;
182 };
183
184 } // namespace Layout
185
186 } // namespace Text
187
188 } // namespace Toolkit
189
190 } // namespace Dali
191
192 #endif // DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H