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>
26 #include <dali-toolkit/internal/text/text-definitions.h>
41 typedef IntrusivePtr<VisualModel> VisualModelPtr;
44 * @brief A visual text model contains layout specific information.
47 * - A series of glyphs in visual order i.e. after the bidirectional reordering.
48 * - The position of each glyph within a 2D bounding box.
50 class VisualModel : public RefObject
55 * @brief Create a new instance of a VisualModel.
57 * @return A pointer to a new VisualModel.
59 static VisualModelPtr New();
64 * @brief Replaces any glyphs previously set.
66 * @note If the number of glyphs is zero, all buffers are cleared.
67 * @note If one pointer is NULL and the number of glyphs is not zero, the buffer is not touched.
69 * @param[in] glyphs An array of glyphs in the visual order.
70 * @param[in] characterIndices An array containing the first character in the logical model that each glyph relates to.
71 * @param[in] charactersPerGlyph An array containing the number of characters per glyph.
72 * @param[in] numberOfGlyphs The number of glyphs.
74 void SetGlyphs( const GlyphInfo* glyphs,
75 const CharacterIndex* characterIndices,
76 const Length* charactersPerGlyph,
77 Length numberOfGlyphs );
80 * Retrieves the number of glyphs.
82 * @return The number of glyphs.
84 Length GetNumberOfGlyphs() const;
87 * @brief Retrieves glyphs in the given buffer.
89 * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
90 * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
91 * @param[in] glyphIndex Index to the first glyph.
92 * @param[in] numberOfGlyphs Number of glyphs to be copied.
94 void GetGlyphs( GlyphInfo* glyphs,
95 GlyphIndex glyphIndex,
96 Length numberOfGlyphs ) const;
101 * @param[in] glyphIndex Index to a glyph.
105 const GlyphInfo& GetGlyphInfo( GlyphIndex glyphIndex ) const;
110 * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
111 * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
113 * @param[in] glyphIndex Where to replace the glyphs.
114 * @param[in] numberOfGlyphsToRemove The number of glyphs to be removed.
115 * @param[in] glyphs Pointer to a buffer with the new glyphs.
116 * @param[in] numberOfCharacters Pointer to a buffer with the number of characters per glyph.
117 * @param[in] numberOfGlyphsToInsert The number of new glyphs in the buffer.
119 void ReplaceGlyphs( GlyphIndex glyphIndex,
120 Length numberOfGlyphsToRemove,
121 const GlyphInfo* const glyphs,
122 const Length* const numberOfCharacters,
123 Length numberOfGlyphsToInsert );
125 // Character <--> Glyph conversion
128 * @brief Retrieves the first character in the logical model which a glyph represents.
130 * @note After shaping several characters may be represented by the same glyph.
131 * Alternatively several glyphs may be required to display a character.
132 * @param[in] glyphIndex The glyph index.
133 * @return The character index.
135 CharacterIndex GetCharacterIndex( GlyphIndex glyphIndex ) const;
138 * @brief Query the number of characters the glyph represents.
140 * @param[in] glyphIndex The glyph index.
141 * @return The number of characters represented by the glyph.
143 Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
146 * Retrieves the first glyph in the visual model which represents a given character.
148 * @note After shaping several characters may be represented by the same glyph.
149 * Alternatively several glyphs may be required to display a character.
150 * @param[in] characterIndex The character index.
151 * @return The glyph index.
153 GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
156 * Retrieves the whole or part of the character to glyph conversion map.
158 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
160 * @param[out] characterToGlyphMap Pointer to a buffer where the conversion map is copied.
161 * @param[in] characterIndex Index to the first character.
162 * @param[in] numberOfCharacters The number of characters.
164 void GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
165 CharacterIndex characterIndex,
166 Length numberOfCharacters ) const;
169 * Retrieves the whole or part of the glyph to character conversion map.
171 * The size of the buffer needs to be big enough to copy the @p numberOfGlyphs.
173 * @param[out] glyphToCharacter Pointer to a buffer where the conversion map is copied.
174 * @param[in] glyphIndex Index to the first glyph.
175 * @param[in] numberOfGlyphs The number of glyphs.
177 void GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
178 GlyphIndex glyphIndex,
179 Length numberOfGlyphs ) const;
182 * Retrieves for each glyph the number of characters the glyph represents.
184 * @param[out] charactersPerGlyph Pointer to a buffer where the number of characters for each glyph are copied.
185 * @param[in] glyphIndex Index to the first glyph.
186 * @param[in] numberOfGlyphs The number of glyphs.
188 void GetCharactersPerGlyphMap( Length* charactersPerGlyph,
189 GlyphIndex glyphIndex,
190 Length numberOfGlyphs ) const;
193 * Retrieves for each character the number of glyphs the character is shaped.
195 * @param[out] glyphsPerCharacter Pointer to a buffer where the number of glyphs for each character are copied.
196 * @param[in] characterIndex Index to the first character.
197 * @param[in] numberOfCharacters The number of characters.
199 void GetGlyphsPerCharacterMap( Length* glyphsPerCharacter,
200 CharacterIndex characterIndex,
201 Length numberOfCharacters ) const;
203 // Position interface
206 * @brief Replaces any glyph positions previously set.
208 * @note If the number of glyphs is zero the position buffer is cleared.
210 * @param[in] glyphPositions An array of visual positions for each glyph.
211 * @param[in] numberOfGlyphs The number of positions.
213 void SetGlyphPositions( const Vector2* glyphPositions,
214 Length numberOfGlyphs );
217 * Retrieves the number of glyph positions set.
219 * @note This may be less than the number of glyphs in the model.
220 * @return The number of glyphs.
222 Length GetNumberOfGlyphPositions() const;
225 * @brief Retrieves the glyph positions.
227 * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
228 * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
229 * @param[in] glyphIndex Index to the first glyph position.
230 * @param[in] numberOfGlyphs The number of positions to be copied.
232 void GetGlyphPositions( Vector2* glyphPositions,
233 GlyphIndex glyphIndex,
234 Length numberOfGlyphs ) const;
237 * Retrieve the glyph's position of the given glyph.
239 * @param[in] glyphIndex Index to the glyph.
241 * @return The glyph's position.
243 const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
246 * Replaces glyph's positions.
248 * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
249 * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
251 * @param[in] glyphIndex Where to replace the glyph's positions.
252 * @param[in] numberOfGlyphsToRemove The number of glyph's positions to be removed.
253 * @param[in] positions Pointer to a buffer with the new glyph's positions.
254 * @param[in] numberOfGlyphsToInsert The number of new glyph's positions in the buffer.
256 void ReplaceGlyphPositions( GlyphIndex glyphIndex,
257 Length numberOfGlyphsToRemove,
258 const Vector2* const positions,
259 Length numberOfGlyphsToInsert );
266 * Replaces any lines previously set.
268 * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
270 * @note If the number of lines is zero or the pointer is NULL, the lines buffer is cleared.
272 * @param[in] lines Pointer to a buffer containing all the line runs.
273 * @param[in] numberOfLines The number of lines in the buffer.
275 void SetLines( const LineRun* const lines,
276 Length numberOfLines );
279 * Retrieves the number of lines of the whole text.
281 * @return The number of lines.
283 Length GetNumberOfLines() const;
288 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
290 * @param[out] lines Pointer to a buffer where the lines are copied.
291 * @param[in] lineIndex Index to the first line.
292 * @param[in] numberOfLines Number of lines to be copied.
294 void GetLines( LineRun* lines,
296 Length numberOfLines ) const;
299 * Retrieves the number of lines where the given range of glyphs is laid out.
301 * @param[in] glyphIndex Index to the first glyph.
302 * @param[in] numberOfGlyphs The number of glyph.
304 * @return The number of lines.
306 Length GetNumberOfLines( GlyphIndex glyphIndex,
307 Length numberOfGlyphs ) const;
309 * Retrieves the lines where the given range of glyphs is laid out.
311 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
313 * @param[out] lines Pointer to a buffer where the lines are copied.
314 * @param[in] glyphIndex Index to the first glyphs of the range.
315 * @param[in] numberOfGlyphs Number of glyphs in the range.
317 void GetLinesOfGlyphRange( LineRun* lines,
318 GlyphIndex glyphIndex,
319 Length numberOfGlyphs ) const;
322 * Replaces lines for the given range of glyphs.
324 * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
325 * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
327 * @param[in] glyphIndex Index of the first glyph where to replace the line info.
328 * @param[in] numberOfGlyphsToRemove The number of glyphs to be the line info removed.
329 * @param[in] lines Pointer to a buffer with the lines.
330 * @param[in] numberOfGlyphsToInsert The number of characters to be the line info inserted.
332 void ReplaceLines( GlyphIndex glyphIndex,
333 Length numberOfGlyphsToRemove,
334 const LineRun* const lines,
335 Length numberOfGlyphsToInsert );
340 * Sets the natural size.
342 * @param[in] size The text's natural size.
344 void SetNaturalSize( const Vector2& size );
347 * Retrieves the natural size.
349 * @return The text's natural size.
351 const Vector2& GetNaturalSize() const;
354 * Sets the text's actual size after it has been laid out.
356 * @param[in] size The text's size.
358 void SetActualSize( const Vector2& size );
361 * Retrieves the text's actual size after it has been laid out.
363 * @return The text's size.
365 const Vector2& GetActualSize() const;
370 * @brief A reference counted object may only be deleted by calling Unreference().
372 virtual ~VisualModel();
377 * @brief Private constructor.
382 VisualModel( const VisualModel& handle );
385 VisualModel& operator=( const VisualModel& handle );
394 } // namespace Toolkit
398 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__