1 #ifndef __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__
2 #define __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/math/vector2.h>
26 #include <dali-toolkit/internal/text/line-run.h>
27 #include <dali-toolkit/internal/text/metrics.h>
38 struct LayoutParameters;
41 * @brief LayoutEngine is responsible for calculating the visual position of glyphs in layout.
53 enum HorizontalAlignment
55 HORIZONTAL_ALIGN_BEGIN,
56 HORIZONTAL_ALIGN_CENTER,
60 enum VerticalAlignment
63 VERTICAL_ALIGN_CENTER,
68 * @brief Create a new instance of a LayoutEngine.
73 * @brief Virtual destructor.
78 * @brief Provide the wrapper around FontClient used to get metrics
80 * @param[in] metrics Used to get metrics
82 void SetMetrics( MetricsPtr& metrics );
85 * @brief Choose the required layout.
87 * @param[in] layout The required layout.
89 void SetLayout( Layout layout );
92 * @brief Query the required layout.
94 * @return The required layout.
96 Layout GetLayout() const;
99 * @brief Enable or disable the text ellipsis.
101 * @param[in] enabled Whether to enable the text ellipsis.
103 void SetTextEllipsisEnabled( bool enabled );
106 * @return Whether the text ellipsis is enabled.
108 bool GetTextEllipsisEnabled() const;
111 * @brief Choose the required text horizontal alignment.
113 * @param[in] alignment The required alignment.
115 void SetHorizontalAlignment( HorizontalAlignment alignment );
118 * @brief Query the required text horizontal alignment.
120 * @return The required alignment.
122 HorizontalAlignment GetHorizontalAlignment() const;
125 * @brief Choose the required text vertical alignment.
127 * @param[in] alignment The required alignment.
129 void SetVerticalAlignment( VerticalAlignment alignment );
132 * @brief Query the required text vertical alignment.
134 * @return The required alignment.
136 VerticalAlignment GetVerticalAlignment() const;
139 * @brief Sets the width of the cursor.
141 * @param[in] width The width of the cursor in pixels.
143 void SetCursorWidth( int width );
146 * @brief Retrieves the width of the cursor.
148 * @return The width of the cursor in pixels.
150 int GetCursorWidth() const;
153 * @brief Store the visual position of glyphs in the VisualModel.
155 * @param[in] layoutParameters The parameters needed to layout the text.
156 * @param[out] glyphPositions The positions of all the glyphs.
157 * @param[out] lines The laid-out lines.
158 * @param[out] layoutSize The size of the text after it has been laid-out.
160 * @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.
162 bool LayoutText( const LayoutParameters& layoutParameters,
163 Vector<Vector2>& glyphPositions,
164 Vector<LineRun>& lines,
168 * @brief Re-lays out those lines with right to left characters.
170 * It doesn't change the phisical position of the glyphs in the model but sets their new position.
172 * @param[in] layoutParameters The parameters needed to layout the text.
173 * @param[in] startIndex Character index of the line from where the lines are reordered.
174 * @param[in] numberOfCharacters The number of characters.
175 * @param[in,out] glyphPositions The positions of all the glyphs.
177 void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
178 CharacterIndex startIndex,
179 Length numberOfCharacters,
180 Vector<Vector2>& glyphPositions );
183 * @brief Aligns the laid out lines.
185 * @param[in] size The size of the container where the text is laid-out.
186 * @param[in] startIndex Character index of the line from where the lines are aligned.
187 * @param[in] numberOfCharacters The number of characters.
188 * @param[in,out] lines The laid-out lines.
190 void Align( const Size& size,
191 CharacterIndex startIndex,
192 Length numberOfCharacters,
193 Vector<LineRun>& lines );
196 * @brief Sets the default line spacing.
198 * @param[in] lineSpacing The line spacing.
200 void SetDefaultLineSpacing( float lineSpacing );
203 * @brief Retrieves the default line spacing.
205 * @return The line spacing.
207 float GetDefaultLineSpacing() const;
212 LayoutEngine( const LayoutEngine& handle );
215 LayoutEngine& operator=( const LayoutEngine& handle );
224 } // namespace Toolkit
228 #endif // __DALI_TOOLKIT_TEXT_LAYOUT_ENGINE_H__