[dali_1.0.10] Merge branch 'tizen'
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-view / text-processor-bidirectional-info.h
1 #ifndef __DALI_TOOLKIT_TEXT_PROCESSOR_BIDIRECTIONAL_INFO_H__
2 #define __DALI_TOOLKIT_TEXT_PROCESSOR_BIDIRECTIONAL_INFO_H__
3
4 /*
5  * Copyright (c) 2014 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/text/text.h>
24
25 // EXTERNAL INCLUDES
26 #include <fribidi/fribidi.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 namespace TextProcessor
38 {
39
40 /**
41  * Stores the text containing right to left characters and info for each character needed by fribidi to reorder a line.
42  */
43 struct BidirectionalParagraphInfo
44 {
45   /**
46    * Default constructor.
47    *
48    * Initializes all members to their default values.
49    */
50   BidirectionalParagraphInfo();
51
52   /**
53    * Default destructor.
54    */
55   ~BidirectionalParagraphInfo();
56
57   /**
58    * Copy constructor.
59    */
60   BidirectionalParagraphInfo( const BidirectionalParagraphInfo& info );
61
62   /**
63    * Assignment operator.
64    */
65   BidirectionalParagraphInfo& operator=( const BidirectionalParagraphInfo& info );
66
67   FriBidiParType               mDirection;            ///< The paragraph direction.
68   std::vector<FriBidiCharType> mCharactersTypeBuffer; ///< Character type buffer.
69   std::vector<FriBidiLevel>    mLevelsBuffer;         ///< Levels buffer.
70   std::vector<FriBidiChar>     mLogicalUnicodeBuffer; ///< Text buffer in logical order. Coded in unicode.
71 };
72
73 /**
74  * Stores the reordered text, the conversion tables for a paragraph's line,
75  * the index to the first character of the line and the number of characters.
76  */
77 struct BidirectionalLineInfo
78 {
79   /**
80    * Default constructor.
81    *
82    * Initializes all members to their default values.
83    */
84   BidirectionalLineInfo();
85
86   /**
87    * Default destructor.
88    */
89   ~BidirectionalLineInfo();
90
91   /**
92    * Copy constructor.
93    */
94   BidirectionalLineInfo( const BidirectionalLineInfo& info );
95
96   /**
97    * Assignment operator.
98    */
99   BidirectionalLineInfo& operator=( const BidirectionalLineInfo& info );
100
101   std::size_t mCharacterParagraphIndex; ///< Index within the paragraph of the first character of the line.
102   std::size_t mNumberOfCharacters;      ///< Number of characters of the line.
103   Text        mText;                    ///< Text in visual order.
104   Vector<int> mVisualToLogicalMap;      ///< The character position map from the visual output text to the logical input text.
105   Vector<int> mLogicalToVisualMap;      ///< The character position map from the logical input text to the visual output text.
106 };
107
108 /**
109  * Whether the text begins with right-to-left (bidirectional) character.
110  * @param [in] text The given text.
111  * @return \e true if the text begins right-to-left character.
112  */
113 bool BeginsRightToLeftCharacter( const Text& text );
114
115 /**
116  * Whether the text contains any right-to-left (bidirectional) character.
117  * @param [in] text The given text.
118  * @return \e true if the text contains right-to-left character.
119  */
120 bool ContainsRightToLeftCharacter( const Text& text );
121
122 /**
123  * Processes a bidirectional paragraph's text.
124  *
125  * It stores the paragraph's direction (the direction of the first non neutral character),
126  * the direction of all characters, and the ligatures in case of arabic glyphs.
127  *
128  * It doesn't reorder the paragraph as this task must be done per line.
129  * The stored info is needed to reorder each line of the paragraph.
130  *
131  * @param[in] paragraph The paragraph to be processed.
132  * @param[out] info Struct containing the needed info to reorder each line of the paragraph.
133  */
134 void ProcessBidirectionalText( Text& paragraph,
135                                BidirectionalParagraphInfo* info );
136
137 /**
138  * Reorders one line of the paragraph according the Unicode Bidirectional Algorithm.
139  *
140  * The result is the text in the visual order and the conversion tables: logical <--> visual order
141  *
142  * @param[in] paragraphInfo Struct containing the needed info to reorder each line of the paragraph.
143  * @param[in,out] lineInfo Struct containing (in) A character index pointing the first character of the line and the number of characters, (out) the reordered line and the conversion tables.
144  */
145 void ReorderLine( BidirectionalParagraphInfo* paragraphInfo,
146                   BidirectionalLineInfo* lineInfo );
147
148 } // namespace TextProcessor
149
150 } // namespace Internal
151
152 } // namespace Toolkit
153
154 } // namespace Dali
155
156 #endif // __DALI_TOOLKIT_TEXT_PROCESSOR_BIDIRECTIONAL_INFO_H__
157