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 * @brief Retrieves the glyph positions.
188 * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
189 * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
190 * @param[in] glyphIndex Index to the first glyph position.
191 * @param[in] numberOfGlyphs The number of positions to be copied.
193 void GetGlyphPositions( Vector2* glyphPositions,
194 GlyphIndex glyphIndex,
195 Length numberOfGlyphs ) const;
198 * Retrieve the glyph's position of the given glyph.
200 * @param[in] glyphIndex Index to the glyph.
202 * @return The glyph's position.
204 const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
211 * Replaces any lines previously set.
213 * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
215 * @note If the number of lines is zero or the pointer is NULL, the lines buffer is cleared.
217 * @param[in] lines Pointer to a buffer containing all the line runs.
218 * @param[in] numberOfLines The number of lines in the buffer.
220 void SetLines( const LineRun* const lines,
221 Length numberOfLines );
224 * Retrieves the number of lines of the whole text.
226 * @return The number of lines.
228 Length GetNumberOfLines() const;
233 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
235 * @param[out] lines Pointer to a buffer where the lines are copied.
236 * @param[in] lineIndex Index to the first line.
237 * @param[in] numberOfLines Number of lines to be copied.
239 void GetLines( LineRun* lines,
241 Length numberOfLines ) const;
244 * Retrieves the number of lines where the given range of glyphs is laid out.
246 * @param[in] glyphIndex Index to the first glyph.
247 * @param[in] numberOfGlyphs The number of glyph.
249 * @return The number of lines.
251 Length GetNumberOfLines( GlyphIndex glyphIndex,
252 Length numberOfGlyphs ) const;
254 * Retrieves the lines where the given range of glyphs is laid out.
256 * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
258 * @param[out] lines Pointer to a buffer where the lines are copied.
259 * @param[in] glyphIndex Index to the first glyphs of the range.
260 * @param[in] numberOfGlyphs Number of glyphs in the range.
262 void GetLinesOfGlyphRange( LineRun* lines,
263 GlyphIndex glyphIndex,
264 Length numberOfGlyphs ) const;
269 * Sets the natural size.
271 * @param[in] size The text's natural size.
273 void SetNaturalSize( const Vector2& size );
276 * Retrieves the natural size.
278 * @return The text's natural size.
280 const Vector2& GetNaturalSize() const;
283 * Sets the text's actual size after it has been laid out.
285 * @param[in] size The text's size.
287 void SetActualSize( const Vector2& size );
290 * Retrieves the text's actual size after it has been laid out.
292 * @return The text's size.
294 const Vector2& GetActualSize() const;
299 * @brief A reference counted object may only be deleted by calling Unreference().
301 virtual ~VisualModel();
306 * @brief Private constructor.
311 VisualModel( const VisualModel& handle );
314 VisualModel& operator=( const VisualModel& handle );
323 } // namespace Toolkit
327 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__