1 #ifndef __DALI_TOOLKIT_TEXT_PROCESSOR_BIDIRECTIONAL_INFO_H__
2 #define __DALI_TOOLKIT_TEXT_PROCESSOR_BIDIRECTIONAL_INFO_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/text/text.h>
26 #include <fribidi/fribidi.h>
37 namespace TextProcessor
41 * Stores the text containing right to left characters and info for each character needed by fribidi to reorder a line.
43 struct BidirectionalParagraphInfo
46 * Default constructor.
48 * Initializes all members to their default values.
50 BidirectionalParagraphInfo();
55 ~BidirectionalParagraphInfo();
60 BidirectionalParagraphInfo( const BidirectionalParagraphInfo& info );
63 * Assignment operator.
65 BidirectionalParagraphInfo& operator=( const BidirectionalParagraphInfo& info );
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.
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.
77 struct BidirectionalLineInfo
80 * Default constructor.
82 * Initializes all members to their default values.
84 BidirectionalLineInfo();
89 ~BidirectionalLineInfo();
94 BidirectionalLineInfo( const BidirectionalLineInfo& info );
97 * Assignment operator.
99 BidirectionalLineInfo& operator=( const BidirectionalLineInfo& info );
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.
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.
113 bool BeginsRightToLeftCharacter( const Text& text );
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.
120 bool ContainsRightToLeftCharacter( const Text& text );
123 * Processes a bidirectional paragraph's text.
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.
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.
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.
134 void ProcessBidirectionalText( Text& paragraph,
135 BidirectionalParagraphInfo* info );
138 * Reorders one line of the paragraph according the Unicode Bidirectional Algorithm.
140 * The result is the text in the visual order and the conversion tables: logical <--> visual order
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.
145 void ReorderLine( BidirectionalParagraphInfo* paragraphInfo,
146 BidirectionalLineInfo* lineInfo );
148 } // namespace TextProcessor
150 } // namespace Internal
152 } // namespace Toolkit
156 #endif // __DALI_TOOLKIT_TEXT_PROCESSOR_BIDIRECTIONAL_INFO_H__