1 #ifndef DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H
2 #define DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H
5 * Copyright (c) 2022 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/anchor.h>
28 #include <dali-toolkit/internal/text/bidirectional-line-info-run.h>
29 #include <dali-toolkit/internal/text/bidirectional-paragraph-info-run.h>
30 #include <dali-toolkit/internal/text/bounded-paragraph-run.h>
31 #include <dali-toolkit/internal/text/character-spacing-character-run.h>
32 #include <dali-toolkit/internal/text/color-run.h>
33 #include <dali-toolkit/internal/text/embedded-item.h>
34 #include <dali-toolkit/internal/text/font-description-run.h>
35 #include <dali-toolkit/internal/text/font-run.h>
36 #include <dali-toolkit/internal/text/paragraph-run.h>
37 #include <dali-toolkit/internal/text/script-run.h>
38 #include <dali-toolkit/internal/text/strikethrough-character-run.h>
39 #include <dali-toolkit/internal/text/underlined-character-run.h>
48 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
52 * @brief A logical text model contains layout independent information.
55 * - A series of UTF-32 characters in logical order
57 class LogicalModel : public RefObject
61 * @brief Create a new instance of a LogicalModel.
63 * @return A pointer to a new LogicalModel.
65 static LogicalModelPtr New();
67 // Language support interface.
70 * @brief Retrieves the script for the given character index.
72 * @param[in] characterIndex Index to the character.
74 * @return The character's script.
76 Script GetScript(CharacterIndex characterIndex) const;
78 // Bidirectional support interface.
81 * @brief Retrieves the direction of a characters.
83 * See GetCharacterDirections().
85 * @param[in] characterIndex Index to a character.
87 * @return The character's direction.
89 CharacterDirection GetCharacterDirection(CharacterIndex characterIndex) const;
91 // Visual <--> Logical conversion tables.
94 * @brief Retrieves the logical cursor index for the given visual cursor index.
96 * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false,
97 * then the character is not in a bidirectional line and the result will be invalid.
99 * @param[in] visualCursorIndex The visual cursor index.
101 * @return The logical cursor index.
103 CharacterIndex GetLogicalCursorIndex(CharacterIndex visualCursorIndex);
106 * @brief Retrieves the logical character index for the given visual character index.
108 * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false,
109 * then the character is not in a bidirectional line and the result will be invalid.
111 * @param[in] visualCharacterIndex The visual character index.
113 * @return The logical character index.
115 CharacterIndex GetLogicalCharacterIndex(CharacterIndex visualCharacterIndex);
118 * @brief Fetch the bidirectional line info for the given character.
120 * Call GetBidirectionalLineInfo() to retrieve the last fetched line.
122 * @param[in] characterIndex The character index.
124 * @return @e true if the given @e character is in a bidirectional line.
126 bool FetchBidirectionalLineInfo(CharacterIndex characterIndex);
129 * @brief Retrieves the last fetched bidirectional line info.
131 * @return The index of the bidirectional line info.
133 BidirectionalLineRunIndex GetBidirectionalLineInfo() const;
138 * @brief Updates the text's style runs with the added or removed text.
140 * @param[in] index The character's index.
141 * @param[in] numberOfCharacters The number of characters added or removed. If the value is negative the characters are removed.
143 void UpdateTextStyleRuns(CharacterIndex index, int numberOfCharacters);
146 * @brief Retrieves the text's style for the given character index.
148 * @param[in] index The character index.
149 * @param[out] style The text's style in the given style.
151 void RetrieveStyle(CharacterIndex index, InputStyle& style);
154 * @brief Clears the font description runs.
156 void ClearFontDescriptionRuns();
159 * @brief Clears the strikethrough runs.
161 void ClearStrikethroughRuns();
164 * @brief Clears the underline runs.
166 void ClearUnderlineRuns();
171 * @brief Creates the paragraph info.
173 * @pre The line break info must be set.
175 * @param[in] startIndex The character from where the paragraph info is set.
176 * @param[in] numberOfCharacters The number of characters.
178 void CreateParagraphInfo(CharacterIndex startIndex,
179 Length numberOfCharacters);
182 * @brief Find the paragraphs which contains the given characters.
184 * @param[in] index The first character's index of the run.
185 * @param[in] numberOfCharacters The number of characters of the run.
186 * @param[out] paragraphs Indices to the paragraphs which contain the characters.
188 void FindParagraphs(CharacterIndex index,
189 Length numberOfCharacters,
190 Vector<ParagraphRunIndex>& paragraphs);
193 * @brief Retrieves the number of bounded paragraph runs.
195 * @return The number of bounded paragraph runs.
197 Length GetNumberOfBoundedParagraphRuns() const;
200 * @brief Retrieves the reference for bounded paragraph runs.
202 * @return The reference for bounded paragraph runs.
204 const Vector<BoundedParagraphRun>& GetBoundedParagraphRuns() const;
207 * @brief Retrieves the number of character-spacing runs.
209 * @return The number of character-spacing runs.
211 Length GetNumberOfCharacterSpacingCharacterRuns() const;
214 * @brief Retrieves the reference for character-spacing runs.
216 * @return The reference for character-spacing runs.
218 const Vector<CharacterSpacingCharacterRun>& GetCharacterSpacingCharacterRuns() const;
223 * @brief Clears the embedded images.
225 void ClearEmbeddedImages();
228 * @brief Clears the anchors.
234 * @brief A reference counted object may only be deleted by calling Unreference().
236 virtual ~LogicalModel();
240 * @brief Private constructor.
245 LogicalModel(const LogicalModel& handle);
248 LogicalModel& operator=(const LogicalModel& handle);
251 Vector<Character> mText;
252 Vector<ScriptRun> mScriptRuns;
253 Vector<FontRun> mFontRuns;
254 Vector<ColorRun> mColorRuns;
255 Vector<ColorRun> mBackgroundColorRuns;
256 Vector<FontDescriptionRun> mFontDescriptionRuns;
257 Vector<LineBreakInfo> mLineBreakInfo;
258 Vector<ParagraphRun> mParagraphInfo;
259 Vector<BidirectionalParagraphInfoRun> mBidirectionalParagraphInfo;
260 Vector<CharacterDirection> mCharacterDirections; ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ).
261 Vector<BidirectionalLineInfoRun> mBidirectionalLineInfo;
262 Vector<EmbeddedItem> mEmbeddedItems;
263 Vector<Anchor> mAnchors;
264 Vector<UnderlinedCharacterRun> mUnderlinedCharacterRuns; ///< The underlined character run from markup-processor
265 Vector<StrikethroughCharacterRun> mStrikethroughCharacterRuns; ///< The strikethrough character run from markup-processor
266 Vector<BoundedParagraphRun> mBoundedParagraphRuns; ///< The bounded paragraph is used to handle a paragraph mark-up tag and it's attributes. Like TextAlign, TextDirection, TextIndent, LineHeight, etc.
267 Vector<CharacterSpacingCharacterRun> mCharacterSpacingCharacterRuns; ///< The character-spacing character run from markup-processor.
269 BidirectionalLineRunIndex mBidirectionalLineIndex; ///< The last fetched bidirectional line info.
270 bool mSpannedTextPlaced : 1; ///< Whether the spanned-text is placed.
272 bool mUnderlineRunsUpdated : 1; /// Whether the UnderlinedCharacterRuns is updated. (Added for SpannedText)
273 bool mCharacterSpacingRunsUpdated : 1; // Flag for updating character-spacing.
274 bool mStrikethroughRunsUpdated : 1; /// Whether the StrikethroughCharacterRuns is updated. (Added for SpannedText)
279 } // namespace Toolkit
283 #endif // DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H