Fix Klocwork issues.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / bidirectional-support.cpp
index b9ff99a..aff18be 100644 (file)
@@ -19,7 +19,8 @@
 #include <dali-toolkit/internal/text/bidirectional-support.h>
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/text-abstraction/bidirectional-support.h>
+#include <memory.h>
+#include <dali/devel-api/text-abstraction/bidirectional-support.h>
 
 namespace Dali
 {
@@ -161,15 +162,8 @@ void SetBidirectionalInfo( const Vector<Character>& text,
   }
 }
 
-void ReplaceBidirectionalInfo( LogicalModel& model,
-                               CharacterIndex characterIndex,
-                               Length numberOfCharactersToRemove,
-                               Length numberOfCharactersToInsert )
-{
-}
-
 void ReorderLines( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
-                   const Vector<LineRun>& lineRuns,
+                   Vector<LineRun>& lineRuns,
                    Vector<BidirectionalLineInfoRun>& lineInfoRuns )
 {
   // Handle to the bidirectional info module in text-abstraction.
@@ -201,12 +195,15 @@ void ReorderLines( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInf
     lineIndex = firstLine + numberOfLines;
 
     // Traverse the lines and reorder them
-    for( Vector<LineRun>::ConstIterator lineIt = lineRuns.Begin() + firstLine,
+    for( Vector<LineRun>::Iterator lineIt = lineRuns.Begin() + firstLine,
            endLineIt = lineRuns.Begin() + firstLine + numberOfLines;
            lineIt != endLineIt;
          ++lineIt )
     {
-      const LineRun& line = *lineIt;
+      LineRun& line = *lineIt;
+
+      // Sets the paragraph's direction.
+      line.direction = direction;
 
       // Creates a bidirectional info for the line run.
       BidirectionalLineInfoRun lineInfoRun;
@@ -218,11 +215,14 @@ void ReorderLines( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInf
       // 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 ) ) );
 
-      // Reorders the line.
-      bidirectionalSupport.Reorder( paragraphInfo.bidirectionalInfoIndex,
-                                    line.characterRun.characterIndex,
-                                    line.characterRun.numberOfCharacters,
-                                    lineInfoRun.visualToLogicalMap );
+      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 );
@@ -230,14 +230,6 @@ void ReorderLines( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInf
   }
 }
 
-void ReorderLines( LogicalModel& logicalModel,
-                   const VisualModel& visualModel,
-                   CharacterIndex characterIndex,
-                   Length numberOfCharactersToRemove,
-                   Length numberOfCharactersToInsert )
-{
-}
-
 bool GetMirroredText( const Vector<Character>& text,
                       Vector<Character>& mirroredText )
 {
@@ -250,6 +242,34 @@ bool GetMirroredText( const Vector<Character>& text,
                                                mirroredText.Count() );
 }
 
+void GetCharactersDirection( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
+                             Vector<CharacterDirection>& directions )
+{
+  // Handle to the bidirectional info module in text-abstraction.
+  TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get();
+
+  CharacterIndex index = 0u;
+  CharacterDirection* directionsBuffer = directions.Begin();
+  for( Vector<BidirectionalParagraphInfoRun>::ConstIterator it = bidirectionalInfo.Begin(),
+         endIt = bidirectionalInfo.End();
+       it != endIt;
+       ++it )
+  {
+    const BidirectionalParagraphInfoRun& paragraph = *it;
+
+    // Fills with left to right those paragraphs without right to left characters.
+    memset( directionsBuffer + index, false, ( paragraph.characterRun.characterIndex - index ) * sizeof( bool ) );
+    index += paragraph.characterRun.numberOfCharacters;
+
+    bidirectionalSupport.GetCharactersDirection( paragraph.bidirectionalInfoIndex,
+                                                 directionsBuffer + paragraph.characterRun.characterIndex,
+                                                 paragraph.characterRun.numberOfCharacters );
+  }
+
+  // Fills with left to right those paragraphs without right to left characters.
+  memset( directionsBuffer + index, false, ( directions.Count() - index ) * sizeof( bool ) );
+}
+
 } // namespace Text
 
 } // namespace Toolkit