[dali_2.3.20] 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] isHiddenInputEnabled if isHiddenInputEnabled is true, hidden input feature is enabled.
112    * @param[in] ellipsisPosition The location of the text ellipsis
113    *
114    * @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.
115    */
116   bool LayoutText(Parameters&                       layoutParameters,
117                   Size&                             layoutSize,
118                   bool                              elideTextEnabled,
119                   bool&                             isAutoScrollEnabled,
120                   bool                              isAutoScrollMaxTextureExceeded,
121                   bool                              isHiddenInputEnabled,
122                   DevelText::EllipsisPosition::Type ellipsisPosition);
123
124   /**
125    * @brief Aligns the laid out lines.
126    *
127    * @param[in] size The size of the container where the text is laid-out.
128    * @param[in] startIndex Character index of the line from where the lines are aligned.
129    * @param[in] numberOfCharacters The number of characters.
130    * @param[in] horizontalAlignment The horizontal alignment.
131    * @param[in,out] lines The laid-out lines.
132    * @param[out] alignmentOffset The alignment offset.
133    * @param[in] layoutDirection The direction of the layout.
134    * @param[in] matchLayoutDirection Whether match align for layout direction or not.
135    */
136   void Align(const Size&                     size,
137              CharacterIndex                  startIndex,
138              Length                          numberOfCharacters,
139              Text::HorizontalAlignment::Type horizontalAlignment,
140              Vector<LineRun>&                lines,
141              float&                          alignmentOffset,
142              Dali::LayoutDirection::Type     layoutDirection,
143              bool                            matchLayoutDirection);
144
145   /**
146    * @brief Sets the default line spacing.
147    *
148    * @param[in] lineSpacing The line spacing.
149    */
150   void SetDefaultLineSpacing(float lineSpacing);
151
152   /**
153    * @brief Retrieves the default line spacing.
154    *
155    * @return The line spacing.
156    */
157   float GetDefaultLineSpacing() const;
158
159   /**
160    * @brief Sets the default line size.
161    *
162    * @param[in] lineSize The line size.
163    */
164   void SetDefaultLineSize(float lineSize);
165
166   /**
167    * @brief Retrieves the default line size.
168    *
169    * @return The line size.
170    */
171   float GetDefaultLineSize() const;
172
173   /**
174    * @brief Sets relative line size to the original line size.
175    *
176    * @param[in] relativeLineSize The relative line size.
177    */
178   void SetRelativeLineSize(float relativeLineSize);
179
180   /**
181    * @brief Retrieves the relative line size.
182    *
183    * @return The relative line size.
184    */
185   float GetRelativeLineSize() const;
186
187 private:
188   // Undefined
189   Engine(const Engine& handle);
190
191   // Undefined
192   Engine& operator=(const Engine& handle);
193
194 private:
195   struct Impl;
196   Impl* mImpl;
197 };
198
199 } // namespace Layout
200
201 } // namespace Text
202
203 } // namespace Toolkit
204
205 } // namespace Dali
206
207 #endif // DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H