Make alpha value pre-multiplied in all text cases
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / markup-processor.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // FILE HEADER
19 #include <dali-toolkit/internal/text/markup-processor.h>
20
21 // EXTERNAL INCLUDES
22 #include <climits>  // for ULONG_MAX
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/character-set-conversion.h>
27 #include <dali-toolkit/internal/text/markup-processor-color.h>
28 #include <dali-toolkit/internal/text/markup-processor-font.h>
29 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
30 #include <dali-toolkit/internal/text/xhtml-entities.h>
31
32
33
34 namespace Dali
35 {
36
37 namespace Toolkit
38 {
39
40 namespace Text
41 {
42
43 namespace
44 {
45 // HTML-ISH tag and attribute constants.
46 // Note they must be lower case in order to make the comparison to work
47 // as the parser converts all the read tags to lower case.
48 const std::string XHTML_COLOR_TAG("color");
49 const std::string XHTML_FONT_TAG("font");
50 const std::string XHTML_B_TAG("b");
51 const std::string XHTML_I_TAG("i");
52 const std::string XHTML_U_TAG("u");
53 const std::string XHTML_SHADOW_TAG("shadow");
54 const std::string XHTML_GLOW_TAG("glow");
55 const std::string XHTML_OUTLINE_TAG("outline");
56
57 const char LESS_THAN      = '<';
58 const char GREATER_THAN   = '>';
59 const char EQUAL          = '=';
60 const char QUOTATION_MARK = '\'';
61 const char SLASH          = '/';
62 const char BACK_SLASH     = '\\';
63 const char AMPERSAND      = '&';
64 const char HASH           = '#';
65 const char SEMI_COLON     = ';';
66 const char CHAR_ARRAY_END = '\0';
67 const char HEX_CODE       = 'x';
68
69 const char WHITE_SPACE    = 0x20; // ASCII value of the white space.
70
71 // Range 1 0x0u < XHTML_DECIMAL_ENTITY_RANGE <= 0xD7FFu
72 // Range 2 0xE000u < XHTML_DECIMAL_ENTITY_RANGE <= 0xFFFDu
73 // Range 3 0x10000u < XHTML_DECIMAL_ENTITY_RANGE <= 0x10FFFFu
74 const unsigned long XHTML_DECIMAL_ENTITY_RANGE[] = { 0x0u, 0xD7FFu, 0xE000u, 0xFFFDu, 0x10000u, 0x10FFFFu };
75
76 const unsigned int MAX_NUM_OF_ATTRIBUTES =  5u; ///< The font tag has the 'family', 'size' 'weight', 'width' and 'slant' attrubutes.
77 const unsigned int DEFAULT_VECTOR_SIZE   = 16u; ///< Default size of run vectors.
78
79 #if defined(DEBUG_ENABLED)
80 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_MARKUP_PROCESSOR");
81 #endif
82
83 /**
84  * @brief Struct used to retrieve the style runs from the mark-up string.
85  */
86 struct StyleStack
87 {
88   typedef VectorBase::SizeType RunIndex;
89
90   Vector<RunIndex>  stack;    ///< Use a vector as a style stack. Stores the indices pointing where the run is stored inside the logical model.
91   unsigned int topIndex; ///< Points the top of the stack.
92
93   StyleStack()
94   : stack(),
95     topIndex( 0u )
96   {
97     stack.Resize( DEFAULT_VECTOR_SIZE );
98   }
99
100   void Push( RunIndex index )
101   {
102     // Check if there is space inside the style stack.
103     const VectorBase::SizeType size = stack.Count();
104     if( topIndex >= size )
105     {
106       // Resize the style stack.
107       stack.Resize( 2u * size );
108     }
109
110     // Set the run index in the top of the stack.
111     *( stack.Begin() + topIndex ) = index;
112
113     // Reposition the pointer to the top of the stack.
114     ++topIndex;
115   }
116
117   RunIndex Pop()
118   {
119     // Pop the top of the stack.
120     --topIndex;
121     return *( stack.Begin() + topIndex );
122   }
123 };
124
125 /**
126  * @brief Initializes a font run description to its defaults.
127  *
128  * @param[in,out] fontRun The font description run to initialize.
129  */
130 void Initialize( FontDescriptionRun& fontRun )
131 {
132   fontRun.characterRun.characterIndex = 0u;
133   fontRun.characterRun.numberOfCharacters = 0u;
134   fontRun.familyName = NULL;
135   fontRun.familyLength = 0u;
136   fontRun.weight = TextAbstraction::FontWeight::NORMAL;
137   fontRun.width = TextAbstraction::FontWidth::NORMAL;
138   fontRun.slant = TextAbstraction::FontSlant::NORMAL;
139   fontRun.size = 0u;
140   fontRun.familyDefined = false;
141   fontRun.weightDefined = false;
142   fontRun.widthDefined = false;
143   fontRun.slantDefined = false;
144   fontRun.sizeDefined = false;
145 }
146
147 /**
148  * @brief Splits the tag string into the tag name and its attributes.
149  *
150  * The attributes are stored in a vector in the tag.
151  *
152  * @param[in,out] tag The tag.
153  */
154 void ParseAttributes( Tag& tag )
155 {
156   tag.attributes.Resize( MAX_NUM_OF_ATTRIBUTES );
157
158   // Find first the tag name.
159   bool isQuotationOpen = false;
160
161   const char* tagBuffer = tag.buffer;
162   const char* const tagEndBuffer = tagBuffer + tag.length;
163   tag.length = 0u;
164   for( ; tagBuffer < tagEndBuffer; ++tagBuffer )
165   {
166     const char character = *tagBuffer;
167     if( WHITE_SPACE < character )
168     {
169       ++tag.length;
170     }
171     else
172     {
173       // Stops counting the length of the tag when a white space is found.
174       // @note a white space is the WHITE_SPACE character and anything below as 'tab', 'return' or 'control characters'.
175       break;
176     }
177   }
178   SkipWhiteSpace( tagBuffer, tagEndBuffer );
179
180   // Find the attributes.
181   unsigned int attributeIndex = 0u;
182   const char* nameBuffer = NULL;
183   const char* valueBuffer = NULL;
184   Length nameLength = 0u;
185   Length valueLength = 0u;
186
187   bool addToNameValue = true;
188   Length numberOfWhiteSpace = 0u;
189   for( ; tagBuffer < tagEndBuffer; ++tagBuffer )
190   {
191     const char character = *tagBuffer;
192     if( ( WHITE_SPACE >= character ) && !isQuotationOpen )
193     {
194       if( NULL != valueBuffer )
195       {
196         // Remove white spaces at the end of the value.
197         valueLength -= numberOfWhiteSpace;
198       }
199
200       if( ( NULL != nameBuffer ) && ( NULL != valueBuffer ) )
201       {
202         // Every time a white space is found, a new attribute is created and stored in the attributes vector.
203         Attribute& attribute = *( tag.attributes.Begin() + attributeIndex );
204         ++attributeIndex;
205
206         attribute.nameBuffer = nameBuffer;
207         attribute.valueBuffer = valueBuffer;
208         attribute.nameLength = nameLength;
209         attribute.valueLength = valueLength;
210
211         nameBuffer = NULL;
212         valueBuffer = NULL;
213         nameLength = 0u;
214         valueLength = 0u;
215
216         addToNameValue = true; // next read characters will be added to the name.
217       }
218     }
219     else if( EQUAL == character ) // '='
220     {
221       addToNameValue = false; // next read characters will be added to the value.
222       SkipWhiteSpace( tagBuffer, tagEndBuffer );
223     }
224     else if( QUOTATION_MARK == character ) // '\''
225     {
226       // Do not add quotation marks to neither name nor value.
227       isQuotationOpen = !isQuotationOpen;
228
229       if( isQuotationOpen )
230       {
231         ++tagBuffer;
232         SkipWhiteSpace( tagBuffer, tagEndBuffer );
233         --tagBuffer;
234       }
235     }
236     else
237     {
238       // Adds characters to the name or the value.
239       if( addToNameValue )
240       {
241         if( NULL == nameBuffer )
242         {
243           nameBuffer = tagBuffer;
244         }
245         ++nameLength;
246       }
247       else
248       {
249         if( isQuotationOpen )
250         {
251           if( WHITE_SPACE >= character )
252           {
253             ++numberOfWhiteSpace;
254           }
255           else
256           {
257             numberOfWhiteSpace = 0u;
258           }
259         }
260         if( NULL == valueBuffer )
261         {
262           valueBuffer = tagBuffer;
263         }
264         ++valueLength;
265       }
266     }
267   }
268
269   if( NULL != valueBuffer )
270   {
271     // Remove white spaces at the end of the value.
272     valueLength -= numberOfWhiteSpace;
273   }
274
275   if( ( NULL != nameBuffer ) && ( NULL != valueBuffer ) )
276   {
277     // Checks if the last attribute needs to be added.
278     Attribute& attribute = *( tag.attributes.Begin() + attributeIndex );
279     ++attributeIndex;
280
281     attribute.nameBuffer = nameBuffer;
282     attribute.valueBuffer = valueBuffer;
283     attribute.nameLength = nameLength;
284     attribute.valueLength = valueLength;
285   }
286
287   // Resize the vector of attributes.
288   tag.attributes.Resize( attributeIndex );
289 }
290
291 /**
292  * @brief It parses a tag and its attributes if the given iterator @e it is pointing at a tag beginning.
293  *
294  * @param[in,out] markupStringBuffer The mark-up string buffer. It's a const iterator pointing the current character.
295  * @param[in] markupStringEndBuffer Pointer to one character after the end of the mark-up string buffer.
296  * @param[out] tag The tag with its attributes.
297  *
298  * @return @e true if the iterator @e it is pointing a mark-up tag. Otherwise @e false.
299  */
300 bool IsTag( const char*& markupStringBuffer,
301             const char* const markupStringEndBuffer,
302             Tag& tag )
303 {
304   bool isTag = false;
305   bool isQuotationOpen = false;
306   bool attributesFound = false;
307   tag.isEndTag = false;
308
309   const char character = *markupStringBuffer;
310   if( LESS_THAN == character ) // '<'
311   {
312     tag.buffer = NULL;
313     tag.length = 0u;
314
315     // if the iterator is pointing to a '<' character, then check if it's a mark-up tag is needed.
316     ++markupStringBuffer;
317     if( markupStringBuffer < markupStringEndBuffer )
318     {
319       SkipWhiteSpace( markupStringBuffer, markupStringEndBuffer );
320
321       for( ; ( !isTag ) && ( markupStringBuffer < markupStringEndBuffer ); ++markupStringBuffer )
322       {
323         const char character = *markupStringBuffer;
324
325         if( SLASH == character ) // '/'
326         {
327           // if the tag has a '/' then it's an end or empty tag.
328           tag.isEndTag = true;
329
330           if( ( markupStringBuffer + 1u < markupStringEndBuffer ) && ( WHITE_SPACE >= *( markupStringBuffer + 1u ) ) && ( !isQuotationOpen ) )
331           {
332             ++markupStringBuffer;
333             SkipWhiteSpace( markupStringBuffer, markupStringEndBuffer );
334             --markupStringBuffer;
335           }
336         }
337         else if( GREATER_THAN == character ) // '>'
338         {
339           isTag = true;
340         }
341         else if( QUOTATION_MARK == character )
342         {
343           isQuotationOpen = !isQuotationOpen;
344           ++tag.length;
345         }
346         else if( WHITE_SPACE >= character ) // ' '
347         {
348           // If the tag contains white spaces then it may have attributes.
349           if( !isQuotationOpen )
350           {
351             attributesFound = true;
352           }
353           ++tag.length;
354         }
355         else
356         {
357           if( NULL == tag.buffer )
358           {
359             tag.buffer = markupStringBuffer;
360           }
361
362           // If it's not any of the 'special' characters then just add it to the tag string.
363           ++tag.length;
364         }
365       }
366     }
367
368     // If the tag string has white spaces, then parse the attributes is needed.
369     if( attributesFound )
370     {
371       ParseAttributes( tag );
372     }
373   }
374
375   return isTag;
376 }
377
378 /**
379  * @brief Returns length of XHTML entity by parsing the text. It also determines if it is XHTML entity or not.
380  *
381  * @param[in] markupStringBuffer The mark-up string buffer. It's a const iterator pointing the current character.
382  * @param[in] markupStringEndBuffer Pointing to end of mark-up string buffer.
383  *
384  * @return Length of markupText in case of XHTML entity otherwise return 0.
385  */
386 unsigned int GetXHTMLEntityLength( const char*& markupStringBuffer,
387                                    const char* const markupStringEndBuffer )
388 {
389   char character = *markupStringBuffer;
390   if( AMPERSAND == character ) // '&'
391   {
392     // if the iterator is pointing to a '&' character, then check for ';' to find end to XHTML entity.
393     ++markupStringBuffer;
394     if( markupStringBuffer < markupStringEndBuffer )
395     {
396       unsigned int len = 1u;
397       for( ; markupStringBuffer < markupStringEndBuffer ; ++markupStringBuffer )
398       {
399         character = *markupStringBuffer;
400         ++len;
401         if( SEMI_COLON == character ) // ';'
402         {
403           // found end of XHTML entity
404           ++markupStringBuffer;
405           return len;
406         }
407         else if( ( AMPERSAND == character ) || ( BACK_SLASH == character ) || ( LESS_THAN == character ))
408         {
409           return 0;
410         }
411       }
412     }
413   }
414   return 0;
415 }
416
417 /**
418  * @brief It parses a XHTML string which has hex/decimal entity and fill its corresponging utf-8 string.
419  *
420  * @param[in] markupText The mark-up text buffer.
421  * @param[out] utf-8 text Corresponding to markup Text
422  *
423  * @return true if string is successfully parsed otherwise false
424  */
425 bool XHTMLNumericEntityToUtf8 ( const char* markupText, char* utf8 )
426 {
427   bool result = false;
428
429   if( NULL != markupText )
430   {
431     bool isHex = false;
432
433     // check if hex or decimal entity
434     if( ( CHAR_ARRAY_END != *markupText ) && ( HEX_CODE == *markupText ) )
435     {
436       isHex = true;
437       ++markupText;
438     }
439
440     char* end = NULL;
441     unsigned long l = strtoul( markupText, &end, ( isHex ? 16 : 10 ) );  // l contains UTF-32 code in case of correct XHTML entity
442
443     // check for valid XHTML numeric entities (between '#' or "#x" and ';')
444     if( ( l > 0 ) && ( l < ULONG_MAX ) && ( *end == SEMI_COLON ) ) // in case wrong XHTML entity is set eg. "&#23abcdefs;" in that case *end will be 'a'
445     {
446       /* characters XML 1.1 permits */
447       if( ( ( XHTML_DECIMAL_ENTITY_RANGE[0] < l ) && ( l <= XHTML_DECIMAL_ENTITY_RANGE[1] ) ) ||
448         ( ( XHTML_DECIMAL_ENTITY_RANGE[2] <= l ) && ( l <= XHTML_DECIMAL_ENTITY_RANGE[3] ) ) ||
449         ( ( XHTML_DECIMAL_ENTITY_RANGE[4] <= l ) && ( l <= XHTML_DECIMAL_ENTITY_RANGE[5] ) ) )
450       {
451         // Convert UTF32 code to UTF8
452         Utf32ToUtf8( reinterpret_cast<const uint32_t* const>( &l ), 1, reinterpret_cast<uint8_t*>( utf8 ) );
453         result = true;
454        }
455     }
456   }
457   return result;
458 }
459
460 } // namespace
461
462 void ProcessMarkupString( const std::string& markupString, MarkupProcessData& markupProcessData )
463 {
464   // Reserve space for the plain text.
465   const Length markupStringSize = markupString.size();
466   markupProcessData.markupProcessedText.reserve( markupStringSize );
467
468   // Stores a struct with the index to the first character of the run, the type of run and its parameters.
469   StyleStack styleStack;
470
471   // Points the next free position in the vector of runs.
472   StyleStack::RunIndex colorRunIndex = 0u;
473   StyleStack::RunIndex fontRunIndex = 0u;
474
475   // Give an initial default value to the model's vectors.
476   markupProcessData.colorRuns.Reserve( DEFAULT_VECTOR_SIZE );
477   markupProcessData.fontRuns.Reserve( DEFAULT_VECTOR_SIZE );
478
479   // Get the mark-up string buffer.
480   const char* markupStringBuffer = markupString.c_str();
481   const char* const markupStringEndBuffer = markupStringBuffer + markupStringSize;
482
483   Tag tag;
484   CharacterIndex characterIndex = 0u;
485   for( ; markupStringBuffer < markupStringEndBuffer; )
486   {
487     if( IsTag( markupStringBuffer,
488                markupStringEndBuffer,
489                tag ) )
490     {
491       if( TokenComparison( XHTML_COLOR_TAG, tag.buffer, tag.length ) )
492       {
493         if( !tag.isEndTag )
494         {
495           // Create a new color run.
496           ColorRun colorRun;
497           colorRun.characterRun.numberOfCharacters = 0u;
498
499           // Set the start character index.
500           colorRun.characterRun.characterIndex = characterIndex;
501
502           // Fill the run with the attributes.
503           ProcessColorTag( tag, colorRun );
504
505           // Push the color run in the logical model.
506           markupProcessData.colorRuns.PushBack( colorRun );
507
508           // Push the index of the run into the stack.
509           styleStack.Push( colorRunIndex );
510
511           // Point the next color run.
512           ++colorRunIndex;
513         }
514         else
515         {
516           // Pop the top of the stack and set the number of characters of the run.
517           ColorRun& colorRun = *( markupProcessData.colorRuns.Begin() + styleStack.Pop() );
518           colorRun.characterRun.numberOfCharacters = characterIndex - colorRun.characterRun.characterIndex;
519         }
520       } // <color></color>
521       else if( TokenComparison( XHTML_I_TAG, tag.buffer, tag.length ) )
522       {
523         if( !tag.isEndTag )
524         {
525           // Create a new font run.
526           FontDescriptionRun fontRun;
527           Initialize( fontRun );
528
529           // Fill the run with the parameters.
530           fontRun.characterRun.characterIndex = characterIndex;
531           fontRun.slant = TextAbstraction::FontSlant::ITALIC;
532           fontRun.slantDefined = true;
533
534           // Push the font run in the logical model.
535           markupProcessData.fontRuns.PushBack( fontRun );
536
537           // Push the index of the run into the stack.
538           styleStack.Push( fontRunIndex );
539
540           // Point the next free font run.
541           ++fontRunIndex;
542         }
543         else
544         {
545           // Pop the top of the stack and set the number of characters of the run.
546           FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
547           fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
548         }
549       } // <i></i>
550       else if( TokenComparison( XHTML_U_TAG, tag.buffer, tag.length ) )
551       {
552         if( !tag.isEndTag )
553         {
554           // Create a new underline run.
555         }
556         else
557         {
558           // Pop the top of the stack and set the number of characters of the run.
559         }
560       } // <u></u>
561       else if( TokenComparison( XHTML_B_TAG, tag.buffer, tag.length ) )
562       {
563         if( !tag.isEndTag )
564         {
565           // Create a new font run.
566           FontDescriptionRun fontRun;
567           Initialize( fontRun );
568
569           // Fill the run with the parameters.
570           fontRun.characterRun.characterIndex = characterIndex;
571           fontRun.weight = TextAbstraction::FontWeight::BOLD;
572           fontRun.weightDefined = true;
573
574           // Push the font run in the logical model.
575           markupProcessData.fontRuns.PushBack( fontRun );
576
577           // Push the index of the run into the stack.
578           styleStack.Push( fontRunIndex );
579
580           // Point the next free font run.
581           ++fontRunIndex;
582         }
583         else
584         {
585           // Pop the top of the stack and set the number of characters of the run.
586           FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
587           fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
588         }
589       } // <b></b>
590       else if( TokenComparison( XHTML_FONT_TAG, tag.buffer, tag.length ) )
591       {
592         if( !tag.isEndTag )
593         {
594           // Create a new font run.
595           FontDescriptionRun fontRun;
596           Initialize( fontRun );
597
598           // Fill the run with the parameters.
599           fontRun.characterRun.characterIndex = characterIndex;
600
601           ProcessFontTag( tag, fontRun );
602
603           // Push the font run in the logical model.
604           markupProcessData.fontRuns.PushBack( fontRun );
605
606           // Push the index of the run into the stack.
607           styleStack.Push( fontRunIndex );
608
609           // Point the next free font run.
610           ++fontRunIndex;
611         }
612         else
613         {
614           // Pop the top of the stack and set the number of characters of the run.
615           FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
616           fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
617         }
618       } // <font></font>
619       else if( TokenComparison( XHTML_SHADOW_TAG, tag.buffer, tag.length ) )
620       {
621         if( !tag.isEndTag )
622         {
623           // Create a new shadow run.
624         }
625         else
626         {
627           // Pop the top of the stack and set the number of characters of the run.
628         }
629       } // <shadow></shadow>
630       else if( TokenComparison( XHTML_GLOW_TAG, tag.buffer, tag.length ) )
631       {
632         if( !tag.isEndTag )
633         {
634           // Create a new glow run.
635         }
636         else
637         {
638           // Pop the top of the stack and set the number of characters of the run.
639         }
640       } // <glow></glow>
641       else if( TokenComparison( XHTML_OUTLINE_TAG, tag.buffer, tag.length ) )
642       {
643         if( !tag.isEndTag )
644         {
645           // Create a new outline run.
646         }
647         else
648         {
649           // Pop the top of the stack and set the number of characters of the run.
650         }
651       } // <outline></outline>
652     }  // end if( IsTag() )
653     else if( markupStringBuffer < markupStringEndBuffer )
654     {
655       unsigned char character = *markupStringBuffer;
656       const char* markupBuffer = markupStringBuffer;
657       unsigned char count = GetUtf8Length( character );
658       char utf8[8];
659
660       if( ( BACK_SLASH == character ) && ( markupStringBuffer + 1u < markupStringEndBuffer ) )
661       {
662         // Adding < , >  or & special character.
663         const unsigned char nextCharacter = *( markupStringBuffer + 1u );
664         if( ( LESS_THAN == nextCharacter ) || ( GREATER_THAN == nextCharacter ) || ( AMPERSAND == nextCharacter ) )
665         {
666           character = nextCharacter;
667           ++markupStringBuffer;
668
669           count = GetUtf8Length( character );
670           markupBuffer = markupStringBuffer;
671         }
672       }
673       else   // checking if conatins XHTML entity or not
674       {
675         const unsigned int len =  GetXHTMLEntityLength( markupStringBuffer, markupStringEndBuffer);
676
677         // Parse markupStringTxt if it contains XHTML Entity between '&' and ';'
678         if( len > 0 )
679         {
680           char* entityCode = NULL;
681           bool result = false;
682           count = 0;
683
684           // Checking if XHTML Numeric Entity
685           if( HASH == *( markupBuffer + 1u ) )
686           {
687             entityCode = &utf8[0];
688             // markupBuffer is currently pointing to '&'. By adding 2u to markupBuffer it will point to numeric string by skipping "&#'
689             result = XHTMLNumericEntityToUtf8( ( markupBuffer + 2u ), entityCode );
690           }
691           else    // Checking if XHTML Named Entity
692           {
693             entityCode = const_cast<char*> ( NamedEntityToUtf8( markupBuffer, len ) );
694             result = ( entityCode != NULL );
695           }
696           if ( result )
697           {
698             markupBuffer = entityCode; //utf8 text assigned to markupBuffer
699             character = markupBuffer[0];
700           }
701           else
702           {
703             DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Not valid XHTML entity : (%.*s) \n", len, markupBuffer );
704             markupBuffer = NULL;
705           }
706         }
707         else    // in case string conatins Start of XHTML Entity('&') but not its end character(';')
708         {
709           if( character == AMPERSAND )
710           {
711             markupBuffer = NULL;
712             DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Not Well formed XHTML content \n" );
713           }
714         }
715       }
716
717       if( markupBuffer != NULL )
718       {
719         const unsigned char numberOfBytes = GetUtf8Length( character );
720         markupProcessData.markupProcessedText.push_back( character );
721
722         for( unsigned char i = 1u; i < numberOfBytes; ++i )
723         {
724           ++markupBuffer;
725           markupProcessData.markupProcessedText.push_back( *markupBuffer );
726         }
727
728         ++characterIndex;
729         markupStringBuffer += count;
730       }
731     }
732   }
733
734   // Resize the model's vectors.
735   if( 0u == fontRunIndex )
736   {
737     markupProcessData.fontRuns.Clear();
738   }
739   else
740   {
741     markupProcessData.fontRuns.Resize( fontRunIndex );
742   }
743
744   if( 0u == colorRunIndex )
745   {
746     markupProcessData.colorRuns.Clear();
747   }
748   else
749   {
750     markupProcessData.colorRuns.Resize( colorRunIndex );
751   }
752 }
753
754 } // namespace Text
755
756 } // namespace Toolkit
757
758 } // namespace Dali