Markup procesor. Color
[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/script-run.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Text
40 {
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   /**
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 Sets the visual to logical and the logical to visual map tables.
91    *
92    * Replaces any map tables previously set.
93    *
94    * @note If the number of runs is zero the bidirectional info buffer is cleared.
95    *
96    * @param[in] bidirectionalInfo Pointer to a buffer with all the bidirectional info runs.
97    * @param[in] numberOfRuns The number of bidirectional info runs.
98    */
99   void SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo,
100                               Length numberOfRuns );
101
102   /**
103    * @brief Retrieves the logical character index for the given visual character index.
104    *
105    * @param[in] visualCharacterIndex The visual character index.
106    *
107    * @return The logical character index.
108    */
109   CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const;
110
111   /**
112    * @brief Updates the text's style runs with the added or removed text.
113    *
114    * @param[in] index The character's index.
115    * @param[in] numberOfCharacters The number of characters added or removed. If the value is negative the characters are removed.
116    */
117   void UpdateTextStyleRuns( CharacterIndex index, int numberOfCharacters );
118
119   /**
120    * @brief Retrieves the text's style for the given character index.
121    *
122    * @param[in] index The character index.
123    * @param[out] style The text's style in the given style.
124    */
125   void RetrieveStyle( CharacterIndex index, InputStyle& style );
126
127 protected:
128
129   /**
130    * @brief A reference counted object may only be deleted by calling Unreference().
131    */
132   virtual ~LogicalModel();
133
134 private:
135
136   /**
137    * @brief Private constructor.
138    */
139   LogicalModel();
140
141   // Undefined
142   LogicalModel( const LogicalModel& handle );
143
144   // Undefined
145   LogicalModel& operator=( const LogicalModel& handle );
146
147 public:
148
149   Vector<Character>                     mText;
150   Vector<ScriptRun>                     mScriptRuns;
151   Vector<FontRun>                       mFontRuns;
152   Vector<ColorRun>                      mColorRuns;
153   Vector<LineBreakInfo>                 mLineBreakInfo;
154   Vector<WordBreakInfo>                 mWordBreakInfo;
155   Vector<BidirectionalParagraphInfoRun> mBidirectionalParagraphInfo;
156   Vector<CharacterDirection>            mCharacterDirections;        ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ).
157   Vector<BidirectionalLineInfoRun>      mBidirectionalLineInfo;
158   Vector<CharacterIndex>                mLogicalToVisualMap;         ///< Bidirectional logical to visual conversion table.
159   Vector<CharacterIndex>                mVisualToLogicalMap;         ///< Bidirectional visual to logical conversion table.
160   Vector<CharacterIndex>                mVisualToLogicalCursorMap;   ///< Bidirectional visual to logical cursor conversion table.
161 };
162
163 } // namespace Text
164
165 } // namespace Toolkit
166
167 } // namespace Dali
168
169 #endif // __DALI_TOOLKIT_TEXT_LOGICAL_MODEL_IMPL_H__