Removed some pointless setters
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / visual-model.h
1 #ifndef __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__
2 #define __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/ref-object.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/text-definitions.h>
27
28 namespace Dali
29 {
30
31 struct Vector2;
32
33 namespace Toolkit
34 {
35
36 namespace Text
37 {
38
39 struct LineRun;
40 class VisualModel;
41 typedef IntrusivePtr<VisualModel> VisualModelPtr;
42
43 /**
44  * @brief A visual text model contains layout specific information.
45  *
46  * This includes:
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.
49  */
50 class VisualModel : public RefObject
51 {
52 public:
53
54   /**
55    * @brief Create a new instance of a VisualModel.
56    *
57    * @return A pointer to a new VisualModel.
58    */
59   static VisualModelPtr New();
60
61   // Glyph interface.
62
63   /**
64    * @brief Replaces any glyphs previously set.
65    *
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.
68    *
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.
73    */
74   void SetGlyphs( const GlyphInfo* glyphs,
75                   const CharacterIndex* characterIndices,
76                   const Length* charactersPerGlyph,
77                   Length numberOfGlyphs );
78
79   /**
80    * Retrieves the number of glyphs.
81    *
82    * @return The number of glyphs.
83    */
84   Length GetNumberOfGlyphs() const;
85
86   /**
87    * @brief Retrieves glyphs in the given buffer.
88    *
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.
93    */
94   void GetGlyphs( GlyphInfo* glyphs,
95                   GlyphIndex glyphIndex,
96                   Length numberOfGlyphs ) const;
97
98   /**
99    * Retrieves a glyph.
100    *
101    * @param[in] glyphIndex Index to a glyph.
102    *
103    * @return A glyph.
104    */
105   const GlyphInfo& GetGlyphInfo( GlyphIndex glyphIndex ) const;
106
107   // Character <--> Glyph conversion
108
109   /**
110    * @brief Retrieves the first character in the logical model which a glyph represents.
111    *
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.
116    */
117   CharacterIndex GetCharacterIndex( GlyphIndex glyphIndex ) const;
118
119   /**
120    * @brief Query the number of characters the glyph represents.
121    *
122    * @param[in] glyphIndex The glyph index.
123    * @return The number of characters represented by the glyph.
124    */
125   Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
126
127   /**
128    * Retrieves the first glyph in the visual model which represents a given character.
129    *
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.
134    */
135   GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
136
137   /**
138    * Retrieves the whole or part of the character to glyph conversion map.
139    *
140    * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
141    *
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.
145    */
146   void GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
147                                CharacterIndex characterIndex,
148                                Length numberOfCharacters ) const;
149
150   /**
151    * Retrieves the whole or part of the glyph to character conversion map.
152    *
153    * The size of the buffer needs to be big enough to copy the @p numberOfGlyphs.
154    *
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.
158    */
159   void GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
160                                GlyphIndex glyphIndex,
161                                Length numberOfGlyphs ) const;
162
163   /**
164    * Retrieves for each glyph the number of characters the glyph represents.
165    *
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.
169    */
170   void GetCharactersPerGlyphMap( Length* charactersPerGlyph,
171                                  GlyphIndex glyphIndex,
172                                  Length numberOfGlyphs ) const;
173
174   /**
175    * Retrieves for each character the number of glyphs the character is shaped.
176    *
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.
180    */
181   void GetGlyphsPerCharacterMap( Length* glyphsPerCharacter,
182                                  CharacterIndex characterIndex,
183                                  Length numberOfCharacters ) const;
184
185   // Position interface
186
187   /**
188    * @brief Replaces any glyph positions previously set.
189    *
190    * @note If the number of glyphs is zero the position buffer is cleared.
191    *
192    * @param[in] glyphPositions An array of visual positions for each glyph.
193    * @param[in] numberOfGlyphs The number of positions.
194    */
195   void SetGlyphPositions( const Vector2* glyphPositions,
196                           Length numberOfGlyphs );
197
198   /**
199    * Retrieves the number of glyph positions set.
200    *
201    * @note This may be less than the number of glyphs in the model.
202    * @return The number of glyphs.
203    */
204   Length GetNumberOfGlyphPositions() const;
205
206   /**
207    * @brief Retrieves the glyph positions.
208    *
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.
213    */
214   void GetGlyphPositions( Vector2* glyphPositions,
215                           GlyphIndex glyphIndex,
216                           Length numberOfGlyphs ) const;
217
218   /**
219    * Retrieve the glyph's position of the given glyph.
220    *
221    * @param[in] glyphIndex Index to the glyph.
222    *
223    * @return The glyph's position.
224    */
225   const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
226
227   // Line interface.
228
229   /**
230    * Sets the lines.
231    *
232    * Replaces any lines previously set.
233    *
234    * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
235    *
236    * @note If the number of lines is zero or the pointer is NULL, the lines buffer is cleared.
237    *
238    * @param[in] lines Pointer to a buffer containing all the line runs.
239    * @param[in] numberOfLines The number of lines in the buffer.
240    */
241   void SetLines( const LineRun* const lines,
242                  Length numberOfLines );
243
244   /**
245    * Retrieves the number of lines of the whole text.
246    *
247    * @return The number of lines.
248    */
249   Length GetNumberOfLines() const;
250
251   /**
252    * Retrieves lines.
253    *
254    * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
255    *
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.
259    */
260   void GetLines( LineRun* lines,
261                  LineIndex lineIndex,
262                  Length numberOfLines ) const;
263
264   /**
265    * Retrieves the number of lines where the given range of glyphs is laid out.
266    *
267    * @param[in] glyphIndex Index to the first glyph.
268    * @param[in] numberOfGlyphs The number of glyph.
269    *
270    * @return The number of lines.
271    */
272   Length GetNumberOfLines( GlyphIndex glyphIndex,
273                            Length numberOfGlyphs ) const;
274   /**
275    * Retrieves the lines where the given range of glyphs is laid out.
276    *
277    * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
278    *
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.
282    */
283   void GetLinesOfGlyphRange( LineRun* lines,
284                              GlyphIndex glyphIndex,
285                              Length numberOfGlyphs ) const;
286
287   // Size interface
288
289   /**
290    * Sets the natural size.
291    *
292    * @param[in] size The text's natural size.
293    */
294   void SetNaturalSize( const Vector2& size  );
295
296   /**
297    * Retrieves the natural size.
298    *
299    * @return The text's natural size.
300    */
301   const Vector2& GetNaturalSize() const;
302
303   /**
304    * Sets the text's actual size after it has been laid out.
305    *
306    * @param[in] size The text's size.
307    */
308   void SetActualSize( const Vector2& size );
309
310   /**
311    * Retrieves the text's actual size after it has been laid out.
312    *
313    * @return The text's size.
314    */
315   const Vector2& GetActualSize() const;
316
317 protected:
318
319   /**
320    * @brief A reference counted object may only be deleted by calling Unreference().
321    */
322   virtual ~VisualModel();
323
324 private:
325
326   /**
327    * @brief Private constructor.
328    */
329   VisualModel();
330
331   // Undefined
332   VisualModel( const VisualModel& handle );
333
334   // Undefined
335   VisualModel& operator=( const VisualModel& handle );
336
337 private:
338
339   struct Impl;
340   Impl* mImpl;
341 };
342 } // namespace Text
343
344 } // namespace Toolkit
345
346 } // namespace Dali
347
348 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__