1 #ifndef DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H
2 #define DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H
5 * Copyright (c) 2021 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-description-run.h>
32 #include <dali-toolkit/internal/text/font-run.h>
33 #include <dali-toolkit/internal/text/paragraph-run.h>
34 #include <dali-toolkit/internal/text/script-run.h>
43 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
47 * @brief A logical text model contains layout independent information.
50 * - A series of UTF-32 characters in logical order
52 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();
62 // Language support interface.
65 * @brief Retrieves the script for the given character index.
67 * @param[in] characterIndex Index to the character.
69 * @return The character's script.
71 Script GetScript(CharacterIndex characterIndex) const;
73 // Bidirectional support interface.
76 * @brief Retrieves the direction of a characters.
78 * See GetCharacterDirections().
80 * @param[in] characterIndex Index to a character.
82 * @return The character's direction.
84 CharacterDirection GetCharacterDirection(CharacterIndex characterIndex) const;
86 // Visual <--> Logical conversion tables.
89 * @brief Retrieves the logical cursor index for the given visual cursor index.
91 * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false,
92 * then the character is not in a bidirectional line and the result will be invalid.
94 * @param[in] visualCursorIndex The visual cursor index.
96 * @return The logical cursor index.
98 CharacterIndex GetLogicalCursorIndex(CharacterIndex visualCursorIndex);
101 * @brief Retrieves the logical character index for the given visual character index.
103 * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false,
104 * then the character is not in a bidirectional line and the result will be invalid.
106 * @param[in] visualCharacterIndex The visual character index.
108 * @return The logical character index.
110 CharacterIndex GetLogicalCharacterIndex(CharacterIndex visualCharacterIndex);
113 * @brief Fetch the bidirectional line info for the given character.
115 * Call GetBidirectionalLineInfo() to retrieve the last fetched line.
117 * @param[in] characterIndex The character index.
119 * @return @e true if the given @e character is in a bidirectional line.
121 bool FetchBidirectionalLineInfo(CharacterIndex characterIndex);
124 * @brief Retrieves the last fetched bidirectional line info.
126 * @return The index of the bidirectional line info.
128 BidirectionalLineRunIndex GetBidirectionalLineInfo() const;
133 * @brief Updates the text's style runs with the added or removed text.
135 * @param[in] index The character's index.
136 * @param[in] numberOfCharacters The number of characters added or removed. If the value is negative the characters are removed.
138 void UpdateTextStyleRuns(CharacterIndex index, int numberOfCharacters);
141 * @brief Retrieves the text's style for the given character index.
143 * @param[in] index The character index.
144 * @param[out] style The text's style in the given style.
146 void RetrieveStyle(CharacterIndex index, InputStyle& style);
149 * @brief Clears the font description runs.
151 void ClearFontDescriptionRuns();
156 * @brief Creates the paragraph info.
158 * @pre The line break info must be set.
160 * @param[in] startIndex The character from where the paragraph info is set.
161 * @param[in] numberOfCharacters The number of characters.
163 void CreateParagraphInfo(CharacterIndex startIndex,
164 Length numberOfCharacters);
167 * @brief Find the paragraphs which contains the given characters.
169 * @param[in] index The first character's index of the run.
170 * @param[in] numberOfCharacters The number of characters of the run.
171 * @param[out] paragraphs Indices to the paragraphs which contain the characters.
173 void FindParagraphs(CharacterIndex index,
174 Length numberOfCharacters,
175 Vector<ParagraphRunIndex>& paragraphs);
180 * @brief Clears the embedded images.
182 void ClearEmbeddedImages();
186 * @brief A reference counted object may only be deleted by calling Unreference().
188 virtual ~LogicalModel();
192 * @brief Private constructor.
197 LogicalModel(const LogicalModel& handle);
200 LogicalModel& operator=(const LogicalModel& handle);
203 Vector<Character> mText;
204 Vector<ScriptRun> mScriptRuns;
205 Vector<FontRun> mFontRuns;
206 Vector<ColorRun> mColorRuns;
207 Vector<ColorRun> mBackgroundColorRuns;
208 Vector<FontDescriptionRun> mFontDescriptionRuns;
209 Vector<LineBreakInfo> mLineBreakInfo;
210 Vector<ParagraphRun> mParagraphInfo;
211 Vector<BidirectionalParagraphInfoRun> mBidirectionalParagraphInfo;
212 Vector<CharacterDirection> mCharacterDirections; ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ).
213 Vector<BidirectionalLineInfoRun> mBidirectionalLineInfo;
214 Vector<EmbeddedItem> mEmbeddedItems;
216 BidirectionalLineRunIndex mBidirectionalLineIndex; ///< The last fetched bidirectional line info.
221 } // namespace Toolkit
225 #endif // DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H