1 #ifndef __DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_H__
2 #define __DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_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/common/intrusive-ptr.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <dali/public-api/object/ref-object.h>
29 #include <dali-toolkit/internal/text/line-run.h>
30 #include <dali-toolkit/internal/text/color-run.h>
42 typedef IntrusivePtr<VisualModel> VisualModelPtr;
45 * @brief A visual text model contains layout specific information.
48 * - A series of glyphs in visual order i.e. after the bidirectional reordering.
49 * - The position of each glyph within a 2D bounding box.
51 class VisualModel : public RefObject
56 * @brief Create a new instance of a VisualModel.
58 * @return A pointer to a new VisualModel.
60 static VisualModelPtr New();
65 * @brief Creates the character to glyph conversion table.
67 * @pre The glyphs per character table needs to be created first.
69 * @param[in] numberOfCharacters The number of characters.
71 void CreateCharacterToGlyphTable( Length numberOfCharacters = 0u );
74 * @brief Creates an array containing the number of glyphs per character.
76 * @param[in] numberOfCharacters The number of characters.
78 void CreateGlyphsPerCharacterTable( Length numberOfCharacters = 0u );
81 * @brief Retrieves glyphs in the given buffer.
83 * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
84 * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
85 * @param[in] glyphIndex Index to the first glyph.
86 * @param[in] numberOfGlyphs Number of glyphs to be copied.
88 void GetGlyphs( GlyphInfo* glyphs,
89 GlyphIndex glyphIndex,
90 Length numberOfGlyphs ) const;
95 * @brief Retrieves the glyph positions.
97 * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
98 * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
99 * @param[in] glyphIndex Index to the first glyph position.
100 * @param[in] numberOfGlyphs The number of positions to be copied.
102 void GetGlyphPositions( Vector2* glyphPositions,
103 GlyphIndex glyphIndex,
104 Length numberOfGlyphs ) const;
109 * @brief Retrieves the number of lines and the index to the first line where the given range of glyphs is laid out.
111 * @param[in] glyphIndex Index to the first glyph.
112 * @param[in] numberOfGlyphs The number of glyph.
113 * @param[out] firstLine Index to the line containing the glyph index.
114 * @param[out] numberOfLines The number of lines.
116 void GetNumberOfLines( GlyphIndex glyphIndex,
117 Length numberOfGlyphs,
118 LineIndex& firstLine,
119 Length& numberOfLines ) const;
122 * @brief Retrieves the lines where the given range of glyphs is laid out.
124 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
126 * @param[out] lines Pointer to a buffer where the lines are copied.
127 * @param[in] glyphIndex Index to the first glyphs of the range.
128 * @param[in] numberOfGlyphs Number of glyphs in the range.
130 void GetLinesOfGlyphRange( LineRun* lines,
131 GlyphIndex glyphIndex,
132 Length numberOfGlyphs ) const;
135 * @brief Retrieves the line index where the character is laid-out.
137 * @param[in] characterIndex The character's index.
139 * @return The line index.
141 LineIndex GetLineOfCharacter( CharacterIndex characterIndex );
146 * @brief Retrieves the underline runs.
148 * @param[out] underlineRuns Pointer to a buffer where the underline runs are copied.
149 * @param[in] index Index of the first underline run to be copied.
150 * @param[in] numberOfRuns Number of underline runs to be copied.
152 void GetUnderlineRuns( GlyphRun* underlineRuns,
153 UnderlineRunIndex index,
154 Length numberOfRuns ) const;
159 * @brief Sets the natural size.
161 * @param[in] size The text's natural size.
163 void SetNaturalSize( const Vector2& size );
166 * @brief Retrieves the natural size.
168 * @return The text's natural size.
170 const Vector2& GetNaturalSize() const;
173 * @brief Sets the text's actual size after it has been laid out.
175 * @param[in] size The text's size.
177 void SetActualSize( const Vector2& size );
180 * @brief Retrieves the text's actual size after it has been laid out.
182 * @return The text's size.
184 const Vector2& GetActualSize() const;
187 * @brief Set the text's color
189 * @param[in] textColor The text's color
191 void SetTextColor( const Vector4& textColor );
194 * @brief Retrieve the text's color
196 * @return The text's color
198 const Vector4& GetTextColor() const;
201 * @brief Sets the text's shadow offset.
203 * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
205 void SetShadowOffset( const Vector2& shadowOffset );
208 * @brief Retrieves the text's shadow offset.
210 * @return The text's shadow offset, 0,0 indicates no shadow.
212 const Vector2& GetShadowOffset() const;
215 * @brief Sets the text's shadow color.
217 * @param[in] shadowColor The shadow color.
219 void SetShadowColor( const Vector4& shadowColor );
222 * @brief Retrieves the text's shadow color.
224 * @return The text's shadow color.
226 const Vector4& GetShadowColor() const;
229 * @brief Sets the text's underline color.
231 * @param[in] color The text's underline color.
233 void SetUnderlineColor( const Vector4& color );
236 * @brief Retrieves the text's underline color.
238 * @return The text's underline color.
240 const Vector4& GetUnderlineColor() const;
243 * @brief Sets the text underline flag.
245 * @param[in] enabled true if underlined.
247 void SetUnderlineEnabled( bool enabled );
250 * @brief Returns whether the text is underlined or not.
252 * @return underline state.
254 bool IsUnderlineEnabled() const;
257 * @brief Clear the caches.
262 * @brief Set the override used for underline height, 0 indicates height will be come from font metrics
264 * @param[in] height The height in pixels of the underline
266 void SetUnderlineHeight( float height );
269 * @brief Retrieves the underline height override
271 * @return Returns the override height for an underline, 0 indicates that font metrics will determine the height
273 float GetUnderlineHeight() const;
278 * @brief A reference counted object may only be deleted by calling Unreference().
280 virtual ~VisualModel();
285 * @brief Private constructor.
290 VisualModel( const VisualModel& handle );
293 VisualModel& operator=( const VisualModel& handle );
297 Vector<GlyphInfo> mGlyphs; ///< For each glyph, the font's id, glyph's index within the font and glyph's metrics.
298 Vector<CharacterIndex> mGlyphsToCharacters; ///< For each glyph, the index of the first character.
299 Vector<GlyphIndex> mCharactersToGlyph; ///< For each character, the index of the first glyph.
300 Vector<Length> mCharactersPerGlyph; ///< For each glyph, the number of characters that form the glyph.
301 Vector<Length> mGlyphsPerCharacter; ///< For each character, the number of glyphs that are shaped.
302 Vector<Vector2> mGlyphPositions; ///< For each glyph, the position.
303 Vector<LineRun> mLines; ///< The laid out lines.
304 Vector<GlyphRun> mUnderlineRuns; ///< Runs of glyphs that are underlined.
305 Vector<ColorGlyphRun> mColorRuns; ///< Runs of glyphs with the same color.
307 Vector2 mControlSize; ///< The size of the UI control the decorator is adding it's decorations to.
308 Vector4 mTextColor; ///< The text color
309 Vector4 mShadowColor; ///< Color of drop shadow
310 Vector4 mUnderlineColor; ///< Color of underline
311 Vector2 mShadowOffset; ///< Offset for drop shadow, 0 indicates no shadow
312 float mUnderlineHeight; ///< Fixed height for underline to override font metrics.
316 Size mNaturalSize; ///< Size of the text with no line wrapping.
317 Size mActualSize; ///< Size of the laid-out text considering the layout properties set.
319 // Caches to increase performance in some consecutive operations.
320 LineIndex mCachedLineIndex; ///< Used to increase performance in consecutive calls to GetLineOfGlyph() or GetLineOfCharacter() with consecutive glyphs or characters.
324 bool mUnderlineEnabled:1; ///< Underline enabled flag
325 bool mUnderlineColorSet:1; ///< Has the underline color been explicitly set?
331 } // namespace Toolkit
335 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_H__