Add support for Animation::EndAction::BakeFinal to builder
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-view / text-view-processor.cpp
index b5800c8..482877a 100644 (file)
@@ -1067,16 +1067,18 @@ void InitializeTextActorInfo( TextView::RelayoutData& relayoutData )
     return;
   }
 
-  std::size_t characterGlobalIndex = 0; // Index to the global character (within the whole text).
-  std::size_t lineLayoutInfoIndex = 0;  // Index to the laid out line info.
+  std::size_t characterGlobalIndex = 0;  // Index to the global character (within the whole text).
+  std::size_t lineLayoutInfoIndex = 0;   // Index to the laid out line info.
   const std::size_t lineLayoutInfoSize = relayoutData.mLines.size(); // Number or laid out lines.
-  bool lineLayoutEnd = false;           // Whether lineLayoutInfoIndex points at the last laid out line.
+  bool lineLayoutEnd = false;            // Whether lineLayoutInfoIndex points at the last laid out line.
+  bool glyphActorCreatedForLine = false; // Whether a renderable actor has been created for this line.
 
-  TextActor currentTextActor;           // text-actor used when the edit mode is disabled.
-  TextStyle currentStyle;               // style for the current text-actor.
-  Vector4 currentGradientColor;         // gradient color for the current text-actor.
-  Vector2 currentStartPoint;            // start point for the current text-actor.
-  Vector2 currentEndPoint;              // end point for the current text-actor.
+  RenderableActor currentGlyphActor;      // text-actor used when the edit mode is disabled.
+  TextStyle currentStyle;                // style for the current text-actor.
+  Vector4 currentGradientColor;          // gradient color for the current text-actor.
+  Vector2 currentStartPoint;             // start point for the current text-actor.
+  Vector2 currentEndPoint;               // end point for the current text-actor.
+  bool currentIsColorGlyph = false;      // Whether current glyph is an emoticon.
 
   std::vector<TextActor> textActorsToRemove; // Keep a vector of text-actors to be included into the cache.
 
