Retrieves the character's directions. 32/37132/2
authorVictor Cebollada <v.cebollada@samsung.com>
Thu, 19 Mar 2015 08:10:55 +0000 (08:10 +0000)
committerVictor Cebollada <v.cebollada@samsung.com>
Thu, 19 Mar 2015 16:39:57 +0000 (16:39 +0000)
Change-Id: I9f75a78eff9f0a1b068d87bde1988f657264ecc5
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
text/dali/internal/text-abstraction/bidirectional-support-impl.cpp
text/dali/internal/text-abstraction/bidirectional-support-impl.h
text/dali/public-api/text-abstraction/bidirectional-support.cpp
text/dali/public-api/text-abstraction/bidirectional-support.h
text/dali/public-api/text-abstraction/text-abstraction-definitions.h

index 28d35e2..3ac48a2 100644 (file)
@@ -34,6 +34,63 @@ namespace TextAbstraction
 namespace Internal
 {
 
+namespace
+{
+  typedef unsigned char BidiDirection;
+
+  // Internal charcter's direction.
+  const BidiDirection LEFT_TO_RIGHT = 0u;
+  const BidiDirection NEUTRAL = 1u;
+  const BidiDirection RIGHT_TO_LEFT = 2u;
+
+  /**
+   * @param[in] paragraphDirection The FriBiDi paragraph's direction.
+   *
+   * @return Whether the paragraph is right to left.
+   */
+  bool GetBidiParagraphDirection( FriBidiParType paragraphDirection )
+  {
+    switch( paragraphDirection )
+    {
+      case FRIBIDI_PAR_RTL:  // Right-To-Left paragraph.
+      case FRIBIDI_PAR_WRTL: // Weak Right To Left paragraph.
+      {
+        return true;
+      }
+      case FRIBIDI_PAR_LTR:  // Left-To-Right paragraph.
+      case FRIBIDI_PAR_ON:   // DirectiOn-Neutral paragraph.
+      case FRIBIDI_PAR_WLTR: // Weak Left To Right paragraph.
+      {
+        return false;
+      }
+    }
+
+    return false;
+  }
+
+  BidiDirection GetBidiCharacterDirection( FriBidiCharType characterDirection )
+  {
+    switch( characterDirection )
+    {
+      case FRIBIDI_TYPE_LTR: // Left-To-Right letter.
+      case FRIBIDI_TYPE_EN:  // European Numeral.
+      case FRIBIDI_TYPE_AN:  // Arabic Numeral.
+      case FRIBIDI_TYPE_ES:  // European number Separator.
+      case FRIBIDI_TYPE_ET:  // European number Terminator.
+      {
+        return LEFT_TO_RIGHT;
+      }
+      case FRIBIDI_TYPE_RTL: // Right-To-Left letter.
+      case FRIBIDI_TYPE_AL:  // Arabic Letter.
+      {
+        return RIGHT_TO_LEFT;
+      }
+    }
+
+    return NEUTRAL;
+  }
+}
+
 struct BidirectionalSupport::Plugin
 {
   /**
@@ -194,22 +251,48 @@ struct BidirectionalSupport::Plugin
     // Retrieve the paragraph's bidirectional info.
     const BidirectionalInfo* const bidirectionalInfo = *( mParagraphBidirectionalInfo.Begin() + bidiInfoIndex );
 
-    switch( bidirectionalInfo->paragraphDirection )
+    return GetBidiParagraphDirection( bidirectionalInfo->paragraphDirection );
+  }
+
+  void GetCharactersDirection( BidiInfoIndex bidiInfoIndex,
+                               CharacterDirection* directions,
+                               Length numberOfCharacters )
+  {
+    const BidirectionalInfo* const bidirectionalInfo = *( mParagraphBidirectionalInfo.Begin() + bidiInfoIndex );
+
+    const CharacterDirection paragraphDirection = GetBidiParagraphDirection( bidirectionalInfo->paragraphDirection );
+    CharacterDirection previousDirection = paragraphDirection;
+
+    for( CharacterIndex index = 0u; index < numberOfCharacters; ++index )
     {
-      case FRIBIDI_PAR_RTL:  // Right-To-Left paragraph.
-      case FRIBIDI_PAR_WRTL: // Weak Right To Left paragraph.
+      CharacterDirection& characterDirection = *( directions + index );
+      characterDirection = false;
+
+      // Get the bidi direction.
+      const BidiDirection bidiDirection = GetBidiCharacterDirection( *( bidirectionalInfo->characterTypes + index ) );
+
+      if( RIGHT_TO_LEFT == bidiDirection )
       {
-        return true;
+        characterDirection = true;
       }
-      case FRIBIDI_PAR_LTR:  // Left-To-Right paragraph.
-      case FRIBIDI_PAR_ON:   // DirectiOn-Neutral paragraph.
-      case FRIBIDI_PAR_WLTR: // Weak Left To Right paragraph.
+      else if( NEUTRAL == bidiDirection )
       {
-        return false;
+        // For neutral characters it check's the next and previous directions.
+        // If they are equals set that direction. If they are not, sets the paragraph's direction.
+        // If there is no next, sets the paragraph's direction.
+
+        CharacterDirection nextDirection = paragraphDirection;
+        const Length nextIndex = index + 1u;
+        if( nextIndex < numberOfCharacters )
+        {
+          const BidiDirection nextBidiDirection = GetBidiCharacterDirection( *( bidirectionalInfo->characterTypes + nextIndex ) );
+
+          nextDirection = RIGHT_TO_LEFT == nextBidiDirection;
+        }
+
+        characterDirection = previousDirection == nextDirection ? previousDirection : paragraphDirection;
       }
     }
-
-    return false;
   }
 
   Vector<BidirectionalInfo*> mParagraphBidirectionalInfo; ///< Stores the bidirectional info per paragraph.
@@ -298,6 +381,17 @@ bool BidirectionalSupport::GetParagraphDirection( BidiInfoIndex bidiInfoIndex )
   return mPlugin->GetParagraphDirection( bidiInfoIndex );
 }
 
+void BidirectionalSupport::GetCharactersDirection( BidiInfoIndex bidiInfoIndex,
+                                                   CharacterDirection* directions,
+                                                   Length numberOfCharacters )
+{
+  CreatePlugin();
+
+  mPlugin->GetCharactersDirection( bidiInfoIndex,
+                                   directions,
+                                   numberOfCharacters );
+}
+
 void BidirectionalSupport::CreatePlugin()
 {
   if( !mPlugin )
index ba637b9..8008988 100644 (file)
@@ -86,6 +86,13 @@ public:
    */
   bool GetParagraphDirection( BidiInfoIndex bidiInfoIndex ) const;
 
+  /**
+   * @copydoc Dali::BidirectionalSupport::GetCharactersDirection()
+   */
+  void GetCharactersDirection( BidiInfoIndex bidiInfoIndex,
+                               CharacterDirection* directions,
+                               Length numberOfCharacters );
+
 private:
 
   /**
index 991727e..8745b6a 100644 (file)
@@ -80,6 +80,15 @@ bool BidirectionalSupport::GetParagraphDirection( BidiInfoIndex bidiInfoIndex )
   return GetImplementation( *this ).GetParagraphDirection( bidiInfoIndex );
 }
 
+void BidirectionalSupport::GetCharactersDirection( BidiInfoIndex bidiInfoIndex,
+                                                   CharacterDirection* directions,
+                                                   Length numberOfCharacters )
+{
+  GetImplementation( *this ).GetCharactersDirection( bidiInfoIndex,
+                                                     directions,
+                                                     numberOfCharacters );
+}
+
 } // namespace TextAbstraction
 
 } // namespace Dali
index 0a2857f..21aed82 100644 (file)
@@ -125,6 +125,17 @@ public:
    * @return @e true if the paragraph is right to left, otherwise @e false.
    */
   bool GetParagraphDirection( BidiInfoIndex bidiInfoIndex ) const;
+
+  /**
+   * @brief Retrieves the character's directions.
+   *
+   * @param[in] bidiInfoIndex The index to the of the object inside the table storing the bidirectional data for the current paragraph.
+   * @param[out] directions The direction, @e false is left to right and @e true is right to left, of each character of the paragraph.
+   * @param[in] numberOfCharacters The number of characters.
+   */
+  void GetCharactersDirection( BidiInfoIndex bidiInfoIndex,
+                               CharacterDirection* directions,
+                               Length numberOfCharacters );
 };
 
 } // namespace TextAbstraction
