1 #ifndef __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__
2 #define __DALI_TOOLKIT_TEXT_VISUAL_MODEL_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/intrusive-ptr.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali-toolkit/internal/text/text-definitions.h>
39 typedef IntrusivePtr<VisualModel> VisualModelPtr;
42 * @brief A visual text model contains layout specific information.
45 * - A series of glyphs in visual order i.e. after the bidirectional reordering.
46 * - The position of each glyph within a 2D bounding box.
48 class VisualModel : public RefObject
53 * @brief Create a new instance of a VisualModel.
55 * @return A pointer to a new VisualModel.
57 static VisualModelPtr New();
62 * @brief Replaces any glyphs previously set.
64 * @param[in] glyphs An array of glyphs in the visual order.
65 * @param[in] characterIndices An array containing the first character in the logical model that each glyph relates to.
66 * @param[in] charactersPerGlyph An array containing the number of characters per glyph.
67 * @param[in] numberOfGlyphs The number of glyphs.
69 void SetGlyphs( const GlyphInfo* glyphs,
70 const CharacterIndex* characterIndices,
71 const Length* charactersPerGlyph,
72 Length numberOfGlyphs );
75 * Retrieves the number of glyphs.
77 * @return The number of glyphs.
79 Length GetNumberOfGlyphs() const;
82 * @brief Retrieves glyphs in the given buffer.
84 * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
85 * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
86 * @param[in] glyphIndex Index to the first glyph.
87 * @param[in] numberOfGlyphs Number of glyphs to be copied.
89 void GetGlyphs( GlyphInfo* glyphs,
90 GlyphIndex glyphIndex,
91 Length numberOfGlyphs ) const;
96 * @param[in] glyphIndex Index to a glyph.
100 const GlyphInfo& GetGlyphInfo( GlyphIndex glyphIndex ) const;
102 // Character <--> Glyph conversion
105 * @brief Retrieves the first character in the logical model which a glyph represents.
107 * @note After shaping several characters may be represented by the same glyph.
108 * Alternatively several glyphs may be required to display a character.
109 * @param[in] glyphIndex The glyph index.
110 * @return The character index.
112 CharacterIndex GetCharacterIndex( GlyphIndex glyphIndex ) const;
115 * @brief Query the number of characters the glyph represents.
117 * @param[in] glyphIndex The glyph index.
118 * @return The number of characters represented by the glyph.
120 Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
123 * Retrieves the first glyph in the visual model which represents a given character.
125 * @note After shaping several characters may be represented by the same glyph.
126 * Alternatively several glyphs may be required to display a character.
127 * @param[in] characterIndex The character index.
128 * @return The glyph index.
130 GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
133 * Retrieves the whole or part of the character to glyph conversion map.
135 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
137 * @param[out] characterToGlyphMap Pointer to a buffer where the conversion map is copied.
138 * @param[in] characterIndex Index to the first character.
139 * @param[in] numberOfCharacters The number of characters.
141 void GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
142 CharacterIndex characterIndex,
143 Length numberOfCharacters ) const;
146 * Retrieves for each glyph the number of characters the glyph represents.
148 * @param[out] charactersPerGlyph Pointer to a buffer where the number of characters for each glyph are copied.
149 * @param[in] glyphIndex Index to the first glyph.
150 * @param[in] numberOfGlyphs The number of glyphs.
152 void GetCharactersPerGlyphMap( Length* charactersPerGlyph,
153 GlyphIndex glyphIndex,
154 Length numberOfGlyphs ) const;
157 * Retrieves the whole or part of the glyph to character conversion map.
159 * The size of the buffer needs to be big enough to copy the @p numberOfGlyphs.
161 * @param[out] glyphToCharacter Pointer to a buffer where the conversion map is copied.
162 * @param[in] glyphIndex Index to the first glyph.
163 * @param[in] numberOfGlyphs The number of glyphs.
165 void GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
166 GlyphIndex glyphIndex,
167 Length numberOfGlyphs ) const;
169 // Position interface
172 * @brief Replaces any glyph positions previously set.
174 * @param[in] glyphPositions An array of visual positions for each glyph.
175 * @param[in] numberOfGlyphs The number of positions.
177 void SetGlyphPositions( const Vector2* glyphPositions,
178 Length numberOfGlyphs );
181 * @brief Retrieves the glyph positions.
183 * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
184 * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
185 * @param[in] glyphIndex Index to the first glyph position.
186 * @param[in] numberOfGlyphs The number of positions to be copied.
188 void GetGlyphPositions( Vector2* glyphPositions,
189 GlyphIndex glyphIndex,
190 Length numberOfGlyphs ) const;
193 * Retrieve the glyph's position of the given glyph.
195 * @param[in] glyphIndex Index to the glyph.
197 * @return The glyph's position.
199 const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
206 * Replaces any lines previously set.
208 * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
210 * @param[in] lines Pointer to a buffer containing all the line runs.
211 * @param[in] numberOfLines The number of lines in the buffer.
213 void SetLines( const LineRun* const lines,
214 Length numberOfLines );
217 * Retrieves the number of lines of the whole text.
219 * @return The number of lines.
221 Length GetNumberOfLines() const;
226 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
228 * @param[out] lines Pointer to a buffer where the lines are copied.
229 * @param[in] lineIndex Index to the first line.
230 * @param[in] numberOfLines Number of lines to be copied.
232 void GetLines( LineRun* lines,
234 Length numberOfLines ) const;
237 * Retrieves the number of lines where the given range of glyphs is laid out.
239 * @param[in] glyphIndex Index to the first glyph.
240 * @param[in] numberOfGlyphs The number of glyph.
242 * @return The number of lines.
244 Length GetNumberOfLines( GlyphIndex glyphIndex,
245 Length numberOfGlyphs ) const;
247 * Retrieves the lines where the given range of glyphs is laid out.
249 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
251 * @param[out] lines Pointer to a buffer where the lines are copied.
252 * @param[in] glyphIndex Index to the first glyphs of the range.
253 * @param[in] numberOfGlyphs Number of glyphs in the range.
255 void GetLinesOfGlyphRange( LineRun* lines,
256 GlyphIndex glyphIndex,
257 Length numberOfGlyphs ) const;
262 * Sets the natural size.
264 * @param[in] size The text's natural size.
266 void SetNaturalSize( const Vector2& size );
269 * Retrieves the natural size.
271 * @return The text's natural size.
273 const Vector2& GetNaturalSize() const;
276 * Sets the text's actual size after it has been laid out.
278 * @param[in] size The text's size.
280 void SetActualSize( const Vector2& size );
283 * Retrieves the text's actual size after it has been laid out.
285 * @return The text's size.
287 const Vector2& GetActualSize() const;
292 * @brief A reference counted object may only be deleted by calling Unreference().
294 virtual ~VisualModel();
299 * @brief Private constructor.
304 VisualModel( const VisualModel& handle );
307 VisualModel& operator=( const VisualModel& handle );
316 } // namespace Toolkit
320 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__