TextView - Merges the TextActor initialization and update in one function.
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-view / text-view-word-processor.cpp
index a994407..ffca8df 100644 (file)
  */
 
 // FILE HEADER
-#include "text-view-word-processor.h"
+#include <dali-toolkit/internal/controls/text-view/text-view-word-processor.h>
 
 // INTERNAL INCLUDES
-#include <dali/dali.h>
-#include "text-view-processor-helper-functions.h"
-#include "text-view-processor-dbg.h"
+#include <dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.h>
+#include <dali-toolkit/internal/controls/text-view/text-view-processor-dbg.h>
 
 namespace Dali
 {
@@ -38,6 +37,8 @@ namespace TextViewProcessor
 namespace
 {
 
+const std::string EMOJI_FONT_NAME( "SamsungEmoji" ); // Emoticons font family name.
+
 /**
  * Updates the word size and ascender.
  *
@@ -48,7 +49,7 @@ namespace
 void UpdateLayoutInfo( WordLayoutInfo& wordLayout )
 {
   // Initialize layout info for the whole word.
-  wordLayout.mSize = Size();
+  wordLayout.mSize = Size::ZERO;
   wordLayout.mAscender = 0.f;
 
   // Traverse the character layout info to update the word layout.
@@ -98,7 +99,7 @@ WordLayoutInfo& WordLayoutInfo::operator=( const WordLayoutInfo& word )
 }
 
 void CreateWordTextInfo( const MarkupProcessor::StyledTextArray& word,
-                         TextViewProcessor::WordLayoutInfo& wordLayoutInfo )
+                         WordLayoutInfo& wordLayoutInfo )
 {
   DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, "-->TextViewProcessor::CreateWordTextInfo\n" );
   // Split in characters.
@@ -109,26 +110,33 @@ void CreateWordTextInfo( const MarkupProcessor::StyledTextArray& word,
     const std::size_t length = styledText.mText.GetLength();
 
     // It could be a group of characters.
-    for( std::size_t index = 0; index < length; ++index )
+    for( std::size_t index = 0u; index < length; ++index )
     {
       MarkupProcessor::StyledText styledCharacter;
       styledCharacter.mStyle = styledText.mStyle;
       Character character = styledText.mText[index];
       styledCharacter.mText.Append( character );
 
-      //Choose the right font for the given character and style.
-      ChooseFontFamilyName( styledCharacter );
-
-      const Font font = Font::New( FontParameters( styledCharacter.mStyle.GetFontName(), styledCharacter.mStyle.GetFontStyle(), styledCharacter.mStyle.GetFontPointSize() ) );
-      const Font::Metrics metrics = font.GetMetrics( character );
-      const float ascender = font.GetAscender();
-
       // Create layout character info.
       CharacterLayoutInfo characterLayoutInfo;
 
       characterLayoutInfo.mIsColorGlyph = GlyphImage::IsColorGlyph( character );
       DALI_LOG_INFO( gTextViewProcessorLogFilter, Debug::General, "  Is color glyph: %s\n", ( characterLayoutInfo.mIsColorGlyph ? "True" : "False" ) );
 
+      if( characterLayoutInfo.mIsColorGlyph )
+      {
+        styledCharacter.mStyle.SetFontName( EMOJI_FONT_NAME );
+      }
+      else
+      {
+        //Choose the right font for the given character and style.
+        ChooseFontFamilyName( styledCharacter );
+      }
+
+      const Font font = Font::New( FontParameters( styledCharacter.mStyle.GetFontName(), styledCharacter.mStyle.GetFontStyle(), styledCharacter.mStyle.GetFontPointSize() ) );
+      const Font::Metrics metrics = font.GetMetrics( character );
+      const float ascender = font.GetAscender();
+
       // Fill Natural size info for current character.
       characterLayoutInfo.mHeight = font.GetLineHeight();
       characterLayoutInfo.mAdvance = metrics.GetAdvance();
@@ -147,7 +155,7 @@ void CreateWordTextInfo( const MarkupProcessor::StyledTextArray& word,
       characterLayoutInfo.mSize.height = characterLayoutInfo.mHeight;
       characterLayoutInfo.mAscender = ascender;
 
-      if( styledCharacter.mStyle.GetUnderline() )
+      if( styledCharacter.mStyle.IsUnderlineEnabled() )
       {
         characterLayoutInfo.mUnderlineThickness = font.GetUnderlineThickness(); // Both thickness and position includes the
         characterLayoutInfo.mUnderlinePosition = font.GetUnderlinePosition();   // vertical pad adjust used in effects like glow or shadow.
@@ -171,33 +179,33 @@ void RemoveCharactersFromWordInfo( TextView::RelayoutData& relayoutData,
                                    const std::size_t numberOfCharacters,
                                    bool& mergeWords,
                                    bool& mergeLines,
-                                   TextViewProcessor::TextInfoIndices& textInfoIndicesBegin,
-                                   TextViewProcessor::TextInfoIndices& textInfoIndicesEnd,
-                                   TextViewProcessor::TextInfoIndices& textInfoMergeIndicesBegin,
-                                   TextViewProcessor::TextInfoIndices& textInfoMergeIndicesEnd,
-                                   TextViewProcessor::WordGroupLayoutInfo& groupLayout,
+                                   TextInfoIndices& textInfoIndicesBegin,
+                                   TextInfoIndices& textInfoIndicesEnd,
+                                   TextInfoIndices& textInfoMergeIndicesBegin,
+                                   TextInfoIndices& textInfoMergeIndicesEnd,
+                                   LineLayoutInfo& lineLayout,
                                    std::vector<TextActor>& removedTextActors )
 {
-  const TextViewProcessor::TextLayoutInfo& textLayoutInfo = relayoutData.mTextLayoutInfo;
+  const TextLayoutInfo& textLayoutInfo = relayoutData.mTextLayoutInfo;
 
   // Get the word.
-  WordLayoutInfo& wordLayout( *( groupLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex ) );
+  WordLayoutInfo& wordLayout( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex ) );
 
-  if( TextViewProcessor::LineSeparator == wordLayout.mType )
+  if( LineSeparator == wordLayout.mType )
   {
     // If the word is a line separator and there is more lines, then current line and the line after need to be merged.
-    if( textInfoIndicesBegin.mLineIndex + 1 < textLayoutInfo.mLinesLayoutInfo.size() )
+    if( textInfoIndicesBegin.mLineIndex + 1u < textLayoutInfo.mLinesLayoutInfo.size() )
     {
       // current line is not the last one.
 
       // Update indices to merge lines.
       textInfoMergeIndicesBegin.mLineIndex = textInfoIndicesBegin.mLineIndex;
-      textInfoMergeIndicesEnd.mLineIndex = textInfoIndicesBegin.mLineIndex + 1;
+      textInfoMergeIndicesEnd.mLineIndex = textInfoIndicesBegin.mLineIndex + 1u;
 
       mergeLines = true;
 
-      ++textInfoIndicesBegin.mLineIndex; // increase both indices,
-      textInfoIndicesEnd.mLineIndex +=2; // will delete last line.
+      ++textInfoIndicesBegin.mLineIndex;   // increase both indices,
+      textInfoIndicesEnd.mLineIndex += 2u; // will delete last line.
     }
 
     ++textInfoIndicesEnd.mWordIndex; //will delete the line separator;
@@ -206,21 +214,21 @@ void RemoveCharactersFromWordInfo( TextView::RelayoutData& relayoutData,
   {
     // If the word is a word separator. Check if the word before and the word after can be merged.
 
-    if( ( 0 < textInfoIndicesBegin.mWordIndex ) && ( groupLayout.mWordsLayoutInfo.size() > textInfoIndicesBegin.mWordIndex + 1 ) )
+    if( ( 0u < textInfoIndicesBegin.mWordIndex ) && ( lineLayout.mWordsLayoutInfo.size() > textInfoIndicesBegin.mWordIndex + 1u ) )
     {
-      const WordLayoutInfo& wordLayoutBefore( *( groupLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex - 1 ) );
-      const WordLayoutInfo& wordLayoutAfter( *( groupLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex + 1 ) );
+      const WordLayoutInfo& wordLayoutBefore( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex - 1u ) );
+      const WordLayoutInfo& wordLayoutAfter( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex + 1u ) );
 
       if( ( NoSeparator == wordLayoutBefore.mType ) && ( NoSeparator == wordLayoutAfter.mType ) )
       {
-        // This word is a word separator (white space) and is not the first word of the group nor the last one.
+        // This word is a word separator (white space) and is not the first word of the line nor the last one.
         mergeWords = true;
 
         // Set indices to merge the words.
-        textInfoMergeIndicesBegin.mWordIndex = textInfoIndicesBegin.mWordIndex - 1; // word before word separator.
-        textInfoMergeIndicesEnd.mWordIndex = textInfoIndicesBegin.mWordIndex + 1; // word after word separator.
+        textInfoMergeIndicesBegin.mWordIndex = textInfoIndicesBegin.mWordIndex - 1u; // word before word separator.
+        textInfoMergeIndicesEnd.mWordIndex = textInfoIndicesBegin.mWordIndex + 1u; // word after word separator.
 
-        textInfoIndicesEnd.mWordIndex += 2; // will delete the word separator and the merged word.
+        textInfoIndicesEnd.mWordIndex += 2u; // will delete the word separator and the merged word.
       }
       else
       {
@@ -256,7 +264,7 @@ void RemoveCharactersFromWord( const std::size_t position,
   // Removes a given number of characters from the given word starting from the 'position' index.
 
   // Early return.
-  if( 0 == numberOfCharacters )
+  if( 0u == numberOfCharacters )
   {
     // nothing to do if the number of characters is zero.
 
@@ -278,7 +286,7 @@ void SplitWord( const std::size_t position,
   // It moves characters from the first part of the word to the last one.
 
   // early returns
-  if( 0 == position )
+  if( 0u == position )
   {
     // the whole word goes to the last part of the word.
     lastWordLayoutInfo = firstWordLayoutInfo;
@@ -372,7 +380,7 @@ CharacterLayoutInfo GetLastCharacterLayoutInfo( const WordLayoutInfo& wordLayout
 
   if( !wordLayoutInfo.mCharactersLayoutInfo.empty() )
   {
-    layoutInfo = *( wordLayoutInfo.mCharactersLayoutInfo.end() - 1 );
+    layoutInfo = *( wordLayoutInfo.mCharactersLayoutInfo.end() - 1u );
   }
 
   return layoutInfo;
@@ -398,9 +406,9 @@ void CollectTextActors( std::vector<TextActor>& textActors, const WordLayoutInfo
   }
 }
 
-void CollectTextActorsFromWords( std::vector<TextActor>& textActors, const WordGroupLayoutInfo& group, const std::size_t wordIndexBegin, const std::size_t wordIndexEnd )
+void CollectTextActorsFromWords( std::vector<TextActor>& textActors, const LineLayoutInfo& line, const std::size_t wordIndexBegin, const std::size_t wordIndexEnd )
 {
-  for( WordLayoutInfoContainer::const_iterator wordIt = group.mWordsLayoutInfo.begin() + wordIndexBegin, wordEndIt = group.mWordsLayoutInfo.begin() + wordIndexEnd;
+  for( WordLayoutInfoContainer::const_iterator wordIt = line.mWordsLayoutInfo.begin() + wordIndexBegin, wordEndIt = line.mWordsLayoutInfo.begin() + wordIndexEnd;
        wordIt != wordEndIt;
        ++wordIt )
   {