TextModel - Remove the visual to logical conversion tables.
[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) 2015 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/font-run.h>
31 #include <dali-toolkit/internal/text/font-description-run.h>
32 #include <dali-toolkit/internal/text/paragraph-run.h>
33 #include <dali-toolkit/internal/text/script-run.h>
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Text
42 {
43
44 class LogicalModel;
45 typedef IntrusivePtr<LogicalModel> LogicalModelPtr;
46 struct InputStyle;
47
48 /**
49  * @brief A logical text model contains layout independent information.
50  *
51  * This includes:
52  * - A series of UTF-32 characters in logical order
53  */
54 class LogicalModel : public RefObject
55 {
56 public:
57
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    * @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    * @param[in] visualCharacterIndex The visual character index.
104    *
105    * @return The logical character index.
106    */
107   CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex );
108
109   /**
110    * @brief Fetch the bidirectional line info for the given character.
111    *
112    * Call GetBidirectionalLineInfo() to retrieve the last fetched line.
113    *
114    * @param[in] characterIndex The character index.
115    *
116    * @return @e true if the given @e character is in a bidirectional line.
117    */
118   bool FetchBidirectionalLineInfo( CharacterIndex characterIndex );
119
120   /**
121    * @brief Retrieves the last fetched bidirectional line info.
122    *
123    * @return The index of the bidirectional line info.
124    */
125   BidirectionalLineRunIndex GetBidirectionalLineInfo() const;
126
127   // Text style.
128
129   /**
130    * @brief Updates the text's style runs with the added or removed text.
131    *
132    * @param[in] index The character's index.
133    * @param[in] numberOfCharacters The number of characters added or removed. If the value is negative the characters are removed.
134    */
135   void UpdateTextStyleRuns( CharacterIndex index, int numberOfCharacters );
136
137   /**
138    * @brief Retrieves the text's style for the given character index.
139    *
140    * @param[in] index The character index.
141    * @param[out] style The text's style in the given style.
142    */
143   void RetrieveStyle( CharacterIndex index, InputStyle& style );
144
145   /**
146    * @brief Clears the font description runs.
147    */
148   void ClearFontDescriptionRuns();
149
150   // Paragraphs
151
152   /**
153    * @brief Creates the paragraph info.
154    *
155    * @pre The line break info must be set.
156    *
157    * @param[in] startIndex The character from where the paragraph info is set.
158    * @param[in] numberOfCharacters The number of characters.
159    */
160   void CreateParagraphInfo( CharacterIndex startIndex,
161                             Length numberOfCharacters );
162
163   /**
164    * @brief Find the paragraphs which contains the given characters.
165    *
166    * @param[in] index The first character's index of the run.
167    * @param[in] numberOfCharacters The number of characters of the run.
168    * @param[out] paragraphs Indices to the paragraphs which contain the characters.
169    */
170   void FindParagraphs( CharacterIndex index,
171                        Length numberOfCharacters,
172                        Vector<ParagraphRunIndex>& paragraphs );
173
174 protected:
175
176   /**
177    * @brief A reference counted object may only be deleted by calling Unreference().
178    */
179   virtual ~LogicalModel();
180
181 private:
182
183   /**
184    * @brief Private constructor.
185    */
186   LogicalModel();
187
188   // Undefined
189   LogicalModel( const LogicalModel& handle );
190
191   // Undefined
192   LogicalModel& operator=( const LogicalModel& handle );
193
194 public:
195
196   Vector<Character>                     mText;
197   Vector<ScriptRun>                     mScriptRuns;
198   Vector<FontRun>                       mFontRuns;
199   Vector<ColorRun>                      mColorRuns;
200   Vector<FontDescriptionRun>            mFontDescriptionRuns;
201   Vector<LineBreakInfo>                 mLineBreakInfo;
202   Vector<WordBreakInfo>                 mWordBreakInfo;
203   Vector<ParagraphRun>                  mParagraphInfo;
204   Vector<BidirectionalParagraphInfoRun> mBidirectionalParagraphInfo;
205   Vector<CharacterDirection>            mCharacterDirections;              ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ).
206   Vector<BidirectionalLineInfoRun>      mBidirectionalLineInfo;
207
208   BidirectionalLineRunIndex             mBidirectionalLineIndex;           ///< The last fetched bidirectional line info.
209 };
210
211 } // namespace Text
212
213 } // namespace Toolkit
214
215 } // namespace Dali
216
217 #endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H__