+ // Reserve memory for the paragraph's bidirectional info.
+ BidirectionalInfo* bidirectionalInfo = new BidirectionalInfo();
+
+ bidirectionalInfo->characterTypes = reinterpret_cast<FriBidiCharType*>( malloc( numberOfCharacters * sizeof( FriBidiCharType ) ) );
+ bidirectionalInfo->embeddedLevels = reinterpret_cast<FriBidiLevel*>( malloc( numberOfCharacters * sizeof( FriBidiLevel ) ) );
+
+ // Retrieve the type of each character..
+ fribidi_get_bidi_types( paragraph, numberOfCharacters, bidirectionalInfo->characterTypes );
+
+ // Retrieve the paragraph's direction.
+ bidirectionalInfo->paragraphDirection = fribidi_get_par_direction( paragraph, numberOfCharacters );
+
+ // Retrieve the embedding levels.
+ fribidi_get_par_embedding_levels( paragraph, numberOfCharacters, &bidirectionalInfo->paragraphDirection, bidirectionalInfo->embeddedLevels );
+
+ // Store the bidirectional info and return the index.
+ BidiInfoIndex index = 0u;
+ const std::size_t numberOfItems = mFreeIndices.Count();
+ if( numberOfItems != 0u )
+ {
+ Vector<BidiInfoIndex>::Iterator it = mFreeIndices.End() - 1u;
+
+ index = *it;
+
+ mFreeIndices.Remove( it );
+
+ *( mParagraphBidirectionalInfo.Begin() + index ) = bidirectionalInfo;
+ }
+ else
+ {
+ index = static_cast<BidiInfoIndex>( numberOfItems );
+
+ mParagraphBidirectionalInfo.PushBack( bidirectionalInfo );
+ }
+
+ return index;