Mirroring bidirectional text. 85/36985/3
authorVictor Cebollada <v.cebollada@samsung.com>
Tue, 17 Mar 2015 18:09:07 +0000 (18:09 +0000)
committerVíctor Cebollada <v.cebollada@samsung.com>
Wed, 18 Mar 2015 07:48:19 +0000 (00:48 -0700)
Change-Id: Ie1392451f1aad81b05d7762b6838c14cccfc0913
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.cpp

index 14fb1a7..f20641b 100644 (file)
@@ -236,6 +236,18 @@ void ReorderLines( LogicalModel& logicalModel,
 {
 }
 
+bool GetMirroredText( const Vector<Character>& text,
+                      Vector<Character>& mirroredText )
+{
+  // Handle to the bidirectional info module in text-abstraction.
+  TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get();
+
+  mirroredText = text;
+
+  return bidirectionalSupport.GetMirroredText( mirroredText.Begin(),
+                                               mirroredText.Count() );
+}
+
 } // namespace Text
 
 } // namespace Toolkit
index 4bdd5e3..227133e 100644 (file)
@@ -110,6 +110,16 @@ void ReorderLines( LogicalModel& logicalModel,
                    Length numberOfCharactersToRemove,
                    Length numberOfCharactersToInsert );
 
+/**
+ * @brief Replaces any character which could be mirrored.
+ *
+ * @param[in] text The text.
+ * @param[in] mirroredText The mirroredText.
+ *
+ * @return @e true if a character has been replaced.
+ */
+bool GetMirroredText( const Vector<Character>& text,
+                      Vector<Character>& mirroredText );
 } // namespace Text
 
 } // namespace Toolkit
index b4d4bb5..ea33695 100644 (file)
@@ -622,6 +622,7 @@ Vector3 Controller::GetNaturalSize()
                                                                            VALIDATE_FONTS    |
                                                                            GET_LINE_BREAKS   |
                                                                            GET_WORD_BREAKS   |
+                                                                           BIDI_INFO         |
                                                                            SHAPE_TEXT        |
                                                                            GET_GLYPH_METRICS );
     // Make sure the model is up-to-date before layouting
@@ -670,6 +671,7 @@ float Controller::GetHeightForWidth( float width )
                                                                            VALIDATE_FONTS    |
                                                                            GET_LINE_BREAKS   |
                                                                            GET_WORD_BREAKS   |
+                                                                           BIDI_INFO         |
                                                                            SHAPE_TEXT        |
                                                                            GET_GLYPH_METRICS );
     // Make sure the model is up-to-date before layouting
@@ -968,6 +970,8 @@ void Controller::UpdateModel( OperationsMask operationsRequired )
     }
   }
 
+  Vector<Character> mirroredUtf32Characters;
+  bool textMirrored = false;
   if( BIDI_INFO & operations )
   {
     // Count the number of LINE_NO_BREAK to reserve some space for the vector of paragraph's
@@ -992,6 +996,14 @@ void Controller::UpdateModel( OperationsMask operationsRequired )
                           scripts,
                           lineBreakInfo,
                           bidirectionalInfo );
+
+    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 );
+    }
   }
 
   Vector<GlyphInfo>& glyphs = mImpl->mVisualModel->mGlyphs;
@@ -999,8 +1011,9 @@ void Controller::UpdateModel( OperationsMask operationsRequired )
   Vector<Length>& charactersPerGlyph = mImpl->mVisualModel->mCharactersPerGlyph;
   if( SHAPE_TEXT & operations )
   {
+    const Vector<Character>& textToShape = textMirrored ? mirroredUtf32Characters : utf32Characters;
     // Shapes the text.
-    ShapeText( utf32Characters,
+    ShapeText( textToShape,
                lineBreakInfo,
                scripts,
                validFonts,