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>
25 #include <dali-toolkit/internal/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 * @note If the number of characters is zero the text buffer is cleared.
67 * @param[in] text An array of UTF-32 characters.
68 * @param[in] numberOfCharacters The length of the array.
70 void SetText( const Character* const text,
71 Length numberOfCharacters );
74 * @brief Retrieves the number of characters of the text.
76 * @return The number of characters.
78 Length GetNumberOfCharacters() const;
81 * @brief Retrieves characters from the text in the given buffer.
83 * @pre The size of the @p text buffer needs to be big enough to copy the @p numberOfCharacters.
84 * @param[in] characterIndex The index to the first character to copy.
85 * @param[out] text Pointer to a buffer where the text is copied.
86 * @param[in] numberOfCharacters The number of characters to be copied.
88 void GetText( CharacterIndex characterIndex,
90 Length numberOfCharacters ) const;
93 * Retrieves a character.
95 * @param[in] characterIndex Index to a character.
97 * @return A character.
99 Character GetCharacter( CharacterIndex characterIndex ) const;
101 // Language support interface.
104 * Sets the script runs.
106 * Replaces any scripts previously set.
108 * A run is a group of consecutive characters. A script run contains the script for a run.
110 * @note If the number of runs is zero the script buffer is cleared.
112 * @param[in] scripts Pointer to a buffer with all the script runs.
113 * @param[in] numberOfRuns The number of script runs.
115 void SetScripts( const ScriptRun* const scripts,
116 Length numberOfRuns );
119 * Retrieves the number of script runs for the given range of characters.
121 * A run is a group of consecutive characters. A script run contains the script for a run.
123 * @param[in] characterIndex Index to the first character.
124 * @param[in] numberOfCharacters The number of characters.
126 * @return The number of script runs.
128 Length GetNumberOfScriptRuns( CharacterIndex characterIndex,
129 Length numberOfCharacters ) const;
132 * Retrieves the script runs for the given range of characters.
134 * The @p scriptRuns buffer needs to be big enough to copy the number of script runs.
135 * Call GetNumberOfScriptRuns() to retrieve the number of script runs.
137 * @param[out] scriptRuns Pointer to a buffer where the script runs are copied.
138 * @param[in] characterIndex Index to the first character.
139 * @param[in] numberOfCharacters The number of characters.
141 void GetScriptRuns( ScriptRun* scriptRuns,
142 CharacterIndex characterIndex,
143 Length numberOfCharacters ) const;
146 * Retrieves the script for the given character index.
148 * @param[in] characterIndex Index to the character.
150 * @return The character's script.
152 Script GetScript( CharacterIndex characterIndex ) const;
155 * Sets the font runs.
157 * Replaces any fonts previously set.
159 * A run is a group of consecutive characters. A font run contains the font id for a run.
161 * @note If the number of runs is zero the font buffer is cleared.
163 * @param[in] fonts Pointer to a buffer with all the font runs.
164 * @param[in] numberOfRuns The number of font runs.
166 void SetFonts( const FontRun* const fonts,
167 Length numberOfRuns );
170 * Retrieves the number of font runs for the given range of characters.
172 * A run is a group of consecutive characters. A font run contains the font id for a run.
174 * @param[in] characterIndex Index to the first character.
175 * @param[in] numberOfCharacters The number of characters.
177 * @return The number of font runs.
179 Length GetNumberOfFontRuns( CharacterIndex characterIndex,
180 Length numberOfCharacters ) const;
183 * Retrieves the font runs for the given range of characters.
185 * The @p fontRuns buffer needs to be big enough to copy the number of font runs.
186 * Call GetNumberOfFontRuns() to retrieve the number of font runs.
188 * @param[out] fontRuns Pointer to a buffer where the font runs are copied.
189 * @param[in] characterIndex Index to the first character.
190 * @param[in] numberOfCharacters The number of characters.
192 void GetFontRuns( FontRun* fontRuns,
193 CharacterIndex characterIndex,
194 Length numberOfCharacters ) const;
197 * Retrieves the font id for the given character index.
199 * @param[in] characterIndex Index to the first character.
201 * @return The font id.
203 FontId GetFont( CharacterIndex characterIndex ) const;
205 // Break info interface.
208 * Sets the line break info.
210 * See GetLineBreakInfo() to get how the line break info is encoded.
212 * Replaces any line break info previously set.
214 * @note If the @length is zero the break info buffer is cleared.
216 * @param[in] lineBreakInfo Pointer to a buffer with the line break info.
217 * @param[in] length The size of the buffer.
219 void SetLineBreakInfo( const LineBreakInfo* const lineBreakInfo,
223 * Retrieves the line break info in the given buffer.
225 * The size of the @p lineBreakInfo buffer needs to be big enough to copy the @p numberOfItems.
227 * Possible values for LineBreakInfo are:
229 * - 0 is a LINE_MUST_BREAK. Text must be broken into a new line.
230 * - 1 is a LINE_ALLOW_BREAK. Is possible to break the text into a new line.
231 * - 2 is a LINE_NO_BREAK. Text can't be broken into a new line.
234 i.e. Hello big\nworld produces:
238 * @param[out] lineBreakInfo Pointer to a buffer where the line break info is copied.
239 * @param[in] characterIndex Index to the first line break info item.
240 * @param[in] numberOfItems The number of items to be copied.
242 void GetLineBreakInfo( LineBreakInfo* lineBreakInfo,
243 CharacterIndex characterIndex,
244 Length numberOfItems ) const;
247 * Retrieves the line break info for the given item index.
249 * @param[in] characterIndex Index to the line break info item.
251 LineBreakInfo GetLineBreakInfo( CharacterIndex characterIndex ) const;
254 * Sets the word break info.
256 * See GetWordBreakInfo() to get how the word break info is encoded.
258 * Replaces any word break info previously set.
260 * @note If the @length is zero the break info buffer is cleared.
262 * @param[in] wordBreakInfo Pointer to a buffer with the word break info.
263 * @param[in] length The size of the buffer.
265 void SetWordBreakInfo( const WordBreakInfo* const wordBreakInfo,
269 * Retrieves the word break info in the given buffer.
271 * The size of the @p wordBreakInfo buffer needs to be big enough to copy the @p numberOfItems.
273 * The size of the buffer has to be big enough to store the whole word break info per character.
274 * Call GetNumberOfCharacters() to get the number of characters.
276 * Possible values for WordBreakInfo are:
278 * - 0 is a WORD_BREAK. Text can be broken into a new word.
279 * - 1 is a WORD_NO_BREAK. Text can't be broken into a new word.
282 i.e. Hello big\nworld produces:
286 * @param[out] wordBreakInfo Pointer to a buffer where the word break info is copied.
287 * @param[in] characterIndex Index to the first word break info item.
288 * @param[in] numberOfItems The number of items to be copied.
290 void GetWordBreakInfo( WordBreakInfo* wordBreakInfo,
291 CharacterIndex characterIndex,
292 Length numberOfItems ) const;
295 * Retrieves the word break info for the given item index.
297 * @param[in] characterIndex Index to the word break info item.
299 WordBreakInfo GetWordBreakInfo( CharacterIndex characterIndex ) const;
301 // Bidirectional support interface.
304 * Sets the bidirectional info runs.
306 * Replaces any bidirectional info previously set.
308 * Each bidirectional info run stores bidirectional info for a whole 'paragraph' of text which contains right to left scripts.
310 * In terms of the bidirectional algorithm, a 'paragraph' is understood as a run of characters between Paragraph Separators or appropriate Newline Functions.
311 * A 'paragraph' may also be determined by higher-level protocols like a mark-up tag.
313 * @note If the number of runs is zero the bidirectional info buffer is cleared.
315 * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
316 * @param[in] numberOfRuns The number of bidirectional info runs.
318 void SetBidirectionalInfo( const BidirectionalParagraphInfoRun* const bidirectionalInfo,
319 Length numberOfRuns );
322 * Retrieves the number of bidirectional info runs for the given range of characters.
324 * It may be zero if there is no right to left scripts.
326 * @param[in] characterIndex Index to the first character.
327 * @param[in] numberOfCharacters The number of characters.
329 * @return The number of bidirectional info runs.
331 Length GetNumberOfBidirectionalInfoRuns( CharacterIndex characterIndex,
332 Length numberOfCharacters ) const;
335 * Retrieves the direction of the characters.
337 * It sets @c true for right to left characters and @c false for left to right.
338 * For neutral characters it check's the next and previous character's directions:
339 * - If they are equals set that direction. If they are not, sets the paragraph's direction.
340 * - If there is no next, sets the paragraph's direction.
342 * See SetBidirectionalInfo() to get an explanation of the 'paragraph' meaning in the bidirectional algorithm.
344 * @param[out] directions Whether the characters are right to left or left to right.
345 * @param[in] characterIndex Index to the first character.
346 * @param[in] numberOfCharacters The number of characters.
348 void GetCharacterDirections( CharacterDirection* directions,
349 CharacterIndex characterIndex,
350 Length numberOfCharacters ) const;
353 * Retrieves the direction of a characters.
355 * See GetCharacterDirections().
357 * @param[in] characterIndex Index to a character.
359 * @return The character's direction.
361 CharacterDirection GetCharacterDirection( CharacterIndex characterIndex ) const;
363 // Visual <--> Logical conversion tables.
366 * Sets the visual to logical and the logical to visual map tables.
368 * Replaces any map tables previously set.
370 * @note If the number of runs is zero the bidirectional info buffer is cleared.
372 * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
373 * @param[in] numberOfRuns The number of bidirectional info runs.
375 void SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo,
376 Length numberOfRuns );
379 * Retrieves the visual character index for the given logical character index.
381 * @param[in] logicalCharacterIndex The logical character index.
383 * @return The visual character index.
385 CharacterIndex GetVisualCharacterIndex( CharacterIndex logicalCharacterIndex ) const;
388 * Retrieves the logical character index for the given visual character index.
390 * @param[in] visualCharacterIndex The visual character index.
392 * @return The logical character index.
394 CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const;
397 * Retrieves the whole or part of the logical to visual conversion map.
399 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
401 * @param[out] logicalToVisualMap Pointer to a buffer where the conversion map is copied.
402 * @param[in] characterIndex Index to the first character.
403 * @param[in] numberOfCharacters The number of characters.
405 void GetLogicalToVisualMap( CharacterIndex* logicalToVisualMap,
406 CharacterIndex characterIndex,
407 Length numberOfCharacters ) const;
410 * Retrieves the whole or part of the visual to logical conversion map.
412 * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
414 * @param[out] visualToLogicalMap Pointer to a buffer where the conversion map is copied.
415 * @param[in] characterIndex Index to the first character.
416 * @param[in] numberOfCharacters The number of characters.
418 void GetVisualToLogicalMap( CharacterIndex* visualToLogicalMap,
419 CharacterIndex characterIndex,
420 Length numberOfCharacters ) const;
425 * @brief A reference counted object may only be deleted by calling Unreference().
427 virtual ~LogicalModel();
432 * @brief Private constructor.
437 LogicalModel( const LogicalModel& handle );
440 LogicalModel& operator=( const LogicalModel& handle );
450 } // namespace Toolkit
454 #endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_H__