Fix for bidirectional support. 72/58772/2
authorVictor Cebollada <v.cebollada@samsung.com>
Wed, 3 Feb 2016 09:15:09 +0000 (09:15 +0000)
committerVíctor Cebollada <v.cebollada@samsung.com>
Wed, 3 Feb 2016 13:53:17 +0000 (05:53 -0800)
-Use the character's direction to know whether to mirror it.

This patches fix a 'mirroring' issue when there is bidirectional text.
i.e if RTL text is added to the string "(Hello world)", the text controller
replaces (mirror) the parenthesis getting the string ")Hello world( RTL_text"

It needs https://review.tizen.org/gerrit/#/c/58668/

Change-Id: If4210aa15d516a4688cd1c79aef7fb714e5f8f69
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
dali-toolkit/internal/text/bidirectional-support.cpp
dali-toolkit/internal/text/bidirectional-support.h
dali-toolkit/internal/text/text-controller-impl.cpp

index fd85439..c09c03c 100644 (file)
@@ -114,8 +114,8 @@ void SetBidirectionalInfo( const Vector<Character>& text,
     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.
+    if( ( lastScriptRunIndex > paragraphCharacterIndex ) &&        // It isn't part of a previous paragraph.
+        TextAbstraction::IsRightToLeftScript( scriptRun.script ) ) // The script is right to left.
     {
       // Find the paragraphs which contains this script run.
       // Consider:
@@ -231,8 +231,9 @@ void ReorderLines( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInf
 }
 
 bool GetMirroredText( const Vector<Character>& text,
-                      Vector<Character>& mirroredText,
-                      const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo )
+                      const Vector<CharacterDirection>& directions,
+                      const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
+                      Vector<Character>& mirroredText )
 {
   bool hasTextMirrored = false;
 
@@ -242,6 +243,7 @@ bool GetMirroredText( const Vector<Character>& text,
   mirroredText = text;
 
   Character* mirroredTextBuffer = mirroredText.Begin();
+  CharacterDirection* directionsBuffer = directions.Begin();
 
   // Traverse the paragraphs and mirror the right to left ones.
   for( Vector<BidirectionalParagraphInfoRun>::ConstIterator it = bidirectionalInfo.Begin(),
@@ -249,10 +251,11 @@ bool GetMirroredText( const Vector<Character>& text,
        it != endIt;
        ++it )
   {
-    const BidirectionalParagraphInfoRun& run = *it;
+    const BidirectionalParagraphInfoRun& paragraph = *it;
 
-    const bool tmpMirrored = bidirectionalSupport.GetMirroredText( mirroredTextBuffer + run.characterRun.characterIndex,
-                                                                   run.characterRun.numberOfCharacters );
+    const bool tmpMirrored = bidirectionalSupport.GetMirroredText( mirroredTextBuffer + paragraph.characterRun.characterIndex,
+                                                                   directionsBuffer + paragraph.characterRun.characterIndex,
+                                                                   paragraph.characterRun.numberOfCharacters );
 
     hasTextMirrored = hasTextMirrored || tmpMirrored;
   }
index f659a9c..e87f866 100644 (file)
@@ -71,14 +71,16 @@ void ReorderLines( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInf
  * @brief Replaces any character in the right to left paragraphs which could be mirrored.
  *
  * @param[in] text The text.
- * @param[in] mirroredText The mirroredText.
+ * @param[in] directions Vector with the direction of each paragraph.
  * @param[in] bidirectionalInfo Vector with the bidirectional infor for each paragraph.
+ * @param[out] mirroredText The mirroredText.
  *
  * @return @e true if a character has been replaced.
  */
 bool GetMirroredText( const Vector<Character>& text,
-                      Vector<Character>& mirroredText,
-                      const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo );
+                      const Vector<CharacterDirection>& directions,
+                      const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
+                      Vector<Character>& mirroredText );
 
 /**
  * @brief Retrieves the character's directions.
index f85d410..9c06327 100644 (file)
@@ -412,19 +412,20 @@ void Controller::Impl::UpdateModel( OperationsMask operationsRequired )
 
     if( 0u != bidirectionalInfo.Count() )
     {
-      // This paragraph has right to left text. Some characters may need to be mirrored.
-      // TODO: consider if the mirrored string can be stored as well.
-
-      textMirrored = GetMirroredText( utf32Characters,
-                                      mirroredUtf32Characters,
-                                      bidirectionalInfo );
-
       // Only set the character directions if there is right to left characters.
       Vector<CharacterDirection>& directions = mLogicalModel->mCharacterDirections;
       directions.Resize( numberOfCharacters );
 
       GetCharactersDirection( bidirectionalInfo,
                               directions );
+
+      // This paragraph has right to left text. Some characters may need to be mirrored.
+      // TODO: consider if the mirrored string can be stored as well.
+
+      textMirrored = GetMirroredText( utf32Characters,
+                                      directions,
+                                      bidirectionalInfo,
+                                      mirroredUtf32Characters );
     }
     else
     {