TextView - Right to Left implementation.
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-view / split-by-char-policies.cpp
index 5563ff5..613b0a6 100644 (file)
@@ -50,7 +50,7 @@ Vector3 NoShrinkWhenExceedPosition( const TextViewRelayout::RelayoutParameters&
         ( wordOffset + relayoutParameters.mCharacterSize.width > relayoutData.mTextViewSize.width ) ) )
   {
     if( !relayoutParameters.mIsNewLine &&
-        ( relayoutParameters.mIsWhiteSpace || relayoutParameters.mIsNewLineCharacter ) )
+        ( relayoutParameters.mIsWhiteSpace || relayoutParameters.mIsNewParagraphCharacter ) )
     {
       // Current character is a white space. Don't want to move a white space to the next line.
       // These white spaces are placed just in the edge.
@@ -59,31 +59,23 @@ Vector3 NoShrinkWhenExceedPosition( const TextViewRelayout::RelayoutParameters&
     else
     {
       // Calculate the line length and the max character height for the current line.
-      TextViewRelayout::SubLineLayoutInfo subLineInfo;
+      TextViewRelayout::LineLayoutInfo subLineInfo;
       subLineInfo.mLineLength = 0.f;
       subLineInfo.mMaxCharHeight = 0.f;
       subLineInfo.mMaxAscender = 0.f;
-      const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + relayoutParameters.mIndices.mLineIndex ) );
+      const TextViewProcessor::ParagraphLayoutInfo& paragraphLayoutInfo( *( relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.begin() + relayoutParameters.mIndices.mParagraphIndex ) );
 
-      TextViewRelayout::CalculateSubLineLayout( relayoutData.mTextViewSize.width,
-                                                relayoutParameters.mIndices,
-                                                lineLayoutInfo,
-                                                TextViewRelayout::WrapByCharacter,
-                                                1.f, // Shrink factor
-                                                subLineInfo );
-
-      // Stores some info to calculate the line justification in a post-process.
-      TextView::LineJustificationInfo justificationInfo;
-
-      justificationInfo.mIndices = relayoutParameters.mIndices;
-      justificationInfo.mLineLength = subLineInfo.mLineLength;
-
-      relayoutData.mLineJustificationInfo.push_back( justificationInfo );
+      TextViewRelayout::CalculateLineLayout( relayoutData.mTextViewSize.width,
+                                             relayoutParameters.mIndices,
+                                             paragraphLayoutInfo,
+                                             TextViewRelayout::WrapByCharacter,
+                                             1.f, // Shrink factor
+                                             subLineInfo );
 
       Toolkit::TextView::LineLayoutInfo lineInfo;
       lineInfo.mCharacterGlobalIndex = relayoutParameters.mCharacterGlobalIndex;    // Index to the first character of the next line.
-      lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of line.
-      lineInfo.mAscender = subLineInfo.mMaxAscender;                                // Ascender of this piece of line.
+      lineInfo.mSize = Size( subLineInfo.mLineLength, subLineInfo.mMaxCharHeight ); // Size of this piece of paragraph.
+      lineInfo.mAscender = subLineInfo.mMaxAscender;                                // Ascender of this piece of paragraph.
       relayoutData.mLines.push_back( lineInfo );
 
       return Vector3( 0.f, previousPositionY + subLineInfo.mMaxCharHeight + layoutParameters.mLineHeightOffset, 0.f );
@@ -115,103 +107,92 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter
 
   relayoutParameters.mPositionOffset = Vector3::ZERO;
   relayoutParameters.mIsFirstCharacter = true;
-  relayoutParameters.mIndices.mLineIndex = 0;
-  relayoutParameters.mCharacterGlobalIndex = 0;
+  relayoutParameters.mIndices.mParagraphIndex = 0u;
+  relayoutParameters.mCharacterGlobalIndex = 0u;
 
-  for( TextViewProcessor::LineLayoutInfoContainer::iterator lineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin(),
-         endLineLayoutIt = relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end();
-       lineLayoutIt != endLineLayoutIt;
-       ++lineLayoutIt, ++relayoutParameters.mIndices.mLineIndex )
+  for( TextViewProcessor::ParagraphLayoutInfoContainer::iterator paragraphLayoutIt = relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.begin(),
+         endParagraphLayoutIt = relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.end();
+       paragraphLayoutIt != endParagraphLayoutIt;
+       ++paragraphLayoutIt, ++relayoutParameters.mIndices.mParagraphIndex )
   {
-    TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *lineLayoutIt );
+    TextViewProcessor::ParagraphLayoutInfo& paragraphLayoutInfo( *paragraphLayoutIt );
 
     relayoutParameters.mIsNewLine = true;
-    relayoutParameters.mLineSize = lineLayoutInfo.mSize;
-    relayoutParameters.mIndices.mGroupIndex = 0;
+    relayoutParameters.mParagraphSize = paragraphLayoutInfo.mSize;
+    relayoutParameters.mIndices.mWordIndex = 0u;
 
-    for( TextViewProcessor::WordGroupLayoutInfoContainer::iterator groupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.begin(),
-           endGroupLayoutIt = lineLayoutInfo.mWordGroupsLayoutInfo.end();
-         groupLayoutIt != endGroupLayoutIt;
-         ++groupLayoutIt, ++relayoutParameters.mIndices.mGroupIndex )
+    for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = paragraphLayoutInfo.mWordsLayoutInfo.begin(),
+           endWordLayoutIt = paragraphLayoutInfo.mWordsLayoutInfo.end();
+         wordLayoutIt != endWordLayoutIt;
+         ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
     {
-      TextViewProcessor::WordGroupLayoutInfo& wordGroupLayoutInfo( *groupLayoutIt );
+      TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
+      relayoutParameters.mIsWhiteSpace = TextViewProcessor::WordSeparator == wordLayoutInfo.mType;
+      relayoutParameters.mIsNewParagraphCharacter = TextViewProcessor::ParagraphSeparator == wordLayoutInfo.mType;
+
+      relayoutParameters.mIsFirstCharacterOfWord = true;
+      relayoutParameters.mWordSize = wordLayoutInfo.mSize;
+      relayoutParameters.mIndices.mCharacterIndex = 0u;
+
+      for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
+             endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
+           characterLayoutIt != endCharacterLayoutIt;
+           ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex )
+      {
+        TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
 
-      relayoutParameters.mIndices.mWordIndex = 0;
+        relayoutParameters.mCharacterSize = characterLayoutInfo.mSize;
 
-      for( TextViewProcessor::WordLayoutInfoContainer::iterator wordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.begin(),
-             endWordLayoutIt = wordGroupLayoutInfo.mWordsLayoutInfo.end();
-           wordLayoutIt != endWordLayoutIt;
-           ++wordLayoutIt, ++relayoutParameters.mIndices.mWordIndex )
-      {
-        TextViewProcessor::WordLayoutInfo& wordLayoutInfo( *wordLayoutIt );
-        relayoutParameters.mIsWhiteSpace = TextViewProcessor::WordSeparator == wordLayoutInfo.mType;
-        relayoutParameters.mIsNewLineCharacter = TextViewProcessor::LineSeparator == wordLayoutInfo.mType;
-
-        relayoutParameters.mIsFirstCharacterOfWord = true;
-        relayoutParameters.mWordSize = wordLayoutInfo.mSize;
-        relayoutParameters.mIndices.mCharacterIndex = 0;
-
-        for( TextViewProcessor::CharacterLayoutInfoContainer::iterator characterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.begin(),
-               endCharacterLayoutIt = wordLayoutInfo.mCharactersLayoutInfo.end();
-             characterLayoutIt != endCharacterLayoutIt;
-             ++characterLayoutIt, ++relayoutParameters.mIndices.mCharacterIndex )
+        switch( layoutParameters.mExceedPolicy )
         {
-          TextViewProcessor::CharacterLayoutInfo& characterLayoutInfo( *characterLayoutIt );
-
-          relayoutParameters.mCharacterSize = characterLayoutInfo.mSize;
+          case TextView::OriginalShrink:
+          case TextView::SplitOriginal:
+          case TextView::SplitFade:
+          case TextView::SplitEllipsizeEnd:
+          case TextView::SplitShrink:
+          case TextView::ShrinkOriginal:
+          case TextView::ShrinkFade:
+          case TextView::Shrink:
+          case TextView::EllipsizeEndOriginal:
+          case TextView::EllipsizeEnd: // Fall Through
+          {
+            DALI_LOG_WARNING( "SplitByChar::CalculateSizeAndPosition() policy not implemented.\n" );
+            break;
+          }
+          case TextView::OriginalFade:
+          case TextView::FadeOriginal:
+          case TextView::Original:
+          case TextView::Fade: // Fall Through
+          {
+            characterLayoutInfo.mPosition = NoShrinkWhenExceedPosition( relayoutParameters,
+                                                                        layoutParameters,
+                                                                        relayoutData );
 
-          switch( layoutParameters.mExceedPolicy )
+            relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
+            break;
+          }
+          default:
           {
-            case TextView::OriginalShrink:
-            case TextView::SplitOriginal:
-            case TextView::SplitFade:
-            case TextView::SplitEllipsizeEnd:
-            case TextView::SplitShrink:
-            case TextView::ShrinkOriginal:
-            case TextView::ShrinkFade:
-            case TextView::Shrink:
-            case TextView::EllipsizeEndOriginal:
-            case TextView::EllipsizeEnd: // Fall Through
-            {
-              DALI_LOG_WARNING( "SplitByChar::CalculateSizeAndPosition() policy not implemented.\n" );
-              break;
-            }
-            case TextView::OriginalFade:
-            case TextView::FadeOriginal:
-            case TextView::Original:
-            case TextView::Fade: // Fall Through
-            {
-              characterLayoutInfo.mPosition = NoShrinkWhenExceedPosition( relayoutParameters,
-                                                                          layoutParameters,
-                                                                          relayoutData );
-
-              relayoutParameters.mPositionOffset = characterLayoutInfo.mPosition + Vector3( characterLayoutInfo.mSize.width, 0.f, 0.f );
-              break;
-            }
-            default:
-            {
-              DALI_LOG_WARNING( "SplitByChar::CalculateSizeAndPosition() policy combination not possible.\n" );
-            }
+            DALI_LOG_WARNING( "SplitByChar::CalculateSizeAndPosition() policy combination not possible.\n" );
           }
+        }
+
+        // Get last line info and calculate the bearing (used to align glyphs with the baseline).
+        TextViewRelayout::CalculateBearing( characterLayoutInfo, relayoutData );
+
+        // updates min and max position to calculate the text size for split by char.
+        TextViewRelayout::UpdateLayoutInfoTable( minMaxXY,
+                                                 wordLayoutInfo,
+                                                 characterLayoutInfo,
+                                                 relayoutParameters,
+                                                 relayoutData );
 
-          // Get last line info and calculate the bearing (used to align glyphs with the baseline).
-          TextViewRelayout::CalculateBearing( characterLayoutInfo, relayoutData );
-
-          // updates min and max position to calculate the text size for split by char.
-          TextViewRelayout::UpdateLayoutInfoTable( minMaxXY,
-                                                   wordGroupLayoutInfo,
-                                                   wordLayoutInfo,
-                                                   characterLayoutInfo,
-                                                   relayoutParameters,
-                                                   relayoutData );
-
-          ++relayoutParameters.mCharacterGlobalIndex;
-          relayoutParameters.mIsFirstCharacter = false;
-          relayoutParameters.mIsNewLine = false;
-        } // end characters
-      } // end words
-    } // end group of words
-  } // end lines
+        ++relayoutParameters.mCharacterGlobalIndex;
+        relayoutParameters.mIsFirstCharacter = false;
+        relayoutParameters.mIsNewLine = false;
+      } // end characters
+    } // end words
+  } // end paragraphs
 
   if( relayoutData.mCharacterLayoutInfoTable.empty() )
   {
@@ -223,14 +204,14 @@ void CalculateSizeAndPosition( const TextView::LayoutParameters& layoutParameter
     relayoutData.mTextSizeForRelayoutOption.height = minMaxXY.w - minMaxXY.y;
   }
 
-  // Check if the last character is a new line character. In that case the height should be added.
-  if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() )
+  // Check if the last character is a new paragraph character. In that case the height should be added.
+  if( !relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.empty() )
   {
-    const TextViewProcessor::LineLayoutInfo& lineLayoutInfo( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.end() - 1 ) );
+    const TextViewProcessor::ParagraphLayoutInfo& paragraphLayoutInfo( *( relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.end() - 1u ) );
 
