d8f6617ada6df65d7dfa4ba8fb4da4474f3fa3be
[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 protected:
189
190   /**
191    * @brief A reference counted object may only be deleted by calling Unreference().
192    */
193   virtual ~LogicalModel();
194
195 private:
196
197   /**
198    * @brief Private constructor.
199    */
200   LogicalModel();
201
202   // Undefined
203   LogicalModel( const LogicalModel& handle );
204
205   // Undefined
206   LogicalModel& operator=( const LogicalModel& handle );
207
208 private:
209
210   struct Impl;
211   Impl* mImpl;
212 };
213
214 } // namespace Text
215
216 } // namespace Toolkit
217
218 } // namespace Dali
219
220 #endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_H__