+ // Handle to the bidirectional info module in text-abstraction.
+ TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get();
+
+ // Keep an index to the first line to be checked if it's contained inside the paragraph.
+ // Avoids check the lines from the beginning for each paragraph.
+ unsigned int lineIndex = 0u;
+
+ for( Vector<BidirectionalParagraphInfoRun>::ConstIterator it = bidirectionalInfo.Begin(),
+ endIt = bidirectionalInfo.End();
+ it != endIt;
+ ++it )
+ {
+ const BidirectionalParagraphInfoRun& paragraphInfo = *it;
+ const CharacterDirection direction = bidirectionalSupport.GetParagraphDirection( paragraphInfo.bidirectionalInfoIndex );
+
+ // Get the lines for this paragraph.
+ unsigned int firstLine = 0u;
+ unsigned int numberOfLines = 0u;
+
+ // Get an index to the first line and the number of lines of the current paragraph.
+ GetLines( paragraphInfo,
+ lineRuns,
+ lineIndex,
+ firstLine,
+ numberOfLines );
+
+ lineIndex = firstLine + numberOfLines;
+
+ // Traverse the lines and reorder them
+ for( Vector<LineRun>::Iterator lineIt = lineRuns.Begin() + firstLine,
+ endLineIt = lineRuns.Begin() + firstLine + numberOfLines;
+ lineIt != endLineIt;
+ ++lineIt )
+ {
+ LineRun& line = *lineIt;
+
+ // Sets the paragraph's direction.
+ line.direction = direction;
+
+ // Creates a bidirectional info for the line run.
+ BidirectionalLineInfoRun lineInfoRun;
+ lineInfoRun.characterRun.characterIndex = line.characterRun.characterIndex;
+ lineInfoRun.characterRun.numberOfCharacters = line.characterRun.numberOfCharacters;
+ lineInfoRun.direction = direction;
+
+ // Allocate space for the conversion maps.
+ // The memory is freed after the visual to logical to visual conversion tables are built in the logical model.
+ lineInfoRun.visualToLogicalMap = reinterpret_cast<CharacterIndex*>( malloc( line.characterRun.numberOfCharacters * sizeof( CharacterIndex ) ) );
+
+ if( NULL != lineInfoRun.visualToLogicalMap )
+ {
+ // Reorders the line.
+ bidirectionalSupport.Reorder( paragraphInfo.bidirectionalInfoIndex,
+ line.characterRun.characterIndex - paragraphInfo.characterRun.characterIndex,
+ line.characterRun.numberOfCharacters,
+ lineInfoRun.visualToLogicalMap );
+ }
+
+ // Push the run into the vector.
+ lineInfoRuns.PushBack( lineInfoRun );
+ }
+ }
+}
+
+bool GetMirroredText( const Vector<Character>& text,
+ Vector<Character>& mirroredText,
+ const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo )
+{
+ bool hasTextMirrored = false;
+
+ // Handle to the bidirectional info module in text-abstraction.
+ TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get();
+
+ mirroredText = text;
+
+ Character* mirroredTextBuffer = mirroredText.Begin();
+
+ // Traverse the paragraphs and mirror the right to left ones.
+ for( Vector<BidirectionalParagraphInfoRun>::ConstIterator it = bidirectionalInfo.Begin(),
+ endIt = bidirectionalInfo.End();
+ it != endIt;
+ ++it )
+ {
+ const BidirectionalParagraphInfoRun& run = *it;
+
+ const bool tmpMirrored = bidirectionalSupport.GetMirroredText( mirroredTextBuffer + run.characterRun.characterIndex,
+ run.characterRun.numberOfCharacters );
+
+ hasTextMirrored = hasTextMirrored || tmpMirrored;
+ }
+
+ return hasTextMirrored;