+ // Handle to the bidirectional info module in text-abstraction.
+ TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get();
+
+ // Creates a bidirectional info for the line run.
+ BidirectionalLineInfoRun lineInfoRun;
+ lineInfoRun.characterRun.characterIndex = startIndex;
+ lineInfoRun.characterRun.numberOfCharacters = numberOfCharacters;
+ lineInfoRun.direction = direction;
+ lineInfoRun.isIdentity = true;
+
+ // 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( numberOfCharacters * sizeof( CharacterIndex ) ) );
+
+ if( nullptr != lineInfoRun.visualToLogicalMap )
+ {
+ // Reorders the line.
+ bidirectionalSupport.Reorder( bidirectionalParagraphInfo.bidirectionalInfoIndex,
+ lineInfoRun.characterRun.characterIndex - bidirectionalParagraphInfo.characterRun.characterIndex,
+ lineInfoRun.characterRun.numberOfCharacters,
+ lineInfoRun.visualToLogicalMap );
+
+ // For those LTR lines inside a bidirectional paragraph.
+ // It will save to relayout the line after reordering.
+ for( unsigned int i=0; i<numberOfCharacters; ++i )
+ {
+ if( i != *( lineInfoRun.visualToLogicalMap + i ) )
+ {
+ lineInfoRun.isIdentity = false;
+ break;
+ }
+ }
+ }
+
+ // Push the run into the vector.
+ lineInfoRuns.Insert( lineInfoRuns.Begin() + bidiLineIndex, lineInfoRun );