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 * @note If the number of glyphs is zero, all buffers are cleared.
65 * @note If one pointer is NULL and the number of glyphs is not zero, the buffer is not touched.
67 * @param[in] glyphs An array of glyphs in the visual order.
68 * @param[in] characterIndices An array containing the first character in the logical model that each glyph relates to.
69 * @param[in] charactersPerGlyph An array containing the number of characters per glyph.
70 * @param[in] numberOfGlyphs The number of glyphs.
72 void SetGlyphs( const GlyphInfo* glyphs,
73 const CharacterIndex* characterIndices,
74 const Length* charactersPerGlyph,
75 Length numberOfGlyphs );
78 * Retrieves the number of glyphs.
80 * @return The number of glyphs.
82 Length GetNumberOfGlyphs() const;
85 * @brief Retrieves glyphs in the given buffer.
87 * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
88 * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
89 * @param[in] glyphIndex Index to the first glyph.
90 * @param[in] numberOfGlyphs Number of glyphs to be copied.
92 void GetGlyphs( GlyphInfo* glyphs,
93 GlyphIndex glyphIndex,
94 Length numberOfGlyphs ) const;
99 * @param[in] glyphIndex Index to a glyph.
103 const GlyphInfo& GetGlyphInfo( GlyphIndex glyphIndex ) const;
105 // Character <--> Glyph conversion
108 * @brief Retrieves the first character in the logical model which a glyph represents.
110 * @note After shaping several characters may be represented by the same glyph.
111 * Alternatively several glyphs may be required to display a character.
112 * @param[in] glyphIndex The glyph index.
113 * @return The character index.
115 CharacterIndex GetCharacterIndex( GlyphIndex glyphIndex ) const;
118 * @brief Query the number of characters the glyph represents.
120 * @param[in] glyphIndex The glyph index.
121 * @return The number of characters represented by the glyph.
123 Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
126 * Retrieves the first glyph in the visual model which represents a given character.
128 * @note After shaping several characters may be represented by the same glyph.
129 * Alternatively several glyphs may be required to display a character.
130 * @param[in] characterIndex The character index.
131 * @return The glyph index.
133 GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
136 * Retrieves the whole or part of the character to glyph conversion map.
138 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
140 * @param[out] characterToGlyphMap Pointer to a buffer where the conversion map is copied.
141 * @param[in] characterIndex Index to the first character.
142 * @param[in] numberOfCharacters The number of characters.
144 void GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
145 CharacterIndex characterIndex,
146 Length numberOfCharacters ) const;
149 * Retrieves for each glyph the number of characters the glyph represents.
151 * @param[out] charactersPerGlyph Pointer to a buffer where the number of characters for each glyph are copied.
152 * @param[in] glyphIndex Index to the first glyph.
153 * @param[in] numberOfGlyphs The number of glyphs.
155 void GetCharactersPerGlyphMap( Length* charactersPerGlyph,
156 GlyphIndex glyphIndex,
157 Length numberOfGlyphs ) const;
160 * Retrieves the whole or part of the glyph to character conversion map.
162 * The size of the buffer needs to be big enough to copy the @p numberOfGlyphs.
164 * @param[out] glyphToCharacter Pointer to a buffer where the conversion map is copied.
165 * @param[in] glyphIndex Index to the first glyph.
166 * @param[in] numberOfGlyphs The number of glyphs.
168 void GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
169 GlyphIndex glyphIndex,
170 Length numberOfGlyphs ) const;
172 // Position interface
175 * @brief Replaces any glyph positions previously set.
177 * @note If the number of glyphs is zero the position buffer is cleared.
179 * @param[in] glyphPositions An array of visual positions for each glyph.
180 * @param[in] numberOfGlyphs The number of positions.
182 void SetGlyphPositions( const Vector2* glyphPositions,
183 Length numberOfGlyphs );
186 * Retrieves the number of glyph positions set.
188 * @note This may be less than the number of glyphs in the model.
189 * @return The number of glyphs.
191 Length GetNumberOfGlyphPositions() const;
194 * @brief Retrieves the glyph positions.
196 * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
197 * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
198 * @param[in] glyphIndex Index to the first glyph position.
199 * @param[in] numberOfGlyphs The number of positions to be copied.
201 void GetGlyphPositions( Vector2* glyphPositions,
202 GlyphIndex glyphIndex,
203 Length numberOfGlyphs ) const;
206 * Retrieve the glyph's position of the given glyph.
208 * @param[in] glyphIndex Index to the glyph.
210 * @return The glyph's position.
212 const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
219 * Replaces any lines previously set.
221 * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
223 * @note If the number of lines is zero or the pointer is NULL, the lines buffer is cleared.
225 * @param[in] lines Pointer to a buffer containing all the line runs.
226 * @param[in] numberOfLines The number of lines in the buffer.
228 void SetLines( const LineRun* const lines,
229 Length numberOfLines );
232 * Retrieves the number of lines of the whole text.
234 * @return The number of lines.
236 Length GetNumberOfLines() const;
241 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
243 * @param[out] lines Pointer to a buffer where the lines are copied.
244 * @param[in] lineIndex Index to the first line.
245 * @param[in] numberOfLines Number of lines to be copied.
247 void GetLines( LineRun* lines,
249 Length numberOfLines ) const;
252 * Retrieves the number of lines where the given range of glyphs is laid out.
254 * @param[in] glyphIndex Index to the first glyph.
255 * @param[in] numberOfGlyphs The number of glyph.
257 * @return The number of lines.
259 Length GetNumberOfLines( GlyphIndex glyphIndex,
260 Length numberOfGlyphs ) const;
262 * Retrieves the lines where the given range of glyphs is laid out.
264 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
266 * @param[out] lines Pointer to a buffer where the lines are copied.
267 * @param[in] glyphIndex Index to the first glyphs of the range.
268 * @param[in] numberOfGlyphs Number of glyphs in the range.
270 void GetLinesOfGlyphRange( LineRun* lines,
271 GlyphIndex glyphIndex,
272 Length numberOfGlyphs ) const;
277 * Sets the natural size.
279 * @param[in] size The text's natural size.
281 void SetNaturalSize( const Vector2& size );
284 * Retrieves the natural size.
286 * @return The text's natural size.
288 const Vector2& GetNaturalSize() const;
291 * Sets the text's actual size after it has been laid out.
293 * @param[in] size The text's size.
295 void SetActualSize( const Vector2& size );
298 * Retrieves the text's actual size after it has been laid out.
300 * @return The text's size.
302 const Vector2& GetActualSize() const;
307 * @brief A reference counted object may only be deleted by calling Unreference().
309 virtual ~VisualModel();
314 * @brief Private constructor.
319 VisualModel( const VisualModel& handle );
322 VisualModel& operator=( const VisualModel& handle );
331 } // namespace Toolkit
335 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__