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