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 );
69 * @return Whether the paragraph is right to left.
71 bool IsRightToLeftParagraph() const;
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.
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.
83 struct BidirectionalLineInfo
86 * Default constructor.
88 * Initializes all members to their default values.
90 BidirectionalLineInfo();
95 ~BidirectionalLineInfo();
100 BidirectionalLineInfo( const BidirectionalLineInfo& info );
103 * Assignment operator.
105 BidirectionalLineInfo& operator=( const BidirectionalLineInfo& info );
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.
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.
119 bool BeginsRightToLeftCharacter( const Text& text );
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.
126 bool ContainsRightToLeftCharacter( const Text& text );
129 * Processes a bidirectional paragraph's text.
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.
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.
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.
140 void ProcessBidirectionalText( Text& paragraph,
141 BidirectionalParagraphInfo* info );
144 * Reorders one line of the paragraph according the Unicode Bidirectional Algorithm.
146 * The result is the text in the visual order and the conversion tables: logical <--> visual order
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.
151 void ReorderLine( BidirectionalParagraphInfo* paragraphInfo,
152 BidirectionalLineInfo* lineInfo );
154 } // namespace TextProcessor
156 } // namespace Internal
158 } // namespace Toolkit
162 #endif // __DALI_TOOLKIT_TEXT_PROCESSOR_BIDIRECTIONAL_INFO_H__