@@ -1104,61 +1106,85 @@ void InitializeTextActorInfo( TextView::RelayoutData& relayoutData )
         {
           CharacterLayoutInfo& characterLayout( *characterIt );
 
+          // Check if there is a new line.
+          const bool newLine = !lineLayoutEnd && ( characterGlobalIndex == relayoutData.mLines[lineLayoutInfoIndex].mCharacterGlobalIndex );
+
+          if( newLine )
+          {
+            // Point to the next line.
+            ++lineLayoutInfoIndex;
+            if( lineLayoutInfoIndex >= lineLayoutInfoSize )
+            {
+              // Arrived at last line.
+              lineLayoutEnd = true; // Avoids access out of bounds in the relayoutData.mLines vector.
+            }
+            glyphActorCreatedForLine = false;
+          }
+
           if( !characterLayout.mStyledText.mText.IsEmpty() )
           {
-            // Do not create a text-actor if there is no text.
-            const std::size_t length = characterLayout.mStyledText.mText.GetLength();
-            const Character character = characterLayout.mStyledText.mText[0];
+            // Do not create a glyph-actor if there is no text.
+            const Character character = characterLayout.mStyledText.mText[0]; // there are only one character per character layout.
 
-            if( ( 1 < length ) ||
-                ( ( 1 == length ) && character.IsWhiteSpace() && characterLayout.mStyledText.mStyle.GetUnderline() ) ||
-                ( ( 1 == length ) && !character.IsNewLine() && !character.IsWhiteSpace() ) )
+            if( characterLayout.mIsColorGlyph ||
+                !character.IsWhiteSpace() || // A new line character is also a white space.
+                ( character.IsWhiteSpace() && characterLayout.mStyledText.mStyle.GetUnderline() ) )
             {
-              // Do not create a text-actor if it's a white space (without underline) or a new line character.
-
-              // Creates one text-actor per each counsecutive group of characters, with the same style, per line.
+              // Do not create a glyph-actor if it's a white space (without underline) or a new line character.
 
-              // Check if there is a new line.
-              const bool newLine = !lineLayoutEnd && ( characterGlobalIndex == relayoutData.mLines[lineLayoutInfoIndex].mCharacterGlobalIndex );
+              // Creates one glyph-actor per each counsecutive group of characters, with the same style, per line, or if it's an emoticon.
 
-              if( ( characterLayout.mStyledText.mStyle != currentStyle ) ||
+              if( !glyphActorCreatedForLine ||
+                  characterLayout.mIsColorGlyph ||
+                  ( characterLayout.mStyledText.mStyle != currentStyle ) ||
                   ( characterLayout.mGradientColor != currentGradientColor ) ||
                   ( characterLayout.mStartPoint != currentStartPoint ) ||
                   ( characterLayout.mEndPoint != currentEndPoint ) ||
-                  newLine )
+                  ( characterLayout.mIsColorGlyph != currentIsColorGlyph ) )
               {
+                characterLayout.mSetText = false;
+                characterLayout.mSetStyle = false;
+
                 // There is a new style or a new line.
-                if( newLine )
+                glyphActorCreatedForLine = true;
+
+                if( characterLayout.mIsColorGlyph )
                 {
-                  // Point to the next line.
-                  ++lineLayoutInfoIndex;
-                  if( lineLayoutInfoIndex >= lineLayoutInfoSize )
+                  ImageActor imageActor = ImageActor::DownCast( characterLayout.mGlyphActor );
+                  if( !imageActor )
                   {
-                    // Arrived at last line.
-                    lineLayoutEnd = true;
+                    characterLayout.mGlyphActor = ImageActor::New();
+                    characterLayout.mSetText = true;
                   }
                 }
-
-                if( characterLayout.mTextActor )
-                {
-                  // Try to reuse first the text-actor of this character.
-                  currentTextActor = characterLayout.mTextActor;
-                  currentTextActor.SetTextStyle( characterLayout.mStyledText.mStyle );
-                }
                 else
                 {
-                  // If there is no text-actor, try to retrieve one from the cache.
-                  currentTextActor = relayoutData.mTextActorCache.RetrieveTextActor();
+                  TextActor textActor = TextActor::DownCast( characterLayout.mGlyphActor );
 
-                  // If still there is no text-actor, create one.
-                  if( !currentTextActor )
+                  if( textActor )
                   {
-                    currentTextActor = TextActor::New( Text(), characterLayout.mStyledText.mStyle, false, true );
+                    // Try to reuse first the text-actor of this character.
+                    textActor.SetTextStyle( characterLayout.mStyledText.mStyle );
+                    currentGlyphActor = textActor;
                   }
                   else
                   {
-                    currentTextActor.SetTextStyle( characterLayout.mStyledText.mStyle );
+                    // If there is no text-actor, try to retrieve one from the cache.
+                    textActor = relayoutData.mTextActorCache.RetrieveTextActor();
+
+                    // If still there is no text-actor, create one.
+                    if( !textActor )
+                    {
+                      textActor = TextActor::New( Text(), characterLayout.mStyledText.mStyle, false, true );
+                    }
+                    else
+                    {
+                      textActor.SetTextStyle( characterLayout.mStyledText.mStyle );
+                    }
+
+                    currentGlyphActor = textActor;
                   }
+                  characterLayout.mGlyphActor = currentGlyphActor;
                 }
 
                 // Update style to be checked with next characters.
@@ -1166,24 +1192,28 @@ void InitializeTextActorInfo( TextView::RelayoutData& relayoutData )
                 currentGradientColor = characterLayout.mGradientColor;
                 currentStartPoint = characterLayout.mStartPoint;
                 currentEndPoint = characterLayout.mEndPoint;
+                currentIsColorGlyph = characterLayout.mIsColorGlyph;
 
-                characterLayout.mSetText = false;
-                characterLayout.mSetStyle = false;
-
-                characterLayout.mTextActor = currentTextActor;
-                characterLayout.mTextActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
-                characterLayout.mTextActor.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
+                characterLayout.mGlyphActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
+                characterLayout.mGlyphActor.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
               }
               else
               {
+                DALI_ASSERT_DEBUG( !characterLayout.mIsColorGlyph && "TextViewProcessor::InitializeTextActorInfo. An image-actor doesn't store more than one emoticon." );
+
                 // Same style than previous one.
-                if( characterLayout.mTextActor )
+                TextActor textActor = TextActor::DownCast( characterLayout.mGlyphActor );
+                if( textActor )
                 {
                   // There is a previously created text-actor for this character.
                   // If this character has another one put it into the cache.
-                  characterLayout.mTextActor.SetText( "" );
-                  textActorsToRemove.push_back( characterLayout.mTextActor );
-                  characterLayout.mTextActor.Reset();
+                  textActor.SetText( "" );
+                  textActorsToRemove.push_back( textActor );
+                }
+
+                if( characterLayout.mGlyphActor )
+                {
+                  characterLayout.mGlyphActor.Reset();
                 }
               }
             } // no white space / new line char