[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / logical-model-impl.h
1 #ifndef DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H
2 #define DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
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
26 // INTERNAL INCLUDES
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>
40
41 namespace Dali
42 {
43 namespace Toolkit
44 {
45 namespace Text
46 {
47 class LogicalModel;
48 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
49 struct InputStyle;
50
51 /**
52  * @brief A logical text model contains layout independent information.
53  *
54  * This includes:
55  * - A series of UTF-32 characters in logical order
56  */
57 class LogicalModel : public RefObject
58 {
59 public:
60   /**
61    * @brief Create a new instance of a LogicalModel.
62    *
63    * @return A pointer to a new LogicalModel.
64    */
65   static LogicalModelPtr New();
66
67   // Language support interface.
68
69   /**
70    * @brief Retrieves the script for the given character index.
71    *
72    * @param[in] characterIndex Index to the character.
73    *
74    * @return The character's script.
75    */
76   Script GetScript(CharacterIndex characterIndex) const;
77
78   // Bidirectional support interface.
79
80   /**
81    * @brief Retrieves the direction of a characters.
82    *
83    * See GetCharacterDirections().
84    *
85    * @param[in] characterIndex Index to a character.
86    *
87    * @return The character's direction.
88    */
89   CharacterDirection GetCharacterDirection(CharacterIndex characterIndex) const;
90
91   // Visual <--> Logical conversion tables.
92
93   /**
94    * @brief Retrieves the logical cursor index for the given visual cursor index.
95    *
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.
98    *
99    * @param[in] visualCursorIndex The visual cursor index.
100    *
101    * @return The logical cursor index.
102    */
103   CharacterIndex GetLogicalCursorIndex(CharacterIndex visualCursorIndex);
104
105   /**
106    * @brief Retrieves the logical character index for the given visual character index.
107    *
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.
110    *
111    * @param[in] visualCharacterIndex The visual character index.
112    *
113    * @return The logical character index.
114    */
115   CharacterIndex GetLogicalCharacterIndex(CharacterIndex visualCharacterIndex);
116
117   /**
118    * @brief Fetch the bidirectional line info for the given character.
119    *
120    * Call GetBidirectionalLineInfo() to retrieve the last fetched line.
121    *
122    * @param[in] characterIndex The character index.
123    *
124    * @return @e true if the given @e character is in a bidirectional line.
125    */
126   bool FetchBidirectionalLineInfo(CharacterIndex characterIndex);
127
128   /**
129    * @brief Retrieves the last fetched bidirectional line info.
130    *
131    * @return The index of the bidirectional line info.
132    */
133   BidirectionalLineRunIndex GetBidirectionalLineInfo() const;
134
135   // Text style.
136
137   /**
138    * @brief Updates the text's style runs with the added or removed text.
139    *
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.
142    */
143   void UpdateTextStyleRuns(CharacterIndex index, int numberOfCharacters);
144
145   /**
146    * @brief Retrieves the text's style for the given character index.
147    *
148    * @param[in] index The character index.
149    * @param[out] style The text's style in the given style.
150    */
151   void RetrieveStyle(CharacterIndex index, InputStyle& style);
152
153   /**
154    * @brief Clears the font description runs.
155    */
156   void ClearFontDescriptionRuns();
157
158   /**
159    * @brief Clears the strikethrough runs.
160    */
161   void ClearStrikethroughRuns();
162
163   // Paragraphs
164
165   /**
166    * @brief Creates the paragraph info.
167    *
168    * @pre The line break info must be set.
169    *
170    * @param[in] startIndex The character from where the paragraph info is set.
171    * @param[in] numberOfCharacters The number of characters.
172    */
173   void CreateParagraphInfo(CharacterIndex startIndex,
174                            Length         numberOfCharacters);
175
176   /**
177    * @brief Find the paragraphs which contains the given characters.
178    *
179    * @param[in] index The first character's index of the run.
180    * @param[in] numberOfCharacters The number of characters of the run.
181    * @param[out] paragraphs Indices to the paragraphs which contain the characters.
182    */
183   void FindParagraphs(CharacterIndex             index,
184                       Length                     numberOfCharacters,
185                       Vector<ParagraphRunIndex>& paragraphs);
186
187   /**
188    * @brief Retrieves the number of bounded paragraph runs.
189    *
190    * @return The number of bounded paragraph runs.
191    */
192   Length GetNumberOfBoundedParagraphRuns() const;
193
194   /**
195    * @brief Retrieves the reference for bounded paragraph runs.
196    *
197    * @return The reference for bounded paragraph runs.
198    */
199   const Vector<BoundedParagraphRun>& GetBoundedParagraphRuns() const;
200
201   /**
202    * @brief Retrieves the number of character-spacing runs.
203    *
204    * @return The number of character-spacing runs.
205    */
206   Length GetNumberOfCharacterSpacingCharacterRuns() const;
207
208   /**
209    * @brief Retrieves the reference for character-spacing runs.
210    *
211    * @return The reference for character-spacing runs.
212    */
213   const Vector<CharacterSpacingCharacterRun>& GetCharacterSpacingCharacterRuns() const;
214
215   // Embedded images
216
217   /**
218    * @brief Clears the embedded images.
219    */
220   void ClearEmbeddedImages();
221
222   /**
223    * @brief Clears the anchors.
224    */
225   void ClearAnchors();
226
227 protected:
228   /**
229    * @brief A reference counted object may only be deleted by calling Unreference().
230    */
231   virtual ~LogicalModel();
232
233 private:
234   /**
235    * @brief Private constructor.
236    */
237   LogicalModel();
238
239   // Undefined
240   LogicalModel(const LogicalModel& handle);
241
242   // Undefined
243   LogicalModel& operator=(const LogicalModel& handle);
244
245 public:
246   Vector<Character>                     mText;
247   Vector<ScriptRun>                     mScriptRuns;
248   Vector<FontRun>                       mFontRuns;
249   Vector<ColorRun>                      mColorRuns;
250   Vector<ColorRun>                      mBackgroundColorRuns;
251   Vector<FontDescriptionRun>            mFontDescriptionRuns;
252   Vector<LineBreakInfo>                 mLineBreakInfo;
253   Vector<ParagraphRun>                  mParagraphInfo;
254   Vector<BidirectionalParagraphInfoRun> mBidirectionalParagraphInfo;
255   Vector<CharacterDirection>            mCharacterDirections; ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ).
256   Vector<BidirectionalLineInfoRun>      mBidirectionalLineInfo;
257   Vector<EmbeddedItem>                  mEmbeddedItems;
258   Vector<Anchor>                        mAnchors;
259   Vector<UnderlinedCharacterRun>        mUnderlinedCharacterRuns;       ///< The underlined character run from markup-processor
260   Vector<StrikethroughCharacterRun>     mStrikethroughCharacterRuns;    ///< The strikethrough character run from markup-processor
261   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.
262   Vector<CharacterSpacingCharacterRun>  mCharacterSpacingCharacterRuns; ///< The character-spacing character run from markup-processor.
263
264   BidirectionalLineRunIndex mBidirectionalLineIndex; ///< The last fetched bidirectional line info.
265   bool                      mSpannedTextPlaced : 1;  ///< Whether the spanned-text is placed.
266
267   bool mUnderlineRunsUpdated : 1;        /// Whether the UnderlinedCharacterRuns is updated. (Added for SpannedText)
268   bool mCharacterSpacingRunsUpdated : 1; // Flag for updating character-spacing.
269   bool mStrikethroughRunsUpdated : 1;    /// Whether the StrikethroughCharacterRuns is updated. (Added for SpannedText)
270 };
271
272 } // namespace Text
273
274 } // namespace Toolkit
275
276 } // namespace Dali
277
278 #endif // DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H