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