08c636d11fb620a2ab786809d82d1b4ceeefc7a8
[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/color-run.h>
31 #include <dali-toolkit/internal/text/embedded-item.h>
32 #include <dali-toolkit/internal/text/font-description-run.h>
33 #include <dali-toolkit/internal/text/font-run.h>
34 #include <dali-toolkit/internal/text/paragraph-run.h>
35 #include <dali-toolkit/internal/text/script-run.h>
36 #include <dali-toolkit/internal/text/strikethrough-character-run.h>
37 #include <dali-toolkit/internal/text/underlined-character-run.h>
38
39 namespace Dali
40 {
41 namespace Toolkit
42 {
43 namespace Text
44 {
45 class LogicalModel;
46 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
47 struct InputStyle;
48
49 /**
50  * @brief A logical text model contains layout independent information.
51  *
52  * This includes:
53  * - A series of UTF-32 characters in logical order
54  */
55 class LogicalModel : public RefObject
56 {
57 public:
58   /**
59    * @brief Create a new instance of a LogicalModel.
60    *
61    * @return A pointer to a new LogicalModel.
62    */
63   static LogicalModelPtr New();
64
65   // Language support interface.
66
67   /**
68    * @brief Retrieves the script for the given character index.
69    *
70    * @param[in] characterIndex Index to the character.
71    *
72    * @return The character's script.
73    */
74   Script GetScript(CharacterIndex characterIndex) const;
75
76   // Bidirectional support interface.
77
78   /**
79    * @brief Retrieves the direction of a characters.
80    *
81    * See GetCharacterDirections().
82    *
83    * @param[in] characterIndex Index to a character.
84    *
85    * @return The character's direction.
86    */
87   CharacterDirection GetCharacterDirection(CharacterIndex characterIndex) const;
88
89   // Visual <--> Logical conversion tables.
90
91   /**
92    * @brief Retrieves the logical cursor index for the given visual cursor index.
93    *
94    * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false,
95    *      then the character is not in a bidirectional line and the result will be invalid.
96    *
97    * @param[in] visualCursorIndex The visual cursor index.
98    *
99    * @return The logical cursor index.
100    */
101   CharacterIndex GetLogicalCursorIndex(CharacterIndex visualCursorIndex);
102
103   /**
104    * @brief Retrieves the logical character index for the given visual character index.
105    *
106    * @pre The method FetchBidirectionalLineInfo() must be called before. If the result of FetchBidirectionalLineInfo() is false,
107    *      then the character is not in a bidirectional line and the result will be invalid.
108    *
109    * @param[in] visualCharacterIndex The visual character index.
110    *
111    * @return The logical character index.
112    */
113   CharacterIndex GetLogicalCharacterIndex(CharacterIndex visualCharacterIndex);
114
115   /**
116    * @brief Fetch the bidirectional line info for the given character.
117    *
118    * Call GetBidirectionalLineInfo() to retrieve the last fetched line.
119    *
120    * @param[in] characterIndex The character index.
121    *
122    * @return @e true if the given @e character is in a bidirectional line.
123    */
124   bool FetchBidirectionalLineInfo(CharacterIndex characterIndex);
125
126   /**
127    * @brief Retrieves the last fetched bidirectional line info.
128    *
129    * @return The index of the bidirectional line info.
130    */
131   BidirectionalLineRunIndex GetBidirectionalLineInfo() const;
132
133   // Text style.
134
135   /**
136    * @brief Updates the text's style runs with the added or removed text.
137    *
138    * @param[in] index The character's index.
139    * @param[in] numberOfCharacters The number of characters added or removed. If the value is negative the characters are removed.
140    */
141   void UpdateTextStyleRuns(CharacterIndex index, int numberOfCharacters);
142
143   /**
144    * @brief Retrieves the text's style for the given character index.
145    *
146    * @param[in] index The character index.
147    * @param[out] style The text's style in the given style.
148    */
149   void RetrieveStyle(CharacterIndex index, InputStyle& style);
150
151   /**
152    * @brief Clears the font description runs.
153    */
154   void ClearFontDescriptionRuns();
155
156   /**
157    * @brief Clears the strikethrough runs.
158    */
159   void ClearStrikethroughRuns();
160
161   // Paragraphs
162
163   /**
164    * @brief Creates the paragraph info.
165    *
166    * @pre The line break info must be set.
167    *
168    * @param[in] startIndex The character from where the paragraph info is set.
169    * @param[in] numberOfCharacters The number of characters.
170    */
171   void CreateParagraphInfo(CharacterIndex startIndex,
172                            Length         numberOfCharacters);
173
174   /**
175    * @brief Find the paragraphs which contains the given characters.
176    *
177    * @param[in] index The first character's index of the run.
178    * @param[in] numberOfCharacters The number of characters of the run.
179    * @param[out] paragraphs Indices to the paragraphs which contain the characters.
180    */
181   void FindParagraphs(CharacterIndex             index,
182                       Length                     numberOfCharacters,
183                       Vector<ParagraphRunIndex>& paragraphs);
184
185   // Embedded images
186
187   /**
188    * @brief Clears the embedded images.
189    */
190   void ClearEmbeddedImages();
191
192   /**
193    * @brief Clears the anchors.
194    */
195   void ClearAnchors();
196
197 protected:
198   /**
199    * @brief A reference counted object may only be deleted by calling Unreference().
200    */
201   virtual ~LogicalModel();
202
203 private:
204   /**
205    * @brief Private constructor.
206    */
207   LogicalModel();
208
209   // Undefined
210   LogicalModel(const LogicalModel& handle);
211
212   // Undefined
213   LogicalModel& operator=(const LogicalModel& handle);
214
215 public:
216   Vector<Character>                     mText;
217   Vector<ScriptRun>                     mScriptRuns;
218   Vector<FontRun>                       mFontRuns;
219   Vector<ColorRun>                      mColorRuns;
220   Vector<ColorRun>                      mBackgroundColorRuns;
221   Vector<FontDescriptionRun>            mFontDescriptionRuns;
222   Vector<LineBreakInfo>                 mLineBreakInfo;
223   Vector<ParagraphRun>                  mParagraphInfo;
224   Vector<BidirectionalParagraphInfoRun> mBidirectionalParagraphInfo;
225   Vector<CharacterDirection>            mCharacterDirections; ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ).
226   Vector<BidirectionalLineInfoRun>      mBidirectionalLineInfo;
227   Vector<EmbeddedItem>                  mEmbeddedItems;
228   Vector<Anchor>                        mAnchors;
229   Vector<UnderlinedCharacterRun>        mUnderlinedCharacterRuns;    ///< The underlined character run from markup-processor
230   Vector<StrikethroughCharacterRun>     mStrikethroughCharacterRuns; ///< The strikethrough character run from markup-processor
231
232   BidirectionalLineRunIndex mBidirectionalLineIndex; ///< The last fetched bidirectional line info.
233 };
234
235 } // namespace Text
236
237 } // namespace Toolkit
238
239 } // namespace Dali
240
241 #endif // DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H