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] startIndex The character from where the conversion table is created.
70 * @param[in] startGlyphIndex The glyph from where the conversion table is created.
71 * @param[in] numberOfCharacters The number of characters.
73 void CreateCharacterToGlyphTable( CharacterIndex startIndex,
74 GlyphIndex startGlyphIndex,
75 Length numberOfCharacters );
78 * @brief Creates an array containing the number of glyphs per character.
80 * @param[in] startIndex The character from where the table is created.
81 * @param[in] startGlyphIndex The glyph from where the conversion table is created.
82 * @param[in] numberOfCharacters The number of characters.
84 void CreateGlyphsPerCharacterTable( CharacterIndex startIndex,
85 GlyphIndex startGlyphIndex,
86 Length numberOfCharacters );
89 * @brief Retrieves glyphs in the given buffer.
91 * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
92 * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
93 * @param[in] glyphIndex Index to the first glyph.
94 * @param[in] numberOfGlyphs Number of glyphs to be copied.
96 void GetGlyphs( GlyphInfo* glyphs,
97 GlyphIndex glyphIndex,
98 Length numberOfGlyphs ) const;
100 // Position interface
103 * @brief Retrieves the glyph positions.
105 * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
106 * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
107 * @param[in] glyphIndex Index to the first glyph position.
108 * @param[in] numberOfGlyphs The number of positions to be copied.
110 void GetGlyphPositions( Vector2* glyphPositions,
111 GlyphIndex glyphIndex,
112 Length numberOfGlyphs ) const;
117 * @brief Retrieves the number of lines and the index to the first line where the given range of glyphs is laid out.
119 * @param[in] glyphIndex Index to the first glyph.
120 * @param[in] numberOfGlyphs The number of glyph.
121 * @param[out] firstLine Index to the line containing the glyph index.
122 * @param[out] numberOfLines The number of lines.
124 void GetNumberOfLines( GlyphIndex glyphIndex,
125 Length numberOfGlyphs,
126 LineIndex& firstLine,
127 Length& numberOfLines ) const;
130 * @brief Retrieves the lines where the given range of glyphs is laid out.
132 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
134 * @param[out] lines Pointer to a buffer where the lines are copied.
135 * @param[in] glyphIndex Index to the first glyphs of the range.
136 * @param[in] numberOfGlyphs Number of glyphs in the range.
138 void GetLinesOfGlyphRange( LineRun* lines,
139 GlyphIndex glyphIndex,
140 Length numberOfGlyphs ) const;
143 * @brief Retrieves the line index where the character is laid-out.
145 * @param[in] characterIndex The character's index.
147 * @return The line index.
149 LineIndex GetLineOfCharacter( CharacterIndex characterIndex );
154 * @brief Retrieves the underline runs.
156 * @param[out] underlineRuns Pointer to a buffer where the underline runs are copied.
157 * @param[in] index Index of the first underline run to be copied.
158 * @param[in] numberOfRuns Number of underline runs to be copied.
160 void GetUnderlineRuns( GlyphRun* underlineRuns,
161 UnderlineRunIndex index,
162 Length numberOfRuns ) const;
167 * @brief Sets the natural size.
169 * @param[in] size The text's natural size.
171 void SetNaturalSize( const Vector2& size );
174 * @brief Retrieves the natural size.
176 * @return The text's natural size.
178 const Vector2& GetNaturalSize() const;
181 * @brief Sets the text's layout size.
183 * @param[in] size The text's size.
185 void SetLayoutSize( const Vector2& size );
188 * @brief Retrieves the text's layout size.
190 * @return The text's size.
192 const Vector2& GetLayoutSize() const;
195 * @brief Set the text's color
197 * @param[in] textColor The text's color
199 void SetTextColor( const Vector4& textColor );
202 * @brief Retrieve the text's color
204 * @return The text's color
206 const Vector4& GetTextColor() const;
209 * @brief Sets the text's shadow offset.
211 * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
213 void SetShadowOffset( const Vector2& shadowOffset );
216 * @brief Retrieves the text's shadow offset.
218 * @return The text's shadow offset, 0,0 indicates no shadow.
220 const Vector2& GetShadowOffset() const;
223 * @brief Sets the text's shadow color.
225 * @param[in] shadowColor The shadow color.
227 void SetShadowColor( const Vector4& shadowColor );
230 * @brief Retrieves the text's shadow color.
232 * @return The text's shadow color.
234 const Vector4& GetShadowColor() const;
237 * @brief Sets the text's underline color.
239 * @param[in] color The text's underline color.
241 void SetUnderlineColor( const Vector4& color );
244 * @brief Retrieves the text's underline color.
246 * @return The text's underline color.
248 const Vector4& GetUnderlineColor() const;
251 * @brief Sets the text underline flag.
253 * @param[in] enabled true if underlined.
255 void SetUnderlineEnabled( bool enabled );
258 * @brief Returns whether the text is underlined or not.
260 * @return underline state.
262 bool IsUnderlineEnabled() const;
265 * @brief Clear the caches.
270 * @brief Set the override used for underline height, 0 indicates height will be come from font metrics
272 * @param[in] height The height in pixels of the underline
274 void SetUnderlineHeight( float height );
277 * @brief Retrieves the underline height override
279 * @return Returns the override height for an underline, 0 indicates that font metrics will determine the height
281 float GetUnderlineHeight() const;
286 * @brief A reference counted object may only be deleted by calling Unreference().
288 virtual ~VisualModel();
293 * @brief Private constructor.
298 VisualModel( const VisualModel& handle );
301 VisualModel& operator=( const VisualModel& handle );
305 Vector<GlyphInfo> mGlyphs; ///< For each glyph, the font's id, glyph's index within the font and glyph's metrics.
306 Vector<CharacterIndex> mGlyphsToCharacters; ///< For each glyph, the index of the first character.
307 Vector<GlyphIndex> mCharactersToGlyph; ///< For each character, the index of the first glyph.
308 Vector<Length> mCharactersPerGlyph; ///< For each glyph, the number of characters that form the glyph.
309 Vector<Length> mGlyphsPerCharacter; ///< For each character, the number of glyphs that are shaped.
310 Vector<Vector2> mGlyphPositions; ///< For each glyph, the position.
311 Vector<LineRun> mLines; ///< The laid out lines.
312 Vector<GlyphRun> mUnderlineRuns; ///< Runs of glyphs that are underlined.
313 Vector<Vector4> mColors; ///< Colors of the glyphs.
314 Vector<ColorIndex> mColorIndices; ///< Indices to the vector of colors for each glyphs.
316 Vector4 mTextColor; ///< The text color
317 Vector4 mShadowColor; ///< Color of drop shadow
318 Vector4 mUnderlineColor; ///< Color of underline
319 Size mControlSize; ///< The size of the UI control.
320 Vector2 mShadowOffset; ///< Offset for drop shadow, 0 indicates no shadow
321 float mUnderlineHeight; ///< Fixed height for underline to override font metrics.
325 Size mNaturalSize; ///< Size of the text with no line wrapping.
326 Size mLayoutSize; ///< Size of the laid-out text considering the layout properties set.
328 // Caches to increase performance in some consecutive operations.
329 LineIndex mCachedLineIndex; ///< Used to increase performance in consecutive calls to GetLineOfGlyph() or GetLineOfCharacter() with consecutive glyphs or characters.
333 bool mUnderlineEnabled:1; ///< Underline enabled flag
334 bool mUnderlineColorSet:1; ///< Has the underline color been explicitly set?
339 } // namespace Toolkit
343 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_H__