Text segmentation interface added.
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / text / logical-model.h
1 #ifndef __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_H__
2 #define __DALI_TOOLKIT_TEXT_LOGICAL_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
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/text/text-definitions.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Text
34 {
35
36 struct FontRun;
37 class LogicalModel;
38 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
39 struct ScriptRun;
40
41 /**
42  * @brief A logical text model contains layout independent information.
43  *
44  * This includes:
45  * - A series of UTF-32 characters in logical order
46  */
47 class LogicalModel : public RefObject
48 {
49 public:
50
51   /**
52    * @brief Create a new instance of a LogicalModel.
53    *
54    * @return A pointer to a new LogicalModel.
55    */
56   static LogicalModelPtr New();
57
58   // Text interface.
59
60   /**
61    * @brief Replaces any text previously set.
62    *
63    * @param[in] text An array of UTF-32 characters.
64    * @param[in] length The length of the array.
65    */
66   void SetText( const Character* text,
67                 Length length );
68
69   /**
70    * @brief Retrieves the number of characters of the text.
71    *
72    * @return The number of characters.
73    */
74   Length GetNumberOfCharacters() const;
75
76   /**
77    * @brief Retrieves characters from the text in the given buffer.
78    *
79    * @pre The size of the @p text buffer needs to be big enough to copy the @p numberOfCharacters.
80    * @param[in] characterIndex The index to the first character to copy.
81    * @param[out] text Pointer to a buffer where the text is copied.
82    * @param[in] numberOfCharacters The number of characters to be copied.
83    */
84   void GetText( CharacterIndex characterIndex,
85                 Character* text,
86                 Length numberOfCharacters ) const;
87
88   // Language support interface.
89
90   /**
91    * Sets the script runs.
92    *
93    * Replaces any scripts previously set.
94    *
95    * A run is a group of consecutive characters. A script run contains the script for a run.
96    *
97    * @param[in] scripts Pointer to a buffer with all the script runs.
98    * @param[in] numberOfRuns The number of script runs.
99    */
100   void SetScripts( const ScriptRun* const scripts,
101                    Length numberOfRuns );
102
103   /**
104    * Retrieves the number of script runs for the given range of characters.
105    *
106    * A run is a group of consecutive characters. A script run contains the script for a run.
107    *
108    * @param[in] characterIndex Index to the first character.
109    * @param[in] numberOfCharacters The number of characters.
110    *
111    * @return The number of script runs.
112    */
113   Length GetNumberOfScriptRuns( CharacterIndex characterIndex,
114                                 Length numberOfCharacters ) const;
115
116   /**
117    * Retrieves the script runs for the given range of characters.
118    *
119    * The @p scriptRuns buffer needs to be big enough to copy the number of script runs.
120    * Call GetNumberOfScriptRuns() to retrieve the number of script runs.
121    *
122    * @param[out] scriptRuns Pointer to a buffer where the script runs are copied.
123    * @param[in] characterIndex Index to the first character.
124    * @param[in] numberOfCharacters The number of characters.
125    */
126   void GetScriptRuns( ScriptRun* scriptRuns,
127                       CharacterIndex characterIndex,
128                       Length numberOfCharacters ) const;
129
130   /**
131    * Retrieves the script for the given character index.
132    *
133    * @param[in] characterIndex Index to the character.
134    *
135    * @return The character's script.
136    */
137   Script GetScript( CharacterIndex characterIndex ) const;
138
139   /**
140    * Sets the font runs.
141    *
142    * Replaces any fonts previously set.
143    *
144    * A run is a group of consecutive characters. A font run contains the font id for a run.
145    *
146    * @param[in] fonts Pointer to a buffer with all the font runs.
147    * @param[in] numberOfRuns The number of font runs.
148    */
149   void SetFonts( const FontRun* const fonts,
150                  Length numberOfRuns );
151
152   /**
153    * Retrieves the number of font runs for the given range of characters.
154    *
155    * A run is a group of consecutive characters. A font run contains the font id for a run.
156    *
157    * @param[in] characterIndex Index to the first character.
158    * @param[in] numberOfCharacters The number of characters.
159    *
160    * @return The number of font runs.
161    */
162   Length GetNumberOfFontRuns( CharacterIndex characterIndex,
163                               Length numberOfCharacters ) const;
164
165   /**
166    * Retrieves the font runs for the given range of characters.
167    *
168    * The @p fontRuns buffer needs to be big enough to copy the number of font runs.
169    * Call GetNumberOfFontRuns() to retrieve the number of font runs.
170    *
171    * @param[out] fontRuns Pointer to a buffer where the font runs are copied.
172    * @param[in] characterIndex Index to the first character.
173    * @param[in] numberOfCharacters The number of characters.
174    */
175   void GetFontRuns( FontRun* fontRuns,
176                     CharacterIndex characterIndex,
177                     Length numberOfCharacters ) const;
178
179   /**
180    * Retrieves the font id for the given character index.
181    *
182    * @param[in] characterIndex Index to the first character.
183    *
184    * @return The font id.
185    */
186   FontId GetFont( CharacterIndex characterIndex ) const;
187
188   // Break info interface.
189
190   /**
191    * Sets the line break info.
192    *
193    * See GetLineBreakInfo() to get how the line break info is encoded.
194    *
195    * Replaces any line break info previously set.
196    *
197    * @param[in] lineBreakInfo Pointer to a buffer with the line break info.
198    * @param[in] length The size of the buffer.
199    */
200   void SetLineBreakInfo( const LineBreakInfo* const lineBreakInfo,
201                          Length length );
202
203   /**
204    * Retrieves the line break info in the given buffer.
205    *
206    * The size of the @p lineBreakInfo buffer needs to be big enough to copy the @p numberOfItems.
207    *
208    * Possible values for LineBreakInfo are:
209    *
210    *  - 0 is a LINE_MUST_BREAK.  Text must be broken into a new line.
211    *  - 1 is a LINE_ALLOW_BREAK. Is possible to break the text into a new line.
212    *  - 2 is a LINE_NO_BREAK.    Text can't be broken into a new line.
213    *
214      @verbatim
215      i.e. Hello big\nworld produces:
216           2222212220 22220
217      @endverbatim
218    *
219    * @param[out] lineBreakInfo Pointer to a buffer where the line break info is copied.
220    * @param[in] characterIndex Index to the first line break info item.
221    * @param[in] numberOfItems The number of items to be copied.
222    */
223   void GetLineBreakInfo( LineBreakInfo* lineBreakInfo,
224                          CharacterIndex characterIndex,
225                          Length numberOfItems ) const;
226
227   /**
228    * Retrieves the line break info for the given item index.
229    *
230    * @param[in] characterIndex Index to the line break info item.
231    */
232   LineBreakInfo GetLineBreakInfo( CharacterIndex characterIndex ) const;
233
234   /**
235    * Sets the word break info.
236    *
237    * See GetWordBreakInfo() to get how the word break info is encoded.
238    *
239    * Replaces any word break info previously set.
240    *
241    * @param[in] wordBreakInfo Pointer to a buffer with the word break info.
242    * @param[in] length The size of the buffer.
243    */
244   void SetWordBreakInfo( const WordBreakInfo* const wordBreakInfo,
245                          Length length );
246
247   /**
248    * Retrieves the word break info in the given buffer.
249    *
250    * The size of the @p wordBreakInfo buffer needs to be big enough to copy the @p numberOfItems.
251    *
252    * The size of the buffer has to be big enough to store the whole word break info per character.
253    * Call GetNumberOfCharacters() to get the number of characters.
254    *
255    * Possible values for WordBreakInfo are:
256    *
257    * - 0 is a WORD_BREAK.    Text can be broken into a new word.
258    * - 1 is a WORD_NO_BREAK. Text can't be broken into a new word.
259    *
260      @verbatim
261      i.e. Hello big\nworld produces:
262           1111001100 11110
263      @endverbatim
264    *
265    * @param[out] wordBreakInfo Pointer to a buffer where the word break info is copied.
266    * @param[in] characterIndex Index to the first word break info item.
267    * @param[in] numberOfItems The number of items to be copied.
268    */
269   void GetWordBreakInfo( WordBreakInfo* wordBreakInfo,
270                          CharacterIndex characterIndex,
271                          Length numberOfItems ) const;
272
273   /**
274    * Retrieves the word break info for the given item index.
275    *
276    * @param[in] characterIndex Index to the word break info item.
277    */
278   WordBreakInfo GetWordBreakInfo( CharacterIndex characterIndex ) const;
279
280 protected:
281
282   /**
283    * @brief A reference counted object may only be deleted by calling Unreference().
284    */
285   virtual ~LogicalModel();
286
287 private:
288
289   /**
290    * @brief Private constructor.
291    */
292   LogicalModel();
293
294   // Undefined
295   LogicalModel( const LogicalModel& handle );
296
297   // Undefined
298   LogicalModel& operator=( const LogicalModel& handle );
299
300 private:
301
302   struct Impl;
303   Impl* mImpl;
304 };
305
306 } // namespace Text
307
308 } // namespace Toolkit
309
310 } // namespace Dali
311
312 #endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_H__