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/object/ref-object.h>
27 #include <dali-toolkit/internal/text/line-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 Replaces any glyphs previously set.
67 * @note If the number of glyphs is zero, all buffers are cleared.
68 * @note If one pointer is NULL and the number of glyphs is not zero, the buffer is not touched.
70 * @param[in] glyphs An array of glyphs in the visual order.
71 * @param[in] characterIndices An array containing the first character in the logical model that each glyph relates to.
72 * @param[in] charactersPerGlyph An array containing the number of characters per glyph.
73 * @param[in] numberOfGlyphs The number of glyphs.
75 void SetGlyphs( const GlyphInfo* glyphs,
76 const CharacterIndex* characterIndices,
77 const Length* charactersPerGlyph,
78 Length numberOfGlyphs );
81 * @brief Creates the character to glyph conversion table.
83 * @pre The glyphs per character table needs to be created first.
85 * @param[in] numberOfCharacters The number of characters.
87 void CreateCharacterToGlyphTable( Length numberOfCharacters = 0u );
90 * @brief Creates an array containing the number of glyphs per character.
92 * @param[in] numberOfCharacters The number of characters.
94 void CreateGlyphsPerCharacterTable( Length numberOfCharacters = 0u );
97 * Retrieves the number of glyphs.
99 * @return The number of glyphs.
101 Length GetNumberOfGlyphs() const;
104 * @brief Retrieves glyphs in the given buffer.
106 * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
107 * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
108 * @param[in] glyphIndex Index to the first glyph.
109 * @param[in] numberOfGlyphs Number of glyphs to be copied.
111 void GetGlyphs( GlyphInfo* glyphs,
112 GlyphIndex glyphIndex,
113 Length numberOfGlyphs ) const;
118 * @param[in] glyphIndex Index to a glyph.
122 const GlyphInfo& GetGlyphInfo( GlyphIndex glyphIndex ) const;
127 * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
128 * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
130 * @param[in] glyphIndex Where to replace the glyphs.
131 * @param[in] numberOfGlyphsToRemove The number of glyphs to be removed.
132 * @param[in] glyphs Pointer to a buffer with the new glyphs.
133 * @param[in] numberOfCharacters Pointer to a buffer with the number of characters per glyph.
134 * @param[in] numberOfGlyphsToInsert The number of new glyphs in the buffer.
136 void ReplaceGlyphs( GlyphIndex glyphIndex,
137 Length numberOfGlyphsToRemove,
138 const GlyphInfo* const glyphs,
139 const Length* const numberOfCharacters,
140 Length numberOfGlyphsToInsert );
142 // Character <--> Glyph conversion
145 * @brief Retrieves the first character in the logical model which a glyph represents.
147 * @note After shaping several characters may be represented by the same glyph.
148 * Alternatively several glyphs may be required to display a character.
149 * @param[in] glyphIndex The glyph index.
150 * @return The character index.
152 CharacterIndex GetCharacterIndex( GlyphIndex glyphIndex ) const;
155 * @brief Query the number of characters the glyph represents.
157 * @param[in] glyphIndex The glyph index.
158 * @return The number of characters represented by the glyph.
160 Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
163 * Retrieves the first glyph in the visual model which represents a given character.
165 * @note After shaping several characters may be represented by the same glyph.
166 * Alternatively several glyphs may be required to display a character.
167 * @param[in] characterIndex The character index.
168 * @return The glyph index.
170 GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
173 * Retrieves the whole or part of the character to glyph conversion map.
175 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
177 * @param[out] characterToGlyphMap Pointer to a buffer where the conversion map is copied.
178 * @param[in] characterIndex Index to the first character.
179 * @param[in] numberOfCharacters The number of characters.
181 void GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
182 CharacterIndex characterIndex,
183 Length numberOfCharacters ) const;
186 * Retrieves the whole or part of the glyph to character conversion map.
188 * The size of the buffer needs to be big enough to copy the @p numberOfGlyphs.
190 * @param[out] glyphToCharacter Pointer to a buffer where the conversion map is copied.
191 * @param[in] glyphIndex Index to the first glyph.
192 * @param[in] numberOfGlyphs The number of glyphs.
194 void GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
195 GlyphIndex glyphIndex,
196 Length numberOfGlyphs ) const;
199 * Retrieves for each glyph the number of characters the glyph represents.
201 * @param[out] charactersPerGlyph Pointer to a buffer where the number of characters for each glyph are copied.
202 * @param[in] glyphIndex Index to the first glyph.
203 * @param[in] numberOfGlyphs The number of glyphs.
205 void GetCharactersPerGlyphMap( Length* charactersPerGlyph,
206 GlyphIndex glyphIndex,
207 Length numberOfGlyphs ) const;
210 * Retrieves for each character the number of glyphs the character is shaped.
212 * @param[out] glyphsPerCharacter Pointer to a buffer where the number of glyphs for each character are copied.
213 * @param[in] characterIndex Index to the first character.
214 * @param[in] numberOfCharacters The number of characters.
216 void GetGlyphsPerCharacterMap( Length* glyphsPerCharacter,
217 CharacterIndex characterIndex,
218 Length numberOfCharacters ) const;
220 // Position interface
223 * @brief Replaces any glyph positions previously set.
225 * @note If the number of glyphs is zero the position buffer is cleared.
227 * @param[in] glyphPositions An array of visual positions for each glyph.
228 * @param[in] numberOfGlyphs The number of positions.
230 void SetGlyphPositions( const Vector2* glyphPositions,
231 Length numberOfGlyphs );
234 * Retrieves the number of glyph positions set.
236 * @note This may be less than the number of glyphs in the model.
237 * @return The number of glyphs.
239 Length GetNumberOfGlyphPositions() const;
242 * @brief Retrieves the glyph positions.
244 * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
245 * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
246 * @param[in] glyphIndex Index to the first glyph position.
247 * @param[in] numberOfGlyphs The number of positions to be copied.
249 void GetGlyphPositions( Vector2* glyphPositions,
250 GlyphIndex glyphIndex,
251 Length numberOfGlyphs ) const;
254 * Retrieve the glyph's position of the given glyph.
256 * @param[in] glyphIndex Index to the glyph.
258 * @return The glyph's position.
260 const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
263 * Replaces glyph's positions.
265 * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
266 * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
268 * @param[in] glyphIndex Where to replace the glyph's positions.
269 * @param[in] numberOfGlyphsToRemove The number of glyph's positions to be removed.
270 * @param[in] positions Pointer to a buffer with the new glyph's positions.
271 * @param[in] numberOfGlyphsToInsert The number of new glyph's positions in the buffer.
273 void ReplaceGlyphPositions( GlyphIndex glyphIndex,
274 Length numberOfGlyphsToRemove,
275 const Vector2* const positions,
276 Length numberOfGlyphsToInsert );
283 * Replaces any lines previously set.
285 * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
287 * @note If the number of lines is zero or the pointer is NULL, the lines buffer is cleared.
289 * @param[in] lines Pointer to a buffer containing all the line runs.
290 * @param[in] numberOfLines The number of lines in the buffer.
292 void SetLines( const LineRun* const lines,
293 Length numberOfLines );
296 * Retrieves the number of lines of the whole text.
298 * @return The number of lines.
300 Length GetNumberOfLines() const;
305 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
307 * @param[out] lines Pointer to a buffer where the lines are copied.
308 * @param[in] lineIndex Index to the first line.
309 * @param[in] numberOfLines Number of lines to be copied.
311 void GetLines( LineRun* lines,
313 Length numberOfLines ) const;
316 * Retrieves the number of lines and the index to the first line where the given range of glyphs is laid out.
318 * @param[in] glyphIndex Index to the first glyph.
319 * @param[in] numberOfGlyphs The number of glyph.
320 * @param[out] firstLine Index to the line containing the glyph index.
321 * @param[out] numberOfLines The number of lines.
323 void GetNumberOfLines( GlyphIndex glyphIndex,
324 Length numberOfGlyphs,
325 LineIndex& firstLine,
326 Length& numberOfLines ) const;
328 * Retrieves the lines where the given range of glyphs is laid out.
330 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
332 * @param[out] lines Pointer to a buffer where the lines are copied.
333 * @param[in] glyphIndex Index to the first glyphs of the range.
334 * @param[in] numberOfGlyphs Number of glyphs in the range.
336 void GetLinesOfGlyphRange( LineRun* lines,
337 GlyphIndex glyphIndex,
338 Length numberOfGlyphs ) const;
341 * Replaces lines for the given range of glyphs.
343 * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
344 * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
346 * @param[in] glyphIndex Index of the first glyph where to replace the line info.
347 * @param[in] numberOfGlyphsToRemove The number of glyphs to be the line info removed.
348 * @param[in] lines Pointer to a buffer with the lines.
349 * @param[in] numberOfGlyphsToInsert The number of characters to be the line info inserted.
351 void ReplaceLines( GlyphIndex glyphIndex,
352 Length numberOfGlyphsToRemove,
353 const LineRun* const lines,
354 Length numberOfGlyphsToInsert );
359 * Sets the natural size.
361 * @param[in] size The text's natural size.
363 void SetNaturalSize( const Vector2& size );
366 * Retrieves the natural size.
368 * @return The text's natural size.
370 const Vector2& GetNaturalSize() const;
373 * Sets the text's actual size after it has been laid out.
375 * @param[in] size The text's size.
377 void SetActualSize( const Vector2& size );
380 * Retrieves the text's actual size after it has been laid out.
382 * @return The text's size.
384 const Vector2& GetActualSize() const;
389 * @brief A reference counted object may only be deleted by calling Unreference().
391 virtual ~VisualModel();
396 * @brief Private constructor.
401 VisualModel( const VisualModel& handle );
404 VisualModel& operator=( const VisualModel& handle );
408 Vector<GlyphInfo> mGlyphs; ///< For each glyph, the font's id, glyph's index within the font and glyph's metrics.
409 Vector<CharacterIndex> mGlyphsToCharacters; ///< For each glyph, the index of the first character.
410 Vector<GlyphIndex> mCharactersToGlyph; ///< For each character, the index of the first glyph.
411 Vector<Length> mCharactersPerGlyph; ///< For each glyph, the number of characters that form the glyph.
412 Vector<Length> mGlyphsPerCharacter; ///< For each character, the number of glyphs that are shaped.
413 Vector<Vector2> mGlyphPositions; ///< For each glyph, the position.
414 Vector<LineRun> mLines; ///< The laid out lines.
418 Size mNaturalSize; ///< Size of the text with no line wrapping.
419 Size mActualSize; ///< Size of the laid-out text considering the layout properties set.
424 } // namespace Toolkit
428 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_H__