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