-    if( lineLayoutInfo.mWordGroupsLayoutInfo.empty() ) // if it's empty, it means the last character is a new line character.
+    if( paragraphLayoutInfo.mWordsLayoutInfo.empty() ) // if it's empty, it means the last character is a new paragraph character.
     {
-      relayoutData.mTextSizeForRelayoutOption.height += lineLayoutInfo.mSize.height;
+      relayoutData.mTextSizeForRelayoutOption.height += paragraphLayoutInfo.mSize.height;
     }
   }
 }
@@ -245,10 +226,11 @@ void Relayout( Actor textView,
 {
   if( relayoutOperationMask & TextView::RELAYOUT_SIZE_POSITION )
   {
-    relayoutData.mLineJustificationInfo.clear();
     CalculateSizeAndPosition( layoutParameters,
                               relayoutData );
 
+    TextViewRelayout::ReorderRightToLeftLayout( relayoutData );
+
     TextViewRelayout::SetUnderlineInfo( relayoutData );
   }
 
@@ -265,22 +247,18 @@ void Relayout( Actor textView,
                                         relayoutData );
   }
 
-  if( relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS )
-  {
-    TextViewProcessor::InitializeTextActorInfo( relayoutData );
-  }
-
-  if( relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE )
+  const bool initializeTextActors = relayoutOperationMask & TextView::RELAYOUT_INITIALIZE_TEXT_ACTORS;
+  const bool updateTextActors = relayoutOperationMask & TextView::RELAYOUT_TEXT_ACTOR_UPDATE;
+  if( initializeTextActors || updateTextActors )
   {
     TextViewRelayout::UpdateTextActorInfo( visualParameters,
-                                           relayoutData );
+                                           relayoutData,
+                                           initializeTextActors );
   }
 
-  if( ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW ) ||
-      ( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ) )
+  if( relayoutOperationMask & TextView::RELAYOUT_INSERT_TO_TEXT_VIEW )
   {
-    TextViewRelayout::InsertToTextView( relayoutOperationMask,
-                                        textView,
+    TextViewRelayout::InsertToTextView( textView,
                                         relayoutData );
   }
 }