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;
107 // Character <--> Glyph conversion
110 * @brief Retrieves the first character in the logical model which a glyph represents.
112 * @note After shaping several characters may be represented by the same glyph.
113 * Alternatively several glyphs may be required to display a character.
114 * @param[in] glyphIndex The glyph index.
115 * @return The character index.
117 CharacterIndex GetCharacterIndex( GlyphIndex glyphIndex ) const;
120 * @brief Query the number of characters the glyph represents.
122 * @param[in] glyphIndex The glyph index.
123 * @return The number of characters represented by the glyph.
125 Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
128 * Retrieves the first glyph in the visual model which represents a given character.
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] characterIndex The character index.
133 * @return The glyph index.
135 GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
138 * Retrieves the whole or part of the character to glyph conversion map.
140 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
142 * @param[out] characterToGlyphMap Pointer to a buffer where the conversion map is copied.
143 * @param[in] characterIndex Index to the first character.
144 * @param[in] numberOfCharacters The number of characters.
146 void GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
147 CharacterIndex characterIndex,
148 Length numberOfCharacters ) const;
151 * Retrieves the whole or part of the glyph to character conversion map.
153 * The size of the buffer needs to be big enough to copy the @p numberOfGlyphs.
155 * @param[out] glyphToCharacter Pointer to a buffer where the conversion map is copied.
156 * @param[in] glyphIndex Index to the first glyph.
157 * @param[in] numberOfGlyphs The number of glyphs.
159 void GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
160 GlyphIndex glyphIndex,
161 Length numberOfGlyphs ) const;
164 * Retrieves for each glyph the number of characters the glyph represents.
166 * @param[out] charactersPerGlyph Pointer to a buffer where the number of characters for each glyph are copied.
167 * @param[in] glyphIndex Index to the first glyph.
168 * @param[in] numberOfGlyphs The number of glyphs.
170 void GetCharactersPerGlyphMap( Length* charactersPerGlyph,
171 GlyphIndex glyphIndex,
172 Length numberOfGlyphs ) const;
175 * Retrieves for each character the number of glyphs the character is shaped.
177 * @param[out] glyphsPerCharacter Pointer to a buffer where the number of glyphs for each character are copied.
178 * @param[in] characterIndex Index to the first character.
179 * @param[in] numberOfCharacters The number of characters.
181 void GetGlyphsPerCharacterMap( Length* glyphsPerCharacter,
182 CharacterIndex characterIndex,
183 Length numberOfCharacters ) const;
185 // Position interface
188 * @brief Replaces any glyph positions previously set.
190 * @note If the number of glyphs is zero the position buffer is cleared.
192 * @param[in] glyphPositions An array of visual positions for each glyph.
193 * @param[in] numberOfGlyphs The number of positions.
195 void SetGlyphPositions( const Vector2* glyphPositions,
196 Length numberOfGlyphs );
199 * Retrieves the number of glyph positions set.
201 * @note This may be less than the number of glyphs in the model.
202 * @return The number of glyphs.
204 Length GetNumberOfGlyphPositions() const;
207 * @brief Retrieves the glyph positions.
209 * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
210 * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
211 * @param[in] glyphIndex Index to the first glyph position.
212 * @param[in] numberOfGlyphs The number of positions to be copied.
214 void GetGlyphPositions( Vector2* glyphPositions,
215 GlyphIndex glyphIndex,
216 Length numberOfGlyphs ) const;
219 * Retrieve the glyph's position of the given glyph.
221 * @param[in] glyphIndex Index to the glyph.
223 * @return The glyph's position.
225 const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
232 * Replaces any lines previously set.
234 * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
236 * @note If the number of lines is zero or the pointer is NULL, the lines buffer is cleared.
238 * @param[in] lines Pointer to a buffer containing all the line runs.
239 * @param[in] numberOfLines The number of lines in the buffer.
241 void SetLines( const LineRun* const lines,
242 Length numberOfLines );
245 * Retrieves the number of lines of the whole text.
247 * @return The number of lines.
249 Length GetNumberOfLines() const;
254 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
256 * @param[out] lines Pointer to a buffer where the lines are copied.
257 * @param[in] lineIndex Index to the first line.
258 * @param[in] numberOfLines Number of lines to be copied.
260 void GetLines( LineRun* lines,
262 Length numberOfLines ) const;
265 * Retrieves the number of lines where the given range of glyphs is laid out.
267 * @param[in] glyphIndex Index to the first glyph.
268 * @param[in] numberOfGlyphs The number of glyph.
270 * @return The number of lines.
272 Length GetNumberOfLines( GlyphIndex glyphIndex,
273 Length numberOfGlyphs ) const;
275 * Retrieves the lines where the given range of glyphs is laid out.
277 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
279 * @param[out] lines Pointer to a buffer where the lines are copied.
280 * @param[in] glyphIndex Index to the first glyphs of the range.
281 * @param[in] numberOfGlyphs Number of glyphs in the range.
283 void GetLinesOfGlyphRange( LineRun* lines,
284 GlyphIndex glyphIndex,
285 Length numberOfGlyphs ) const;
290 * Sets the natural size.
292 * @param[in] size The text's natural size.
294 void SetNaturalSize( const Vector2& size );
297 * Retrieves the natural size.
299 * @return The text's natural size.
301 const Vector2& GetNaturalSize() const;
304 * Sets the text's actual size after it has been laid out.
306 * @param[in] size The text's size.
308 void SetActualSize( const Vector2& size );
311 * Retrieves the text's actual size after it has been laid out.
313 * @return The text's size.
315 const Vector2& GetActualSize() const;
320 * @brief A reference counted object may only be deleted by calling Unreference().
322 virtual ~VisualModel();
327 * @brief Private constructor.
332 VisualModel( const VisualModel& handle );
335 VisualModel& operator=( const VisualModel& handle );
344 } // namespace Toolkit
348 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__