Fixes for Shaping. Do not shape \n characters.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali-toolkit/public-api/text/text-definitions.h>
25
26 namespace Dali
27 {
28
29 struct Vector2;
30
31 namespace Toolkit
32 {
33
34 namespace Text
35 {
36
37 struct LineRun;
38 class VisualModel;
39 typedef IntrusivePtr<VisualModel> VisualModelPtr;
40
41 /**
42  * @brief A visual text model contains layout specific information.
43  *
44  * This includes:
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.
47  */
48 class VisualModel : public RefObject
49 {
50 public:
51
52   /**
53    * @brief Create a new instance of a VisualModel.
54    *
55    * @return A pointer to a new VisualModel.
56    */
57   static VisualModelPtr New();
58
59   // Glyph interface.
60
61   /**
62    * @brief Replaces any glyphs previously set.
63    *
64    * @param[in] glyphs An array of glyphs in the visual order.
65    * @param[in] characterIndices An array containing the first character in the logical model that each glyph relates to.
66    * @param[in] charactersPerGlyph An array containing the number of characters per glyph.
67    * @param[in] numberOfGlyphs The number of glyphs.
68    */
69   void SetGlyphs( const GlyphInfo* glyphs,
70                   const CharacterIndex* characterIndices,
71                   const Length* charactersPerGlyph,
72                   Length numberOfGlyphs );
73
74   /**
75    * Retrieves the number of glyphs.
76    *
77    * @return The number of glyphs.
78    */
79   Length GetNumberOfGlyphs() const;
80
81   /**
82    * @brief Retrieves glyphs in the given buffer.
83    *
84    * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
85    * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
86    * @param[in] glyphIndex Index to the first glyph.
87    * @param[in] numberOfGlyphs Number of glyphs to be copied.
88    */
89   void GetGlyphs( GlyphInfo* glyphs,
90                   GlyphIndex glyphIndex,
91                   Length numberOfGlyphs ) const;
92
93   /**
94    * Retrieves a glyph.
95    *
96    * @param[in] glyphIndex Index to a glyph.
97    *
98    * @return A glyph.
99    */
100   const GlyphInfo& GetGlyphInfo( GlyphIndex glyphIndex ) const;
101
102   // Character <--> Glyph conversion
103
104   /**
105    * @brief Retrieves the first character in the logical model which a glyph represents.
106    *
107    * @note After shaping several characters may be represented by the same glyph.
108    * Alternatively several glyphs may be required to display a character.
109    * @param[in] glyphIndex The glyph index.
110    * @return The character index.
111    */
112   CharacterIndex GetCharacterIndex( GlyphIndex glyphIndex ) const;
113
114   /**
115    * @brief Query the number of characters the glyph represents.
116    *
117    * @param[in] glyphIndex The glyph index.
118    * @return The number of characters represented by the glyph.
119    */
120   Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
121
122   /**
123    * Retrieves the first glyph in the visual model which represents a given character.
124    *
125    * @note After shaping several characters may be represented by the same glyph.
126    * Alternatively several glyphs may be required to display a character.
127    * @param[in] characterIndex The character index.
128    * @return The glyph index.
129    */
130   GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
131
132   /**
133    * Retrieves the whole or part of the character to glyph conversion map.
134    *
135    * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
136    *
137    * @param[out] characterToGlyphMap Pointer to a buffer where the conversion map is copied.
138    * @param[in] characterIndex Index to the first character.
139    * @param[in] numberOfCharacters The number of characters.
140    */
141   void GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
142                                CharacterIndex characterIndex,
143                                Length numberOfCharacters ) const;
144
145   /**
146    * Retrieves for each glyph the number of characters the glyph represents.
147    *
148    * @param[out] charactersPerGlyph Pointer to a buffer where the number of characters for each glyph are copied.
149    * @param[in] glyphIndex Index to the first glyph.
150    * @param[in] numberOfGlyphs The number of glyphs.
151    */
152   void GetCharactersPerGlyphMap( Length* charactersPerGlyph,
153                                  GlyphIndex glyphIndex,
154                                  Length numberOfGlyphs ) const;
155
156   /**
157    * Retrieves the whole or part of the glyph to character conversion map.
158    *
159    * The size of the buffer needs to be big enough to copy the @p numberOfGlyphs.
160    *
161    * @param[out] glyphToCharacter Pointer to a buffer where the conversion map is copied.
162    * @param[in] glyphIndex Index to the first glyph.
163    * @param[in] numberOfGlyphs The number of glyphs.
164    */
165   void GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
166                                GlyphIndex glyphIndex,
167                                Length numberOfGlyphs ) const;
168
169   // Position interface
170
171   /**
172    * @brief Replaces any glyph positions previously set.
173    *
174    * @param[in] glyphPositions An array of visual positions for each glyph.
175    * @param[in] numberOfGlyphs The number of positions.
176    */
177   void SetGlyphPositions( const Vector2* glyphPositions,
178                           Length numberOfGlyphs );
179
180   /**
181    * @brief Retrieves the glyph positions.
182    *
183    * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
184    * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
185    * @param[in] glyphIndex Index to the first glyph position.
186    * @param[in] numberOfGlyphs The number of positions to be copied.
187    */
188   void GetGlyphPositions( Vector2* glyphPositions,
189                           GlyphIndex glyphIndex,
190                           Length numberOfGlyphs ) const;
191
192   /**
193    * Retrieve the glyph's position of the given glyph.
194    *
195    * @param[in] glyphIndex Index to the glyph.
196    *
197    * @return The glyph's position.
198    */
199   const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
200
201   // Line interface.
202
203   /**
204    * Sets the lines.
205    *
206    * Replaces any lines previously set.
207    *
208    * Every line is an item run containing the index to the first glyph of the line and the number of glyphs.
209    *
210    * @param[in] lines Pointer to a buffer containing all the line runs.
211    * @param[in] numberOfLines The number of lines in the buffer.
212    */
213   void SetLines( const LineRun* const lines,
214                  Length numberOfLines );
215
216   /**
217    * Retrieves the number of lines of the whole text.
218    *
219    * @return The number of lines.
220    */
221   Length GetNumberOfLines() const;
222
223   /**
224    * Retrieves lines.
225    *
226    * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
227    *
228    * @param[out] lines Pointer to a buffer where the lines are copied.
229    * @param[in] lineIndex Index to the first line.
230    * @param[in] numberOfLines Number of lines to be copied.
231    */
232   void GetLines( LineRun* lines,
233                  LineIndex lineIndex,
234                  Length numberOfLines ) const;
235
236   /**
237    * Retrieves the number of lines where the given range of glyphs is laid out.
238    *
239    * @param[in] glyphIndex Index to the first glyph.
240    * @param[in] numberOfGlyphs The number of glyph.
241    *
242    * @return The number of lines.
243    */
244   TextAbstraction::Length GetNumberOfLines( GlyphIndex glyphIndex,
245                                             Length numberOfGlyphs ) const;
246   /**
247    * Retrieves the lines where the given range of glyphs is laid out.
248    *
249    * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
250    *
251    * @param[out] lines Pointer to a buffer where the lines are copied.
252    * @param[in] glyphIndex Index to the first glyphs of the range.
253    * @param[in] numberOfGlyphs Number of glyphs in the range.
254    */
255   void GetLinesOfGlyphRange( LineRun* lines,
256                              GlyphIndex glyphIndex,
257                              Length numberOfGlyphs ) const;
258
259   // Size interface
260
261   /**
262    * Sets the natural size.
263    *
264    * @param[in] size The text's natural size.
265    */
266   void SetNaturalSize( const Vector2& size  );
267
268   /**
269    * Retrieves the natural size.
270    *
271    * @return The text's natural size.
272    */
273   const Vector2& GetNaturalSize() const;
274
275   /**
276    * Sets the text's actual size after it has been laid out.
277    *
278    * @param[in] size The text's size.
279    */
280   void SetActualSize( const Vector2& size );
281
282   /**
283    * Retrieves the text's actual size after it has been laid out.
284    *
285    * @return The text's size.
286    */
287   const Vector2& GetActualSize() const;
288
289 protected:
290
291   /**
292    * @brief A reference counted object may only be deleted by calling Unreference().
293    */
294   virtual ~VisualModel();
295
296 private:
297
298   /**
299    * @brief Private constructor.
300    */
301   VisualModel();
302
303   // Undefined
304   VisualModel( const VisualModel& handle );
305
306   // Undefined
307   VisualModel& operator=( const VisualModel& handle );
308
309 private:
310
311   struct Impl;
312   Impl* mImpl;
313 };
314 } // namespace Text
315
316 } // namespace Toolkit
317
318 } // namespace Dali
319
320 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__