+ // Traverse the script runs. If there is one with a right to left script, create the bidirectional info for the paragraph containing that script is needed.
+ // From the bidirectional point of view, a paragraph is the piece of text between two LINE_MUST_BREAK.
+
+ // Index pointing the first character of the current paragraph.
+ CharacterIndex paragraphCharacterIndex = 0u;
+
+ // Pointer to the text buffer.
+ const Character* textBuffer = text.Begin();
+
+ // Pointer to the line break info buffer.
+ const LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin();
+
+ // The number of characters.
+ const Length numberOfCharacters = text.Count();
+
+ // Handle to the bidirectional info module in text-abstraction.
+ TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get();
+
+ for( Vector<ScriptRun>::ConstIterator it = scripts.Begin(),
+ endIt = scripts.End();
+ it != endIt;
+ ++it )
+ {
+ const ScriptRun& scriptRun = *it;
+ const CharacterIndex lastScriptRunIndex = scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters;
+
+ if( TextAbstraction::IsRightToLeftScript( scriptRun.script ) && // The script is right to left.
+ ( lastScriptRunIndex > paragraphCharacterIndex ) ) // It isn't part of a previous paragraph.
+ {
+ // Find the paragraphs which contains this script run.
+ // Consider:
+ // 1) Different paragraphs may contain this script run.
+ // ------||------------------- rtl sr ------------------------||-------------------
+ // --||----- p -----||------------------ p -------------||-------- p ------||------
+ //
+ // 2) The paragraph which contains this script run may contain other right to left script runs.
+ // -----||--- rtl sr ---||---- ltr sr ----||---------- rtl sr -----------||--------
+ // -----||---------------------------------- p -----------------------------------|
+
+ while( lastScriptRunIndex > paragraphCharacterIndex )
+ {
+ // There is a paragraph which contains the current script.
+
+ Length index = paragraphCharacterIndex;
+ while( ( index < numberOfCharacters ) && ( paragraphCharacterIndex < lastScriptRunIndex ) )
+ {
+ if( TextAbstraction::LINE_MUST_BREAK == *( lineBreakInfoBuffer + index ) )
+ {
+ if( index >= scriptRun.characterRun.characterIndex )
+ {
+ // The Bidirectional run must have the same number of characters than the paragraph.
+ BidirectionalParagraphInfoRun bidirectionalRun;
+ bidirectionalRun.characterRun.characterIndex = paragraphCharacterIndex;
+ bidirectionalRun.characterRun.numberOfCharacters = ( index - paragraphCharacterIndex ) + 1u; // The must break character is part of the paragrah.
+
+ // Create the bidirectional info for the whole paragraph and store the index to the table with this info in the run.
+ bidirectionalRun.bidirectionalInfoIndex = bidirectionalSupport.CreateInfo( textBuffer + bidirectionalRun.characterRun.characterIndex,
+ bidirectionalRun.characterRun.numberOfCharacters );
+
+ bidirectionalInfo.PushBack( bidirectionalRun );
+ }
+
+ // Update the character index of the next paragraph.
+ paragraphCharacterIndex = index + 1u;
+ }
+ ++index;
+ }
+
+ // The last character is always a must-break, so there is no need to check if there is characters left.
+ }
+ }
+ }