Merge branch 'tizen' into new_text
[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
68   /**
69    * @return Whether the paragraph is right to left.
70    */
71   bool IsRightToLeftParagraph() const;
72
73   FriBidiParType               mDirection;            ///< The paragraph direction.
74   std::vector<FriBidiCharType> mCharactersTypeBuffer; ///< Character type buffer.
75   std::vector<FriBidiLevel>    mLevelsBuffer;         ///< Levels buffer.
76   std::vector<FriBidiChar>     mLogicalUnicodeBuffer; ///< Text buffer in logical order. Coded in unicode.
77 };
78
79 /**
80  * Stores the reordered text, the conversion tables for a paragraph's line,
81  * the index to the first character of the line and the number of characters.
82  */
83 struct BidirectionalLineInfo
84 {
85   /**
86    * Default constructor.
87    *
88    * Initializes all members to their default values.
89    */
90   BidirectionalLineInfo();
91
92   /**
93    * Default destructor.
94    */
95   ~BidirectionalLineInfo();
96
97   /**
98    * Copy constructor.
99    */
100   BidirectionalLineInfo( const BidirectionalLineInfo& info );
101
102   /**
103    * Assignment operator.
104    */
105   BidirectionalLineInfo& operator=( const BidirectionalLineInfo& info );
106
107   std::size_t mCharacterParagraphIndex; ///< Index within the paragraph of the first character of the line.
108   std::size_t mNumberOfCharacters;      ///< Number of characters of the line.
109   Text        mText;                    ///< Text in visual order.
110   Vector<int> mVisualToLogicalMap;      ///< The character position map from the visual output text to the logical input text.
111   Vector<int> mLogicalToVisualMap;      ///< The character position map from the logical input text to the visual output text.
112 };
113
114 /**
115  * Whether the text begins with right-to-left (bidirectional) character.
116  * @param [in] text The given text.
117  * @return \e true if the text begins right-to-left character.
118  */
119 bool BeginsRightToLeftCharacter( const Text& text );
120
121 /**
122  * Whether the text contains any right-to-left (bidirectional) character.
123  * @param [in] text The given text.
124  * @return \e true if the text contains right-to-left character.
125  */
126 bool ContainsRightToLeftCharacter( const Text& text );
127
128 /**
129  * Processes a bidirectional paragraph's text.
130  *
131  * It stores the paragraph's direction (the direction of the first non neutral character),
132  * the direction of all characters, and the ligatures in case of arabic glyphs.
133  *
134  * It doesn't reorder the paragraph as this task must be done per line.
135  * The stored info is needed to reorder each line of the paragraph.
136  *
137  * @param[in] paragraph The paragraph to be processed.
138  * @param[out] info Struct containing the needed info to reorder each line of the paragraph.
139  */
140 void ProcessBidirectionalText( Text& paragraph,
141                                BidirectionalParagraphInfo* info );
142
143 /**
144  * Reorders one line of the paragraph according the Unicode Bidirectional Algorithm.
145  *
146  * The result is the text in the visual order and the conversion tables: logical <--> visual order
147  *
148  * @param[in] paragraphInfo Struct containing the needed info to reorder each line of the paragraph.
149  * @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.
150  */
151 void ReorderLine( BidirectionalParagraphInfo* paragraphInfo,
152                   BidirectionalLineInfo* lineInfo );
153
154 } // namespace TextProcessor
155
156 } // namespace Internal
157
158 } // namespace Toolkit
159
160 } // namespace Dali
161
162 #endif // __DALI_TOOLKIT_TEXT_PROCESSOR_BIDIRECTIONAL_INFO_H__
163