1 #ifndef DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H
2 #define DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H
5 * Copyright (c) 2019 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/bidirectional-line-info-run.h>
28 #include <dali-toolkit/internal/text/bidirectional-paragraph-info-run.h>
29 #include <dali-toolkit/internal/text/color-run.h>
30 #include <dali-toolkit/internal/text/embedded-item.h>
31 #include <dali-toolkit/internal/text/font-run.h>
32 #include <dali-toolkit/internal/text/font-description-run.h>
33 #include <dali-toolkit/internal/text/paragraph-run.h>
34 #include <dali-toolkit/internal/text/script-run.h>
46 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
50 * @brief A logical text model contains layout independent information.
53 * - A series of UTF-32 characters in logical order
55 class LogicalModel : public RefObject
60 * @brief Create a new instance of a LogicalModel.
62 * @return A pointer to a new LogicalModel.
64 static LogicalModelPtr New();
66 // Language support interface.
69 * @brief Retrieves the script for the given character index.
71 * @param[in] characterIndex Index to the character.
73 * @return The character's script.
75 Script GetScript( CharacterIndex characterIndex ) const;
77 // Bidirectional support interface.
80 * @brief Retrieves the direction of a characters.
82 * See GetCharacterDirections().
84 * @param[in] characterIndex Index to a character.
86 * @return The character's direction.
88 CharacterDirection GetCharacterDirection( CharacterIndex characterIndex ) const;
90 // Visual <--> Logical conversion tables.
93 * @brief Retrieves the logical cursor index for the given visual cursor index.
95 * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false,
96 * then the character is not in a bidirectional line and the result will be invalid.
98 * @param[in] visualCursorIndex The visual cursor index.
100 * @return The logical cursor index.
102 CharacterIndex GetLogicalCursorIndex( CharacterIndex visualCursorIndex );
105 * @brief Retrieves the logical character index for the given visual character index.
107 * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false,
108 * then the character is not in a bidirectional line and the result will be invalid.
110 * @param[in] visualCharacterIndex The visual character index.
112 * @return The logical character index.
114 CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex );
117 * @brief Fetch the bidirectional line info for the given character.
119 * Call GetBidirectionalLineInfo() to retrieve the last fetched line.
121 * @param[in] characterIndex The character index.
123 * @return @e true if the given @e character is in a bidirectional line.
125 bool FetchBidirectionalLineInfo( CharacterIndex characterIndex );
128 * @brief Retrieves the last fetched bidirectional line info.
130 * @return The index of the bidirectional line info.
132 BidirectionalLineRunIndex GetBidirectionalLineInfo() const;
137 * @brief Updates the text's style runs with the added or removed text.
139 * @param[in] index The character's index.
140 * @param[in] numberOfCharacters The number of characters added or removed. If the value is negative the characters are removed.
142 void UpdateTextStyleRuns( CharacterIndex index, int numberOfCharacters );
145 * @brief Retrieves the text's style for the given character index.
147 * @param[in] index The character index.
148 * @param[out] style The text's style in the given style.
150 void RetrieveStyle( CharacterIndex index, InputStyle& style );
153 * @brief Clears the font description runs.
155 void ClearFontDescriptionRuns();
160 * @brief Creates the paragraph info.
162 * @pre The line break info must be set.
164 * @param[in] startIndex The character from where the paragraph info is set.
165 * @param[in] numberOfCharacters The number of characters.
167 void CreateParagraphInfo( CharacterIndex startIndex,
168 Length numberOfCharacters );
171 * @brief Find the paragraphs which contains the given characters.
173 * @param[in] index The first character's index of the run.
174 * @param[in] numberOfCharacters The number of characters of the run.
175 * @param[out] paragraphs Indices to the paragraphs which contain the characters.
177 void FindParagraphs( CharacterIndex index,
178 Length numberOfCharacters,
179 Vector<ParagraphRunIndex>& paragraphs );
184 * @brief Clears the embedded images.
186 void ClearEmbeddedImages();
191 * @brief A reference counted object may only be deleted by calling Unreference().
193 virtual ~LogicalModel();
198 * @brief Private constructor.
203 LogicalModel( const LogicalModel& handle );
206 LogicalModel& operator=( const LogicalModel& handle );
210 Vector<Character> mText;
211 Vector<ScriptRun> mScriptRuns;
212 Vector<FontRun> mFontRuns;
213 Vector<ColorRun> mColorRuns;
214 Vector<ColorRun> mBackgroundColorRuns;
215 Vector<FontDescriptionRun> mFontDescriptionRuns;
216 Vector<LineBreakInfo> mLineBreakInfo;
217 Vector<ParagraphRun> mParagraphInfo;
218 Vector<BidirectionalParagraphInfoRun> mBidirectionalParagraphInfo;
219 Vector<CharacterDirection> mCharacterDirections; ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ).
220 Vector<BidirectionalLineInfoRun> mBidirectionalLineInfo;
221 Vector<EmbeddedItem> mEmbeddedItems;
223 BidirectionalLineRunIndex mBidirectionalLineIndex; ///< The last fetched bidirectional line info.
228 } // namespace Toolkit
232 #endif // DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H