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