1 #ifndef __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_H__
2 #define __DALI_TOOLKIT_TEXT_LOGICAL_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>
25 #include <dali-toolkit/public-api/text/text-definitions.h>
36 struct BidirectionalLineInfoRun;
37 struct BidirectionalParagraphInfoRun;
40 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
44 * @brief A logical text model contains layout independent information.
47 * - A series of UTF-32 characters in logical order
49 class LogicalModel : public RefObject
54 * @brief Create a new instance of a LogicalModel.
56 * @return A pointer to a new LogicalModel.
58 static LogicalModelPtr New();
63 * @brief Replaces any text previously set.
65 * @param[in] text An array of UTF-32 characters.
66 * @param[in] length The length of the array.
68 void SetText( const Character* text,
72 * @brief Retrieves the number of characters of the text.
74 * @return The number of characters.
76 Length GetNumberOfCharacters() const;
79 * @brief Retrieves characters from the text in the given buffer.
81 * @pre The size of the @p text buffer needs to be big enough to copy the @p numberOfCharacters.
82 * @param[in] characterIndex The index to the first character to copy.
83 * @param[out] text Pointer to a buffer where the text is copied.
84 * @param[in] numberOfCharacters The number of characters to be copied.
86 void GetText( CharacterIndex characterIndex,
88 Length numberOfCharacters ) const;
90 // Language support interface.
93 * Sets the script runs.
95 * Replaces any scripts previously set.
97 * A run is a group of consecutive characters. A script run contains the script for a run.
99 * @param[in] scripts Pointer to a buffer with all the script runs.
100 * @param[in] numberOfRuns The number of script runs.
102 void SetScripts( const ScriptRun* const scripts,
103 Length numberOfRuns );
106 * Retrieves the number of script runs for the given range of characters.
108 * A run is a group of consecutive characters. A script run contains the script for a run.
110 * @param[in] characterIndex Index to the first character.
111 * @param[in] numberOfCharacters The number of characters.
113 * @return The number of script runs.
115 Length GetNumberOfScriptRuns( CharacterIndex characterIndex,
116 Length numberOfCharacters ) const;
119 * Retrieves the script runs for the given range of characters.
121 * The @p scriptRuns buffer needs to be big enough to copy the number of script runs.
122 * Call GetNumberOfScriptRuns() to retrieve the number of script runs.
124 * @param[out] scriptRuns Pointer to a buffer where the script runs are copied.
125 * @param[in] characterIndex Index to the first character.
126 * @param[in] numberOfCharacters The number of characters.
128 void GetScriptRuns( ScriptRun* scriptRuns,
129 CharacterIndex characterIndex,
130 Length numberOfCharacters ) const;
133 * Retrieves the script for the given character index.
135 * @param[in] characterIndex Index to the character.
137 * @return The character's script.
139 Script GetScript( CharacterIndex characterIndex ) const;
142 * Sets the font runs.
144 * Replaces any fonts previously set.
146 * A run is a group of consecutive characters. A font run contains the font id for a run.
148 * @param[in] fonts Pointer to a buffer with all the font runs.
149 * @param[in] numberOfRuns The number of font runs.
151 void SetFonts( const FontRun* const fonts,
152 Length numberOfRuns );
155 * Retrieves the number of font runs for the given range of characters.
157 * A run is a group of consecutive characters. A font run contains the font id for a run.
159 * @param[in] characterIndex Index to the first character.
160 * @param[in] numberOfCharacters The number of characters.
162 * @return The number of font runs.
164 Length GetNumberOfFontRuns( CharacterIndex characterIndex,
165 Length numberOfCharacters ) const;
168 * Retrieves the font runs for the given range of characters.
170 * The @p fontRuns buffer needs to be big enough to copy the number of font runs.
171 * Call GetNumberOfFontRuns() to retrieve the number of font runs.
173 * @param[out] fontRuns Pointer to a buffer where the font runs are copied.
174 * @param[in] characterIndex Index to the first character.
175 * @param[in] numberOfCharacters The number of characters.
177 void GetFontRuns( FontRun* fontRuns,
178 CharacterIndex characterIndex,
179 Length numberOfCharacters ) const;
182 * Retrieves the font id for the given character index.
184 * @param[in] characterIndex Index to the first character.
186 * @return The font id.
188 FontId GetFont( CharacterIndex characterIndex ) const;
190 // Break info interface.
193 * Sets the line break info.
195 * See GetLineBreakInfo() to get how the line break info is encoded.
197 * Replaces any line break info previously set.
199 * @param[in] lineBreakInfo Pointer to a buffer with the line break info.
200 * @param[in] length The size of the buffer.
202 void SetLineBreakInfo( const LineBreakInfo* const lineBreakInfo,
206 * Retrieves the line break info in the given buffer.
208 * The size of the @p lineBreakInfo buffer needs to be big enough to copy the @p numberOfItems.
210 * Possible values for LineBreakInfo are:
212 * - 0 is a LINE_MUST_BREAK. Text must be broken into a new line.
213 * - 1 is a LINE_ALLOW_BREAK. Is possible to break the text into a new line.
214 * - 2 is a LINE_NO_BREAK. Text can't be broken into a new line.
217 i.e. Hello big\nworld produces:
221 * @param[out] lineBreakInfo Pointer to a buffer where the line break info is copied.
222 * @param[in] characterIndex Index to the first line break info item.
223 * @param[in] numberOfItems The number of items to be copied.
225 void GetLineBreakInfo( LineBreakInfo* lineBreakInfo,
226 CharacterIndex characterIndex,
227 Length numberOfItems ) const;
230 * Retrieves the line break info for the given item index.
232 * @param[in] characterIndex Index to the line break info item.
234 LineBreakInfo GetLineBreakInfo( CharacterIndex characterIndex ) const;
237 * Sets the word break info.
239 * See GetWordBreakInfo() to get how the word break info is encoded.
241 * Replaces any word break info previously set.
243 * @param[in] wordBreakInfo Pointer to a buffer with the word break info.
244 * @param[in] length The size of the buffer.
246 void SetWordBreakInfo( const WordBreakInfo* const wordBreakInfo,
250 * Retrieves the word break info in the given buffer.
252 * The size of the @p wordBreakInfo buffer needs to be big enough to copy the @p numberOfItems.
254 * The size of the buffer has to be big enough to store the whole word break info per character.
255 * Call GetNumberOfCharacters() to get the number of characters.
257 * Possible values for WordBreakInfo are:
259 * - 0 is a WORD_BREAK. Text can be broken into a new word.
260 * - 1 is a WORD_NO_BREAK. Text can't be broken into a new word.
263 i.e. Hello big\nworld produces:
267 * @param[out] wordBreakInfo Pointer to a buffer where the word break info is copied.
268 * @param[in] characterIndex Index to the first word break info item.
269 * @param[in] numberOfItems The number of items to be copied.
271 void GetWordBreakInfo( WordBreakInfo* wordBreakInfo,
272 CharacterIndex characterIndex,
273 Length numberOfItems ) const;
276 * Retrieves the word break info for the given item index.
278 * @param[in] characterIndex Index to the word break info item.
280 WordBreakInfo GetWordBreakInfo( CharacterIndex characterIndex ) const;
282 // Bidirectional support interface.
285 * Sets the bidirectional info runs.
287 * Replaces any bidirectional info previously set.
289 * Each bidirectional info run stores bidirectional info for a whole 'paragraph' of text which contains right to left scripts.
291 * In terms of the bidirectional algorithm, a 'paragraph' is understood as a run of characters between Paragraph Separators or appropriate Newline Functions.
292 * A 'paragraph' may also be determined by higher-level protocols like a mark-up tag.
294 * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
295 * @param[in] numberOfRuns The number of bidirectional info runs.
297 void SetBidirectionalInfo( const BidirectionalParagraphInfoRun* const bidirectionalInfo,
298 Length numberOfRuns );
301 * Retrieves the number of bidirectional info runs for the given range of characters.
303 * It may be zero if there is no right to left scripts.
305 * @param[in] characterIndex Index to the first character.
306 * @param[in] numberOfCharacters The number of characters.
308 * @return The number of bidirectional info runs.
310 Length GetNumberOfBidirectionalInfoRuns( CharacterIndex characterIndex,
311 Length numberOfCharacters ) const;
314 * Retrieves the direction of the characters.
316 * It sets @c true for right to left characters and @c false for left to right.
317 * For neutral characters it check's the next and previous character's directions:
318 * - If they are equals set that direction. If they are not, sets the paragraph's direction.
319 * - If there is no next, sets the paragraph's direction.
321 * See SetBidirectionalInfo() to get an explanation of the 'paragraph' meaning in the bidirectional algorithm.
323 * @param[out] directions Whether the characters are right to left or left to right.
324 * @param[in] characterIndex Index to the first character.
325 * @param[in] numberOfCharacters The number of characters.
327 void GetCharacterDirections( CharacterDirection* directions,
328 CharacterIndex characterIndex,
329 Length numberOfCharacters ) const;
332 * Retrieves the direction of a characters.
334 * See GetCharacterDirections().
336 * @param[in] characterIndex Index to a character.
338 * @return The character's direction.
340 CharacterDirection GetCharacterDirection( CharacterIndex characterIndex ) const;
342 // Visual <--> Logical conversion tables.
345 * Sets the visual to logical and the logical to visual map tables.
347 * Replaces any map tables previously set.
349 * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
350 * @param[in] numberOfRuns The number of bidirectional info runs.
352 void SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo,
353 Length numberOfRuns );
356 * Retrieves the visual character index for the given logical character index.
358 * @param[in] logicalCharacterIndex The logical character index.
360 * @return The visual character index.
362 CharacterIndex GetVisualCharacterIndex( CharacterIndex logicalCharacterIndex ) const;
365 * Retrieves the logical character index for the given visual character index.
367 * @param[in] visualCharacterIndex The visual character index.
369 * @return The logical character index.
371 CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const;
374 * Retrieves the whole or part of the logical to visual conversion map.
376 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
378 * @param[out] logicalToVisualMap Pointer to a buffer where the conversion map is copied.
379 * @param[in] characterIndex Index to the first character.
380 * @param[in] numberOfCharacters The number of characters.
382 void GetLogicalToVisualMap( CharacterIndex* logicalToVisualMap,
383 CharacterIndex characterIndex,
384 Length numberOfCharacters ) const;
387 * Retrieves the whole or part of the visual to logical conversion map.
389 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
391 * @param[out] visualToLogicalMap Pointer to a buffer where the conversion map is copied.
392 * @param[in] characterIndex Index to the first character.
393 * @param[in] numberOfCharacters The number of characters.
395 void GetVisualToLogicalMap( CharacterIndex* visualToLogicalMap,
396 CharacterIndex characterIndex,
397 Length numberOfCharacters ) const;
401 * @brief A reference counted object may only be deleted by calling Unreference().
403 virtual ~LogicalModel();
408 * @brief Private constructor.
413 LogicalModel( const LogicalModel& handle );
416 LogicalModel& operator=( const LogicalModel& handle );
426 } // namespace Toolkit
430 #endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_H__