[dali_2.1.26] Merge branch '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) 2022 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/actors/actor-enumerations.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/public-api/math/vector2.h>
25
26 // INTERNAL INCLUDE
27 #include <dali-toolkit/internal/text/line-run.h>
28 #include <dali-toolkit/internal/text/metrics.h>
29 #include <dali-toolkit/public-api/text/text-enumerations.h>
30
31 //DEVEL INCLUDE
32 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
33
34 namespace Dali
35 {
36 namespace Toolkit
37 {
38 namespace Text
39 {
40 namespace Layout
41 {
42 struct Parameters;
43
44 /**
45  * @brief LayoutEngine is responsible for calculating the visual position of glyphs in layout.
46  */
47 class Engine
48 {
49 public:
50   enum Type
51   {
52     SINGLE_LINE_BOX,
53     MULTI_LINE_BOX
54   };
55
56   /**
57    * @brief Create a new instance of a LayoutEngine.
58    */
59   Engine();
60
61   /**
62    * @brief Virtual destructor.
63    */
64   ~Engine();
65
66   /**
67    * @brief Provide the wrapper around FontClient used to get metrics
68    *
69    * @param[in] metrics Used to get metrics
70    */
71   void SetMetrics(MetricsPtr& metrics);
72
73   /**
74    * @brief Choose the required layout.
75    *
76    * @param[in] layout The required layout.
77    */
78   void SetLayout(Type layout);
79
80   /**
81    * @brief Query the required layout.
82    *
83    * @return The required layout.
84    */
85   Type GetLayout() const;
86
87   /**
88    * @brief Sets the width of the cursor.
89    *
90    * @param[in] width The width of the cursor in pixels.
91    */
92   void SetCursorWidth(int width);
93
94   /**
95    * @brief Retrieves the width of the cursor.
96    *
97    * @return The width of the cursor in pixels.
98    */
99   int GetCursorWidth() const;
100
101   /**
102    * @brief Store the visual position of glyphs in the VisualModel.
103    *
104    * Builds the bidirectional info and reorders RTL lines.
105    *
106    * @param[in,out] layoutParameters The parameters needed to layout the text.
107    * @param[out] layoutSize The size of the text after it has been laid-out.
108    * @param[in] elideTextEnabled Whether the text elide is enabled.
109    * @param[in,out] isAutoScrollEnabled If the isAutoScrollEnabled is true and the height of the text exceeds the boundaries of the control the text is elided and the isAutoScrollEnabled is set to false to disable the autoscroll
110    * @param[in] isAutoScrollMaxTextureExceeded If isAutoScrollMaxTextureExceeded is true, enable ellipsis during auro scroll.
111    * @param[in] ellipsisPosition The location of the text ellipsis
112    *
113    * @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.
114    */
115   bool LayoutText(Parameters&                       layoutParameters,
116                   Size&                             layoutSize,
117                   bool                              elideTextEnabled,
118                   bool&                             isAutoScrollEnabled,
119                   bool                              isAutoScrollMaxTextureExceeded,
120                   DevelText::EllipsisPosition::Type ellipsisPosition);
121
122   /**
123    * @brief Aligns the laid out lines.
124    *
125    * @param[in] size The size of the container where the text is laid-out.
126    * @param[in] startIndex Character index of the line from where the lines are aligned.
127    * @param[in] numberOfCharacters The number of characters.
128    * @param[in] horizontalAlignment The horizontal alignment.
129    * @param[in,out] lines The laid-out lines.
130    * @param[out] alignmentOffset The alignment offset.
131    * @param[in] layoutDirection The direction of the layout.
132    * @param[in] matchLayoutDirection Whether match align for layout direction or not.
133    */
134   void Align(const Size&                     size,
135              CharacterIndex                  startIndex,
136              Length                          numberOfCharacters,
137              Text::HorizontalAlignment::Type horizontalAlignment,
138              Vector<LineRun>&                lines,
139              float&                          alignmentOffset,
140              Dali::LayoutDirection::Type     layoutDirection,
141              bool                            matchLayoutDirection);
142
143   /**
144    * @brief Sets the default line spacing.
145    *
146    * @param[in] lineSpacing The line spacing.
147    */
148   void SetDefaultLineSpacing(float lineSpacing);
149
150   /**
151    * @brief Retrieves the default line spacing.
152    *
153    * @return The line spacing.
154    */
155   float GetDefaultLineSpacing() const;
156
157   /**
158    * @brief Sets the default line size.
159    *
160    * @param[in] lineSize The line size.
161    */
162   void SetDefaultLineSize(float lineSize);
163
164   /**
165    * @brief Retrieves the default line size.
166    *
167    * @return The line size.
168    */
169   float GetDefaultLineSize() const;
170
171   /**
172    * @brief Sets relative line size to the original line size.
173    *
174    * @param[in] relativeLineSize The relative line size.
175    */
176   void SetRelativeLineSize(float relativeLineSize);
177
178   /**
179    * @brief Retrieves the relative line size.
180    *
181    * @return The relative line size.
182    */
183   float GetRelativeLineSize() const;
184
185 private:
186   // Undefined
187   Engine(const Engine& handle);
188
189   // Undefined
190   Engine& operator=(const Engine& handle);
191
192 private:
193   struct Impl;
194   Impl* mImpl;
195 };
196
197 } // namespace Layout
198
199 } // namespace Text
200
201 } // namespace Toolkit
202
203 } // namespace Dali
204
205 #endif // DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H