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