Fix for text renderer. Set the right size in order to cull the actor correctly.
[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/script-run.h>
33
34 namespace Dali
35 {
36
37 namespace Toolkit
38 {
39
40 namespace Text
41 {
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   /**
58    * @brief Create a new instance of a LogicalModel.
59    *
60    * @return A pointer to a new LogicalModel.
61    */
62   static LogicalModelPtr New();
63
64   // Language support interface.
65
66   /**
67    * @brief Retrieves the script for the given character index.
68    *
69    * @param[in] characterIndex Index to the character.
70    *
71    * @return The character's script.
72    */
73   Script GetScript( CharacterIndex characterIndex ) const;
74
75   // Bidirectional support interface.
76
77   /**
78    * @brief Retrieves the direction of a characters.
79    *
80    * See GetCharacterDirections().
81    *
82    * @param[in] characterIndex Index to a character.
83    *
84    * @return The character's direction.
85    */
86   CharacterDirection GetCharacterDirection( CharacterIndex characterIndex ) const;
87
88   // Visual <--> Logical conversion tables.
89
90   /**
91    * @brief Sets the visual to logical and the logical to visual map tables.
92    *
93    * Replaces any map tables previously set.
94    *
95    * @note If the number of runs is zero the bidirectional info buffer is cleared.
96    *
97    * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
98    * @param[in] numberOfRuns The number of bidirectional info runs.
99    * @param[in] startIndex Character index from where the conversion tables are set.
100    * @param[in] numberOfCharacters The number of characters.
101    */
102   void SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo,
103                               Length numberOfRuns,
104                               CharacterIndex startIndex,
105                               Length numberOfCharacters );
106
107   /**
108    * @brief Retrieves the logical character index for the given visual character index.
109    *
110    * @param[in] visualCharacterIndex The visual character index.
111    *
112    * @return The logical character index.
113    */
114   CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const;
115
116   // Text style.
117
118   /**
119    * @brief Updates the text's style runs with the added or removed text.
120    *
121    * @param[in] index The character's index.
122    * @param[in] numberOfCharacters The number of characters added or removed. If the value is negative the characters are removed.
123    */
124   void UpdateTextStyleRuns( CharacterIndex index, int numberOfCharacters );
125
126   /**
127    * @brief Retrieves the text's style for the given character index.
128    *
129    * @param[in] index The character index.
130    * @param[out] style The text's style in the given style.
131    */
132   void RetrieveStyle( CharacterIndex index, InputStyle& style );
133
134   /**
135    * @brief Clears the font description runs.
136    */
137   void ClearFontDescriptionRuns();
138
139 protected:
140
141   /**
142    * @brief A reference counted object may only be deleted by calling Unreference().
143    */
144   virtual ~LogicalModel();
145
146 private:
147
148   /**
149    * @brief Private constructor.
150    */
151   LogicalModel();
152
153   // Undefined
154   LogicalModel( const LogicalModel& handle );
155
156   // Undefined
157   LogicalModel& operator=( const LogicalModel& handle );
158
159 public:
160
161   Vector<Character>                     mText;
162   Vector<ScriptRun>                     mScriptRuns;
163   Vector<FontRun>                       mFontRuns;
164   Vector<ColorRun>                      mColorRuns;
165   Vector<FontDescriptionRun>            mFontDescriptionRuns;
166   Vector<LineBreakInfo>                 mLineBreakInfo;
167   Vector<WordBreakInfo>                 mWordBreakInfo;
168   Vector<BidirectionalParagraphInfoRun> mBidirectionalParagraphInfo;
169   Vector<CharacterDirection>            mCharacterDirections;        ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ).
170   Vector<BidirectionalLineInfoRun>      mBidirectionalLineInfo;
171   Vector<CharacterIndex>                mLogicalToVisualMap;         ///< Bidirectional logical to visual conversion table.
172   Vector<CharacterIndex>                mVisualToLogicalMap;         ///< Bidirectional visual to logical conversion table.
173   Vector<CharacterIndex>                mVisualToLogicalCursorMap;   ///< Bidirectional visual to logical cursor conversion table.
174 };
175
176 } // namespace Text
177
178 } // namespace Toolkit
179
180 } // namespace Dali
181
182 #endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H__