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/dali-vector.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24 #include <dali/public-api/object/ref-object.h>
27 #include <dali-toolkit/internal/text/text-definitions.h>
38 struct BidirectionalLineInfoRun;
39 struct BidirectionalParagraphInfoRun;
42 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
46 * @brief A logical text model contains layout independent information.
49 * - A series of UTF-32 characters in logical order
51 class LogicalModel : public RefObject
56 * @brief Create a new instance of a LogicalModel.
58 * @return A pointer to a new LogicalModel.
60 static LogicalModelPtr New();
65 * @brief Replaces any text previously set.
67 * @note If the number of characters is zero the text buffer is cleared.
69 * @param[in] text An array of UTF-32 characters.
70 * @param[in] numberOfCharacters The length of the array.
72 void SetText( const Character* const text,
73 Length numberOfCharacters );
76 * @brief Retrieves the number of characters of the text.
78 * @return The number of characters.
80 Length GetNumberOfCharacters() const;
83 * @brief Retrieves characters from the text in the given buffer.
85 * @pre The size of the @p text buffer needs to be big enough to copy the @p numberOfCharacters.
86 * @param[out] text Pointer to a buffer where the text is copied.
87 * @param[in] characterIndex The index to the first character to copy.
88 * @param[in] numberOfCharacters The number of characters to be copied.
90 void GetText( Character* text,
91 CharacterIndex characterIndex,
92 Length numberOfCharacters ) const;
95 * Retrieves a character.
97 * @param[in] characterIndex Index to a character.
99 * @return A character.
101 Character GetCharacter( CharacterIndex characterIndex ) const;
103 // Language support interface.
106 * Sets the script runs.
108 * Replaces any scripts previously set.
110 * A run is a group of consecutive characters. A script run contains the script for a run.
112 * @note If the number of runs is zero the script buffer is cleared.
114 * @param[in] scripts Pointer to a buffer with all the script runs.
115 * @param[in] numberOfRuns The number of script runs.
117 void SetScripts( const ScriptRun* const scripts,
118 Length numberOfRuns );
121 * Retrieves the number of script runs for the given range of characters.
123 * A run is a group of consecutive characters. A script run contains the script for a run.
125 * @param[in] characterIndex Index to the first character.
126 * @param[in] numberOfCharacters The number of characters.
128 * @return The number of script runs.
130 Length GetNumberOfScriptRuns( CharacterIndex characterIndex,
131 Length numberOfCharacters ) const;
134 * Retrieves the script runs for the given range of characters.
136 * The @p scriptRuns buffer needs to be big enough to copy the number of script runs.
137 * Call GetNumberOfScriptRuns() to retrieve the number of script runs.
139 * @param[out] scriptRuns Pointer to a buffer where the script runs are copied.
140 * @param[in] characterIndex Index to the first character.
141 * @param[in] numberOfCharacters The number of characters.
143 void GetScriptRuns( ScriptRun* scriptRuns,
144 CharacterIndex characterIndex,
145 Length numberOfCharacters ) const;
148 * Retrieves the script for the given character index.
150 * @param[in] characterIndex Index to the character.
152 * @return The character's script.
154 Script GetScript( CharacterIndex characterIndex ) const;
157 * Sets the font runs.
159 * Replaces any fonts previously set.
161 * A run is a group of consecutive characters. A font run contains the font id for a run.
163 * @note If the number of runs is zero the font buffer is cleared.
165 * @param[in] fonts Pointer to a buffer with all the font runs.
166 * @param[in] numberOfRuns The number of font runs.
168 void SetFonts( const FontRun* const fonts,
169 Length numberOfRuns );
172 * Retrieves the number of font runs for the given range of characters.
174 * A run is a group of consecutive characters. A font run contains the font id for a run.
176 * @param[in] characterIndex Index to the first character.
177 * @param[in] numberOfCharacters The number of characters.
179 * @return The number of font runs.
181 Length GetNumberOfFontRuns( CharacterIndex characterIndex,
182 Length numberOfCharacters ) const;
185 * Retrieves the font runs for the given range of characters.
187 * The @p fontRuns buffer needs to be big enough to copy the number of font runs.
188 * Call GetNumberOfFontRuns() to retrieve the number of font runs.
190 * @param[out] fontRuns Pointer to a buffer where the font runs are copied.
191 * @param[in] characterIndex Index to the first character.
192 * @param[in] numberOfCharacters The number of characters.
194 void GetFontRuns( FontRun* fontRuns,
195 CharacterIndex characterIndex,
196 Length numberOfCharacters ) const;
199 * Retrieves the font id for the given character index.
201 * @param[in] characterIndex Index to the first character.
203 * @return The font id.
205 FontId GetFont( CharacterIndex characterIndex ) const;
207 // Break info interface.
210 * Sets the line break info.
212 * See GetLineBreakInfo() to get how the line break info is encoded.
214 * Replaces any line break info previously set.
216 * @note If the @length is zero the break info buffer is cleared.
218 * @param[in] lineBreakInfo Pointer to a buffer with the line break info.
219 * @param[in] length The size of the buffer.
221 void SetLineBreakInfo( const LineBreakInfo* const lineBreakInfo,
225 * Retrieves the line break info in the given buffer.
227 * The size of the @p lineBreakInfo buffer needs to be big enough to copy the @p numberOfItems.
229 * Possible values for LineBreakInfo are:
231 * - 0 is a LINE_MUST_BREAK. Text must be broken into a new line.
232 * - 1 is a LINE_ALLOW_BREAK. Is possible to break the text into a new line.
233 * - 2 is a LINE_NO_BREAK. Text can't be broken into a new line.
236 i.e. Hello big\nworld produces:
240 * @param[out] lineBreakInfo Pointer to a buffer where the line break info is copied.
241 * @param[in] characterIndex Index to the first line break info item.
242 * @param[in] numberOfItems The number of items to be copied.
244 void GetLineBreakInfo( LineBreakInfo* lineBreakInfo,
245 CharacterIndex characterIndex,
246 Length numberOfItems ) const;
249 * Retrieves the line break info for the given item index.
251 * @param[in] characterIndex Index to the line break info item.
253 LineBreakInfo GetLineBreakInfo( CharacterIndex characterIndex ) const;
256 * Sets the word break info.
258 * See GetWordBreakInfo() to get how the word break info is encoded.
260 * Replaces any word break info previously set.
262 * @note If the @length is zero the break info buffer is cleared.
264 * @param[in] wordBreakInfo Pointer to a buffer with the word break info.
265 * @param[in] length The size of the buffer.
267 void SetWordBreakInfo( const WordBreakInfo* const wordBreakInfo,
271 * Retrieves the word break info in the given buffer.
273 * The size of the @p wordBreakInfo buffer needs to be big enough to copy the @p numberOfItems.
275 * The size of the buffer has to be big enough to store the whole word break info per character.
276 * Call GetNumberOfCharacters() to get the number of characters.
278 * Possible values for WordBreakInfo are:
280 * - 0 is a WORD_BREAK. Text can be broken into a new word.
281 * - 1 is a WORD_NO_BREAK. Text can't be broken into a new word.
284 i.e. Hello big\nworld produces:
288 * @param[out] wordBreakInfo Pointer to a buffer where the word break info is copied.
289 * @param[in] characterIndex Index to the first word break info item.
290 * @param[in] numberOfItems The number of items to be copied.
292 void GetWordBreakInfo( WordBreakInfo* wordBreakInfo,
293 CharacterIndex characterIndex,
294 Length numberOfItems ) const;
297 * Retrieves the word break info for the given item index.
299 * @param[in] characterIndex Index to the word break info item.
301 WordBreakInfo GetWordBreakInfo( CharacterIndex characterIndex ) const;
303 // Bidirectional support interface.
306 * Sets the bidirectional info runs.
308 * Replaces any bidirectional info previously set.
310 * Each bidirectional info run stores bidirectional info for a whole 'paragraph' of text which contains right to left scripts.
312 * In terms of the bidirectional algorithm, a 'paragraph' is understood as a run of characters between Paragraph Separators or appropriate Newline Functions.
313 * A 'paragraph' may also be determined by higher-level protocols like a mark-up tag.
315 * @note If the number of runs is zero the bidirectional info buffer is cleared.
317 * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
318 * @param[in] numberOfRuns The number of bidirectional info runs.
320 void SetBidirectionalInfo( const BidirectionalParagraphInfoRun* const bidirectionalInfo,
321 Length numberOfRuns );
324 * Retrieves the number of bidirectional info runs for the given range of characters.
326 * It may be zero if there is no right to left scripts.
328 * @param[in] characterIndex Index to the first character.
329 * @param[in] numberOfCharacters The number of characters.
331 * @return The number of bidirectional info runs.
333 Length GetNumberOfBidirectionalInfoRuns( CharacterIndex characterIndex,
334 Length numberOfCharacters ) const;
337 * Retrieves the bidirectional paragraph info runs for the given range of characters.
339 * The @p bidirectionalInfo buffer needs to be big enough to copy the number of bidirectional
340 * paragraph info runs.
341 * Call GetNumberOfBidirectionalInfoRuns() to retrieve the number of bidirectional runs.
343 * @param[out] bidirectionalInfo Pointer to a buffer where the bidirectional info runs are copied.
344 * @param[in] characterIndex Index to the first character.
345 * @param[in] numberOfCharacters The number of characters.
347 void GetBidirectionalInfo( BidirectionalParagraphInfoRun* bidirectionalInfo,
348 CharacterIndex characterIndex,
349 Length numberOfCharacters ) const;
352 * Retrieves the direction of the characters.
354 * It sets @c true for right to left characters and @c false for left to right.
355 * For neutral characters it check's the next and previous character's directions:
356 * - If they are equals set that direction. If they are not, sets the paragraph's direction.
357 * - If there is no next, sets the paragraph's direction.
359 * See SetBidirectionalInfo() to get an explanation of the 'paragraph' meaning in the bidirectional algorithm.
361 * @param[out] directions Whether the characters are right to left or left to right.
362 * @param[in] characterIndex Index to the first character.
363 * @param[in] numberOfCharacters The number of characters.
365 void GetCharacterDirections( CharacterDirection* directions,
366 CharacterIndex characterIndex,
367 Length numberOfCharacters ) const;
370 * Retrieves the direction of a characters.
372 * See GetCharacterDirections().
374 * @param[in] characterIndex Index to a character.
376 * @return The character's direction.
378 CharacterDirection GetCharacterDirection( CharacterIndex characterIndex ) const;
380 // Visual <--> Logical conversion tables.
383 * Sets the visual to logical and the logical to visual map tables.
385 * Replaces any map tables previously set.
387 * @note If the number of runs is zero the bidirectional info buffer is cleared.
389 * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
390 * @param[in] numberOfRuns The number of bidirectional info runs.
392 void SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo,
393 Length numberOfRuns );
396 * Retrieves the visual character index for the given logical character index.
398 * @param[in] logicalCharacterIndex The logical character index.
400 * @return The visual character index.
402 CharacterIndex GetVisualCharacterIndex( CharacterIndex logicalCharacterIndex ) const;
405 * Retrieves the logical character index for the given visual character index.
407 * @param[in] visualCharacterIndex The visual character index.
409 * @return The logical character index.
411 CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const;
414 * Retrieves the whole or part of the logical to visual conversion map.
416 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
418 * @param[out] logicalToVisualMap Pointer to a buffer where the conversion map is copied.
419 * @param[in] characterIndex Index to the first character.
420 * @param[in] numberOfCharacters The number of characters.
422 void GetLogicalToVisualMap( CharacterIndex* logicalToVisualMap,
423 CharacterIndex characterIndex,
424 Length numberOfCharacters ) const;
427 * Retrieves the whole or part of the visual to logical conversion map.
429 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
431 * @param[out] visualToLogicalMap Pointer to a buffer where the conversion map is copied.
432 * @param[in] characterIndex Index to the first character.
433 * @param[in] numberOfCharacters The number of characters.
435 void GetVisualToLogicalMap( CharacterIndex* visualToLogicalMap,
436 CharacterIndex characterIndex,
437 Length numberOfCharacters ) const;
442 * @brief A reference counted object may only be deleted by calling Unreference().
444 virtual ~LogicalModel();
449 * @brief Private constructor.
454 LogicalModel( const LogicalModel& handle );
457 LogicalModel& operator=( const LogicalModel& handle );
467 } // namespace Toolkit
471 #endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_H__