index b4e48ab..1bbc1e4 100644 (file)
@@ -27,16 +27,17 @@ namespace Dali
 namespace TextAbstraction
 {
 
-typedef uint32_t FontId;          ///< The unique identifier for a font face (generated by FontClient)
-typedef uint32_t PointSize26Dot6; ///< The point size in 26.6 fractional points
-typedef uint32_t FaceIndex;       ///< Used with fonts which allow several font faces
-typedef uint32_t GlyphIndex;      ///< Uniquely identifies a glyph within a particular font
-typedef uint32_t Character;       ///< A UTF-32 representation of a character
-typedef uint32_t CharacterIndex;  ///< An index into an array of characters
-typedef uint32_t Length;          ///< The length of an array
-typedef uint32_t BidiInfoIndex;   ///< Index to the bidirectional info for a paragraph.
-typedef char     LineBreakInfo;   ///< Line break info (must break, allow break, no break).
-typedef char     WordBreakInfo;   ///< Word break info (break, no break).
+typedef uint32_t FontId;             ///< The unique identifier for a font face (generated by FontClient)
+typedef uint32_t PointSize26Dot6;    ///< The point size in 26.6 fractional points
+typedef uint32_t FaceIndex;          ///< Used with fonts which allow several font faces
+typedef uint32_t GlyphIndex;         ///< Uniquely identifies a glyph within a particular font
+typedef uint32_t Character;          ///< A UTF-32 representation of a character
+typedef uint32_t CharacterIndex;     ///< An index into an array of characters
+typedef uint32_t Length;             ///< The length of an array
+typedef uint32_t BidiInfoIndex;      ///< Index to the bidirectional info for a paragraph.
+typedef char     LineBreakInfo;      ///< Line break info (must break, allow break, no break).
+typedef char     WordBreakInfo;      ///< Word break info (break, no break).
+typedef bool     CharacterDirection; ///< The character's direction: @e false is left to right, @e true is right to left.
 
 /**
  * @brief Enumerates the possible line break info values.