+ // For each character, it sets the character's direction.
+
+ // Initialize the paragraph direction. Used to set the direction of weak characters.
+ const bool isParagraphRightToLeft = paragraph.mBidirectionalParagraphInfo->IsRightToLeftParagraph();
+ bool isPreviousRightToLeft = isParagraphRightToLeft;
+
+ for( std::size_t index = 0u; index < paragraph.mNumberOfCharacters; ++index )
+ {
+ // Get the character's layout information (the one is shared with text-input)
+ Toolkit::TextView::CharacterLayoutInfo& info = *( relayoutData.mCharacterLayoutInfoTable.begin() + ( characterGlobalIndex + index ) );
+
+ // Gets the character's direction.
+ const Character::CharacterDirection direction = paragraph.mText[index].GetCharacterDirection();
+ if( Character::RightToLeft == direction )
+ {
+ info.mIsRightToLeftCharacter = true;
+ }
+ else if( Character::Neutral == direction )
+ {
+ // For neutral characters it check's the next and previous directions.
+ // If they are equals set that direction. If they are not, sets the paragraph direction.
+ // If there is no next, sets the previous direction.
+
+ // Check next character's direction.
+ bool isNextRightToLeft = isPreviousRightToLeft;
+ if( index < paragraph.mNumberOfCharacters - 1u )
+ {
+ const Character::CharacterDirection nextDirection = paragraph.mText[index + 1u].GetCharacterDirection();
+ isNextRightToLeft = Character::RightToLeft == nextDirection;
+ }
+
+ info.mIsRightToLeftCharacter = isPreviousRightToLeft == isNextRightToLeft ? isPreviousRightToLeft : isParagraphRightToLeft;
+ }
+ else
+ {
+ info.mIsRightToLeftCharacter = false;
+ }
+
+ isPreviousRightToLeft = info.mIsRightToLeftCharacter;
+ }
+