Markup procesor - Font.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / markup-processor.cpp
index 51a1efb..53ccf0b 100644 (file)
@@ -21,6 +21,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/character-set-conversion.h>
 #include <dali-toolkit/internal/text/markup-processor-color.h>
+#include <dali-toolkit/internal/text/markup-processor-font.h>
 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
 
 namespace Dali
@@ -58,7 +59,6 @@ const char BACK_SLASH        = '\\';
 const char WHITE_SPACE       = 0x20; // ASCII value of the white space.
 
 const unsigned int MAX_NUM_OF_ATTRIBUTES =  5u; ///< The font tag has the 'family', 'size' 'weight', 'width' and 'slant' attrubutes.
-
 const unsigned int DEFAULT_VECTOR_SIZE   = 16u; ///< Default size of run vectors.
 
 /**
@@ -347,9 +347,11 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
 
   // Points the next free position in the vector of runs.
   StyleStack::RunIndex colorRunIndex = 0u;
+  StyleStack::RunIndex fontRunIndex = 0u;
 
   // Give an initial default value to the model's vectors.
   markupProcessData.colorRuns.Reserve( DEFAULT_VECTOR_SIZE );
+  markupProcessData.fontRuns.Reserve( DEFAULT_VECTOR_SIZE );
 
   // Get the mark-up string buffer.
   const char* markupStringBuffer = markupString.c_str();
@@ -398,10 +400,34 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
         if( !tag.isEndTag )
         {
           // Create a new font run.
+          FontDescriptionRun fontRun;
+          fontRun.characterRun.numberOfCharacters = 0u;
+
+          // Fill the run with the parameters.
+          fontRun.characterRun.characterIndex = characterIndex;
+          fontRun.slant = TextAbstraction::FontSlant::ITALIC;
+
+          fontRun.familyName = NULL;
+          fontRun.familyDefined = false;
+          fontRun.weightDefined = false;
+          fontRun.widthDefined = false;
+          fontRun.slantDefined = true;
+          fontRun.sizeDefined = false;
+
+          // Push the font run in the logical model.
+          markupProcessData.fontRuns.PushBack( fontRun );
+
+          // Push the index of the run into the stack.
+          styleStack.Push( fontRunIndex );
+
+          // Point the next free font run.
+          ++fontRunIndex;
         }
         else
         {
           // Pop the top of the stack and set the number of characters of the run.
+          FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
+          fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
         }
       } // <i></i>
       else if( TokenComparison( XHTML_U_TAG, tag.buffer, tag.length ) )
@@ -420,10 +446,35 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
         if( !tag.isEndTag )
         {
           // Create a new font run.
+          FontDescriptionRun fontRun;
+          fontRun.characterRun.numberOfCharacters = 0u;
+
+          // Fill the run with the parameters.
+          fontRun.characterRun.characterIndex = characterIndex;
+
+          fontRun.weight = TextAbstraction::FontWeight::BOLD;
+
+          fontRun.familyName = NULL;
+          fontRun.familyDefined = false;
+          fontRun.weightDefined = true;
+          fontRun.widthDefined = false;
+          fontRun.slantDefined = false;
+          fontRun.sizeDefined = false;
+
+          // Push the font run in the logical model.
+          markupProcessData.fontRuns.PushBack( fontRun );
+
+          // Push the index of the run into the stack.
+          styleStack.Push( fontRunIndex );
+
+          // Point the next free font run.
+          ++fontRunIndex;
         }
         else
         {
           // Pop the top of the stack and set the number of characters of the run.
+          FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
+          fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
         }
       } // <b></b>
       else if( TokenComparison( XHTML_FONT_TAG, tag.buffer, tag.length ) )
@@ -431,10 +482,35 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
         if( !tag.isEndTag )
         {
           // Create a new font run.
+          FontDescriptionRun fontRun;
+          fontRun.characterRun.numberOfCharacters = 0u;
+
+          // Fill the run with the parameters.
+          fontRun.characterRun.characterIndex = characterIndex;
+
+          fontRun.familyName = NULL;
+          fontRun.familyDefined = false;
+          fontRun.weightDefined = false;
+          fontRun.widthDefined = false;
+          fontRun.slantDefined = false;
+          fontRun.sizeDefined = false;
+
+          ProcessFontTag( tag, fontRun );
+
+          // Push the font run in the logical model.
+          markupProcessData.fontRuns.PushBack( fontRun );
+
+          // Push the index of the run into the stack.
+          styleStack.Push( fontRunIndex );
+
+          // Point the next free font run.
+          ++fontRunIndex;
         }
         else
         {
           // Pop the top of the stack and set the number of characters of the run.
+          FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
+          fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
         }
       } // <font></font>
       else if( TokenComparison( XHTML_SHADOW_TAG, tag.buffer, tag.length ) )
@@ -510,6 +586,15 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
   }
 
   // Resize the model's vectors.
+  if( 0u == fontRunIndex )
+  {
+    markupProcessData.fontRuns.Clear();
+  }
+  else
+  {
+    markupProcessData.fontRuns.Resize( fontRunIndex );
+  }
+
   if( 0u == colorRunIndex )
   {
     markupProcessData.colorRuns.Clear();