2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/public-api/markup-processor/markup-processor.h>
22 #include <dali/public-api/text/text.h>
35 namespace MarkupProcessor
40 const std::string WEB_COLOR_TOKEN( "#" );
41 const std::string HEX_COLOR_TOKEN( "0x" );
42 const std::string ALPHA_ONE( "FF" );
44 const std::string BLACK_COLOR( "black" );
45 const std::string WHITE_COLOR( "white" );
46 const std::string RED_COLOR( "red" );
47 const std::string GREEN_COLOR( "green" );
48 const std::string BLUE_COLOR( "blue" );
49 const std::string YELLOW_COLOR( "yellow" );
50 const std::string MAGENTA_COLOR( "magenta" );
51 const std::string CYAN_COLOR( "cyan" );
52 const std::string TRANSPARENT_COLOR( "transparent" );
54 const std::string XHTML_B_TAG("b");
55 const std::string XHTML_I_TAG("i");
56 const std::string XHTML_U_TAG("u");
57 const std::string XHTML_BR_TAG("br");
58 const std::string XHTML_FONT_TAG("font");
59 const std::string XHTML_SHADOW_TAG("shadow");
60 const std::string XHTML_GLOW_TAG("glow");
61 const std::string XHTML_OUTLINE_TAG("outline");
62 const std::string XHTML_SMOOTH_EDGE_TAG("smooth");
63 const std::string XHTML_SIZE_PROPERTY("size");
64 const std::string XHTML_COLOR_PROPERTY("color");
65 const std::string XHTML_FACE_PROPERTY("face");
66 const std::string XHTML_STYLE_PROPERTY("style");
67 const std::string XHTML_PARAM_PROPERTY("param");
68 const std::string XHTML_PARAM_X_PROPERTY("paramx");
69 const std::string XHTML_PARAM_Y_PROPERTY("paramy");
71 const char LESS_THAN( '<' );
72 const char GREATER_THAN( '>' );
73 const char EQUAL( '=' );
74 const char QUOTATION_MARK( '\'');
75 const char LINE_SEPARATOR_CR( 0x0D ); // Carriage return character CR
76 const char LINE_SEPARATOR_LF( 0x0A ); // New line character LF
77 const char SLASH( '/' );
78 const char BACK_SLASH( '\\' );
80 const std::string LINE_SEPARATOR_LF_STRING(1 , LINE_SEPARATOR_LF); ///< a string with 1 line separator character
82 * Stores a property pair: name, value.
86 Property( const std::string& n, const std::string& v )
97 * Compare if two strings are equal.
99 * The comparison is case insensitive.
101 * @param[in] string1 First of the two strings to be compared.
102 * @param[in] string2 Second of the strings to be compared.
104 * @return \e true if both strings are equal (case insensitive).
106 bool CaseInsensitiveComparison( const std::string& string1, const std::string& string2 )
108 const std::size_t stringSize = string1.size();
109 if( stringSize != string2.size() )
111 // Early return. Strings have different sizes.
116 for( std::size_t index = 0; equal && ( index < stringSize ); ++index )
118 if( std::toupper( *( string1.begin() + index ) ) != std::toupper( *( string2.begin() + index ) ) )
128 * Converts a string into a float value.
129 * @param[in] floatStr A float packed inside a string.
130 * @return The float value.
132 float StringToFloat( const std::string& floatStr )
136 std::istringstream( floatStr ) >> ret;
142 * Converts a float into a string.
143 * @param[in] value. A float.
144 * @return The float packed into a string.
146 std::string FloatToString( float value )
148 std::ostringstream stream;
155 * Converts a string into an hexadecimal unsigned int.
156 * @param[in] uintStr An hexadecimal unsigned int packed inside a string.
157 * @return The hexadecimal value.
159 unsigned int StringToHex( const std::string& uintStr )
161 unsigned int ret = 0;
163 std::string str( uintStr );
164 if( uintStr.size() <= 8 )
166 str.insert( 2, std::string( "ff" ) );
169 std::istringstream( str ) >> std::hex >> ret;
175 * Converts an hexadecimal value into a string.
176 * @param[in] value. An hexadecimal value.
177 * @return The hexadecimal value packed inside a string.
179 std::string HexToString( unsigned int value )
181 std::ostringstream stream;
182 stream << std::hex << value;
187 * Converts an ARGB color packed in 4 byte unsigned int into a Vector4 color used in Dali.
188 * @param[in] color An ARGB color packed in an unsigned int.
189 * @param[out] retColor A Vector4 with the converted color.
191 void UintColorToVector4( unsigned int color, Vector4& retColor )
193 retColor.a = static_cast<float>( ( color & 0xFF000000 ) >> 24 ) / 255.f;
194 retColor.r = static_cast<float>( ( color & 0x00FF0000 ) >> 16 ) / 255.f;
195 retColor.g = static_cast<float>( ( color & 0x0000FF00 ) >> 8 ) / 255.f;
196 retColor.b = static_cast<float>( color & 0x000000FF ) / 255.f;
200 * Converts an ARGB Vector4 color into a 4 byte packed inside an unsigned int.
201 * @param[in] color A Vector4 with an ARGB color.
202 * @return An unsigned int with the converted color.
204 unsigned int Vector4ColorToUint( const Vector4& color )
206 unsigned int retColor = 0;
208 retColor = static_cast<unsigned int>( color.a * 255.f ) << 24;
209 retColor += static_cast<unsigned int>( color.r * 255.f ) << 16;
210 retColor += static_cast<unsigned int>( color.g * 255.f ) << 8;
211 retColor += static_cast<unsigned int>( color.b * 255.f );
217 * Converts a color packed inside a string into an ARGB Vector4 color.
218 * The string color could be in hexadecimal ( 0xFF0000FF ), webcolor ( #0000FF or #00F ) or some constant values:
219 * black, white, red, green, blue, yellow, magenta, cyan, transparent.
220 * @param[in] colorStr A color packed inside a string..
221 * @param[out] retColor A color packed inside a Vector4.
223 void ColorStringToVector4( const std::string& colorStr, Vector4& retColor )
225 std::string subStr1 = colorStr.substr( 0, 1 );
226 std::string subStr2 = colorStr.substr( 0, 2 );
228 if( WEB_COLOR_TOKEN == subStr1 )
230 std::string webColor( colorStr.begin() + 1, colorStr.end() );
231 if( 3 == webColor.size() ) // 3 component web color #F00 (red)
233 webColor.insert( 2, &( webColor[2] ), 1 );
234 webColor.insert( 1, &( webColor[1] ), 1 );
235 webColor.insert( 0, &( webColor[0] ), 1 );
236 webColor.insert( 0, ALPHA_ONE );
238 else if( 6 == webColor.size() ) // 6 component web color #FF0000 (red)
240 webColor.insert( 0, ALPHA_ONE );
242 webColor.insert( 0, HEX_COLOR_TOKEN );
244 UintColorToVector4( StringToHex( webColor ), retColor );
246 else if( CaseInsensitiveComparison( HEX_COLOR_TOKEN, subStr2 ) )
248 UintColorToVector4( StringToHex( colorStr ), retColor );
250 else if( CaseInsensitiveComparison( BLACK_COLOR, colorStr ) )
252 retColor = Color::BLACK;
254 else if( CaseInsensitiveComparison( WHITE_COLOR, colorStr ) )
256 retColor = Color::WHITE;
258 else if( CaseInsensitiveComparison( RED_COLOR, colorStr ) )
260 retColor = Color::RED;
262 else if( CaseInsensitiveComparison( GREEN_COLOR, colorStr ) )
264 retColor = Color::GREEN;
266 else if( CaseInsensitiveComparison( BLUE_COLOR, colorStr ) )
268 retColor = Color::BLUE;
270 else if( CaseInsensitiveComparison( YELLOW_COLOR, colorStr ) )
272 retColor = Color::YELLOW;
274 else if( CaseInsensitiveComparison( MAGENTA_COLOR, colorStr ) )
276 retColor = Color::MAGENTA;
278 else if( CaseInsensitiveComparison( CYAN_COLOR, colorStr ) )
280 retColor = Color::CYAN;
282 else if( CaseInsensitiveComparison( TRANSPARENT_COLOR, colorStr ) )
284 retColor = Color::TRANSPARENT;
289 * Converts a color packed inside a Vector4 into a string.
290 * The string color could be in hexadecimal ( 0xFF0000FF ), webcolor ( #0000FF or #00F ) or some constant values:
291 * black, white, red, green, blue, yellow, magenta, cyan, transparent.
292 * @param[in] color A color packed inside a Vector4
293 * @return The color packed inside a string.
295 std::string Vector4ToColorString( const Vector4& color )
297 std::string colorStr;
299 if( Color::BLACK == color )
301 colorStr = BLACK_COLOR;
303 else if( Color::WHITE == color )
305 colorStr = WHITE_COLOR;
307 else if( Color::RED == color )
309 colorStr = RED_COLOR;
311 else if( Color::GREEN == color )
313 colorStr = GREEN_COLOR;
315 else if( Color::BLUE == color )
317 colorStr = BLUE_COLOR;
319 else if( Color::YELLOW == color )
321 colorStr = YELLOW_COLOR;
323 else if( Color::MAGENTA == color )
325 colorStr = MAGENTA_COLOR;
327 else if( Color::CYAN == color )
329 colorStr = CYAN_COLOR;
331 else if( Color::TRANSPARENT == color )
333 colorStr = TRANSPARENT_COLOR;
337 colorStr = HEX_COLOR_TOKEN + HexToString( Vector4ColorToUint( color ) );
344 * Skips any unnecessary white space.
345 * @param[in,out] it Iterator pointing to the current character of the markup string which is being parsed.
346 * @param[in] endIt Iterator pointing to the end of the markup string.
348 void SkipWhiteSpace( std::string::const_iterator& it, const std::string::const_iterator& endIt )
351 for( ; ( !found ) && ( it != endIt ); ++it )
353 if( !isspace( *it ) )
362 * Adds a line separator 'LF' character to the given styled text array.
363 * @param[in] style The current style.
364 * @param[in,out] styledTextArray The given styled text array.
366 void AddNewLineChar( const TextStyle& style, StyledTextArray& styledTextArray )
368 const Text text( LINE_SEPARATOR_LF_STRING );
369 styledTextArray.push_back( StyledText( text, style ) );
373 * Adds text to the given styled text array.
374 * It splits the text in characters.
375 * @param[in] textToBeStored The text to be stored.
376 * @param[in] styleToBeStored The current style.
377 * @param[in,out] styledTextArray The given styled text array.
379 void AddText( const std::string& textToBeStored, const TextStyle& styleToBeStored, StyledTextArray& styledTextArray )
381 const Text text( textToBeStored );
382 for( size_t i = 0, length = text.GetLength(); i < length; ++i )
384 styledTextArray.push_back( StyledText( Text( text[i] ), styleToBeStored ) );
389 * Splits the tag string into the tag name and its properties.
390 * @param[in] tag The tag string with its pairs property, value.
391 * @param[out] tagName The name of the tag.
392 * @param[out] properties Vector of properties.
394 void ParseProperties( const std::string& tag, std::string& tagName, std::vector<Property>& properties )
396 // Find first the tag name.
398 bool isQuotationOpen = false;
399 std::string::const_iterator it, endIt;
400 for( it = tag.begin(), endIt = tag.end(); ( !found ) && ( it != endIt ); ++it )
402 const char character( *it );
403 if( !isspace( character ) )
405 tagName += character;
412 SkipWhiteSpace( it, endIt );
414 // Find the properties.
417 bool addToNameValue = true;
418 for( ; it != endIt; ++it )
420 const char character( *it );
421 if( isspace( character ) && !isQuotationOpen )
423 if( !name.empty() && !value.empty() )
425 // Every time a white space is found, a new property is created and stored in the properties vector.
426 properties.push_back( Property( name, value ) );
429 addToNameValue = true; // next read characters will be added to the name.
432 else if( EQUAL == character ) // '='
434 addToNameValue = false; // next read characters will be added to the value.
435 SkipWhiteSpace( it, endIt );
437 else if( QUOTATION_MARK == character ) // '\''
439 // Do not add quotation marks to neither name nor value.
440 isQuotationOpen = !isQuotationOpen;
444 // Adds characters to the name or the value.
455 if( !name.empty() && !value.empty() )
457 // Checks if the last property needs to be added.
458 properties.push_back( Property( name, value ) );
463 * It parses a tag and its properties if the given iterator \e it is pointing at a tag beginning.
464 * @param[in,out] it Iterator pointing to the current character of the markup string which is being parsed.
465 * @param[in] endIt Iterator pointing to the end of the markup string.
466 * @param[out] tag Name of the tag.
467 * @param[out] isEndTag Whether the tag is and end tag i.e </tag_name> or not.
468 * @param[out] properties The vector with tag properties.
469 * @return \e true if the iterator \e it is pointing a markup tag. Otherwise \e false.
471 bool IsTag( std::string::const_iterator& it, const std::string::const_iterator& endIt, std::string& tag, bool& isEndTag, std::vector<Property>& properties )
474 bool isQuotationOpen = false;
475 bool propertiesFound = false;
476 std::string tagString;
478 const char character( *it );
479 if( LESS_THAN == character ) // '<'
481 // if the iterator is pointing to a '<' character, then check if it's a markup tag is needed.
485 SkipWhiteSpace( it, endIt );
487 for( ; ( !isTag ) && ( it != endIt ); ++it )
489 const char character( *it );
491 if( SLASH == character ) // '/'
493 // if the tag has a '/' then it's an end or empty tag.
496 if( ( it + 1 != endIt ) && ( isspace( *( it + 1 ) ) ) && ( !isQuotationOpen ) )
499 SkipWhiteSpace( it, endIt );
503 else if( GREATER_THAN == character ) // '>'
507 else if(QUOTATION_MARK == character)
509 isQuotationOpen = !isQuotationOpen;
510 tagString += character;
512 else if( isspace( character ) ) // ' '
514 // If the tag contains white spaces then it may have properties.
515 if ( !isQuotationOpen )
517 propertiesFound = true;
519 tagString += character;
523 // If it's not any of the 'special' characters then just add it to the tag string.
524 tagString += character;
531 // If the tag string has white spaces, then parse the properties is needed.
532 if( propertiesFound )
534 ParseProperties( tagString, tag, properties );
546 void GetStyledTextArray( const std::string& markupString, StyledTextArray& styledTextArray, bool scanForMarkup )
548 styledTextArray.clear();
550 if ( !scanForMarkup )
552 const Text text( markupString );
553 const std::size_t size = text.GetLength();
555 styledTextArray.resize( size, StyledText( Text(), TextStyle() ) );
557 std::size_t index = 0;
558 for( StyledTextArray::iterator it = styledTextArray.begin(), endIt = styledTextArray.end(); it != endIt; ++it, ++index )
560 StyledText& styledText( *it );
562 styledText.mText.Append( text[index] );
567 TextStyle defaultStyle;
568 std::stack<TextStyle> styleStack;
570 styleStack.push( defaultStyle );
571 TextStyle currentStyle = styleStack.top();
572 std::string textToBeStored;
573 TextStyle styleToBeStored( currentStyle );
574 for( std::string::const_iterator it = markupString.begin(), endIt = markupString.end(); it != endIt; ++it )
577 bool isEndTag = false;
578 std::vector<Property> tagProperties;
579 if( IsTag( it, endIt, tag, isEndTag, tagProperties ) )
581 if( CaseInsensitiveComparison( XHTML_I_TAG, tag ) )
585 TextStyle newStyle( currentStyle );
586 newStyle.SetItalics( true );
587 styleStack.push( newStyle );
588 currentStyle = styleStack.top();
593 currentStyle = styleStack.top();
596 else if( CaseInsensitiveComparison( XHTML_U_TAG, tag ) )
600 TextStyle newStyle( currentStyle );
601 newStyle.SetUnderline( true );
602 styleStack.push( newStyle );
603 currentStyle = styleStack.top();
608 currentStyle = styleStack.top();
611 else if( CaseInsensitiveComparison( XHTML_B_TAG, tag ) )
615 TextStyle newStyle( currentStyle );
616 newStyle.SetWeight( TextStyle::BOLD );
617 styleStack.push( newStyle );
618 currentStyle = styleStack.top();
623 currentStyle = styleStack.top();
626 else if( CaseInsensitiveComparison( XHTML_BR_TAG, tag ) )
630 AddText( textToBeStored, styleToBeStored, styledTextArray );
631 AddNewLineChar( currentStyle, styledTextArray );
632 textToBeStored.clear();
635 else if( CaseInsensitiveComparison( XHTML_FONT_TAG, tag ) )
639 TextStyle newStyle( currentStyle );
640 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
642 const Property& property( *it );
643 if( CaseInsensitiveComparison( XHTML_FACE_PROPERTY, property.name ) )
645 newStyle.SetFontName( property.value );
647 else if( CaseInsensitiveComparison( XHTML_STYLE_PROPERTY, property.name ) )
649 newStyle.SetFontStyle( property.value );
651 else if( CaseInsensitiveComparison( XHTML_COLOR_PROPERTY, property.name ) )
654 ColorStringToVector4( property.value, color );
655 newStyle.SetTextColor( color );
657 else if( CaseInsensitiveComparison( XHTML_SIZE_PROPERTY, property.name ) )
659 newStyle.SetFontPointSize( PointSize( StringToFloat( property.value ) ) );
662 styleStack.push( newStyle );
663 currentStyle = styleStack.top();
668 currentStyle = styleStack.top();
671 else if( CaseInsensitiveComparison( XHTML_SHADOW_TAG, tag ) )
675 TextStyle newStyle( currentStyle );
676 Vector4 color( TextStyle::DEFAULT_SHADOW_COLOR );
677 Vector2 offset( TextStyle::DEFAULT_SHADOW_OFFSET );
678 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
680 const Property& property( *it );
681 if( CaseInsensitiveComparison( XHTML_PARAM_X_PROPERTY, property.name ) )
683 offset.x = StringToFloat( property.value );
685 else if( CaseInsensitiveComparison( XHTML_PARAM_Y_PROPERTY, property.name ) )
687 offset.y = StringToFloat( property.value );
689 else if( CaseInsensitiveComparison( XHTML_COLOR_PROPERTY, property.name ) )
691 ColorStringToVector4( property.value, color );
694 newStyle.SetShadow( true, color, offset );
695 styleStack.push( newStyle );
696 currentStyle = styleStack.top();
701 currentStyle = styleStack.top();
703 } // <shadow></shadow>
704 else if( CaseInsensitiveComparison( XHTML_GLOW_TAG, tag ) )
708 TextStyle newStyle( currentStyle );
709 Vector4 color( TextStyle::DEFAULT_GLOW_COLOR );
710 float intensity = TextStyle::DEFAULT_GLOW_INTENSITY;
711 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
713 const Property& property( *it );
714 if( CaseInsensitiveComparison( XHTML_PARAM_PROPERTY, property.name ) )
716 intensity = StringToFloat( property.value );
718 else if( CaseInsensitiveComparison( XHTML_COLOR_PROPERTY, property.name ) )
720 ColorStringToVector4( property.value, color );
723 newStyle.SetGlow( true, color, intensity );
724 styleStack.push( newStyle );
725 currentStyle = styleStack.top();
730 currentStyle = styleStack.top();
733 else if( CaseInsensitiveComparison( XHTML_OUTLINE_TAG, tag ) )
737 TextStyle newStyle( currentStyle );
738 Vector4 color( TextStyle::DEFAULT_OUTLINE_COLOR );
739 Vector2 thickness( TextStyle::DEFAULT_OUTLINE_THICKNESS );
740 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
742 const Property& property( *it );
743 if( CaseInsensitiveComparison( XHTML_PARAM_X_PROPERTY, property.name ) )
745 thickness.x = StringToFloat( property.value );
747 else if( CaseInsensitiveComparison( XHTML_PARAM_Y_PROPERTY, property.name ) )
749 thickness.y = StringToFloat( property.value );
751 else if( CaseInsensitiveComparison( XHTML_COLOR_PROPERTY, property.name ) )
753 ColorStringToVector4( property.value, color );
756 newStyle.SetOutline( true, color, thickness );
757 styleStack.push( newStyle );
758 currentStyle = styleStack.top();
763 currentStyle = styleStack.top();
765 } // <outline></outline>
766 else if( CaseInsensitiveComparison( XHTML_SMOOTH_EDGE_TAG, tag ) )
770 TextStyle newStyle( currentStyle );
771 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
773 const Property& property( *it );
774 if( CaseInsensitiveComparison( XHTML_PARAM_PROPERTY, property.name ) )
776 newStyle.SetSmoothEdge( StringToFloat( property.value ) );
779 styleStack.push( newStyle );
780 currentStyle = styleStack.top();
785 currentStyle = styleStack.top();
787 } // <smooth></smooth>
788 } // end if( IsTag() )
791 char character( *it );
793 // Adding < or > special character.
794 if( ( BACK_SLASH == character ) && ( it + 1 != endIt ) )
796 const char nextChar( *( it + 1 ) );
797 if( ( LESS_THAN == nextChar ) || ( GREATER_THAN == nextChar ) )
799 character = nextChar;
803 else if( ( LINE_SEPARATOR_CR == character ) && ( it + 1 != endIt ) )
805 if( LINE_SEPARATOR_LF == *( it + 1 ) )
807 character = LINE_SEPARATOR_LF;
812 if( styleToBeStored != currentStyle )
814 if( !textToBeStored.empty() )
816 AddText( textToBeStored, styleToBeStored, styledTextArray );
817 textToBeStored.clear();
819 styleToBeStored = currentStyle;
821 textToBeStored.insert( textToBeStored.end(), character );
824 if( !textToBeStored.empty() )
826 AddText( textToBeStored, styleToBeStored, styledTextArray );
827 textToBeStored.clear();
831 void GetPlainString( const StyledTextArray& styledTextArray, std::string& plainString )
833 // First step is put all simultaneous characters with same style together.
834 for( StyledTextArray::const_iterator it = styledTextArray.begin(), endIt = styledTextArray.end(); it != endIt; ++it )
836 const StyledText& styledText( *it );
837 plainString += styledText.mText.GetText();
841 void GetMarkupString( const StyledTextArray& styledTextArray, std::string& markupString )
843 const std::string WHITE_SPACE( " " );
845 TextStyle previousStyle;
846 StyledText newStyledText;
847 StyledTextArray compressedStyledTextArray;
849 markupString.clear();
851 // First step is put all simultaneous characters with same style together.
852 for( StyledTextArray::const_iterator it = styledTextArray.begin(), endIt = styledTextArray.end(); it != endIt; ++it )
854 const StyledText& styledText( *it );
856 if( previousStyle != styledText.mStyle )
858 if( !newStyledText.mText.IsEmpty() )
860 compressedStyledTextArray.push_back( newStyledText );
862 newStyledText = StyledText();
863 newStyledText.mStyle = styledText.mStyle;
866 if( !styledText.mText.IsEmpty() )
868 const char character = styledText.mText.GetText()[0];
869 if( ( character == LESS_THAN ) || ( character == GREATER_THAN ) )
871 newStyledText.mText.Append( Text( std::string( &BACK_SLASH, 1 ) ) );
875 newStyledText.mText.Append( styledText.mText );
877 previousStyle = newStyledText.mStyle;
880 //Add the last characters.
881 if( !newStyledText.mText.IsEmpty() )
883 compressedStyledTextArray.push_back( newStyledText );
886 // Write markup string.
887 const std::string lineSeparatorStr( &LINE_SEPARATOR_LF );
888 const Text lineSeparator( lineSeparatorStr );
890 const TextStyle defaultStyle;
891 for( StyledTextArray::const_iterator it = compressedStyledTextArray.begin(), endIt = compressedStyledTextArray.end(); it != endIt; ++it )
893 const StyledText& styledText( *it );
895 bool isItalics = styledText.mStyle.IsItalicsEnabled();
896 bool isBold = defaultStyle.GetWeight() != styledText.mStyle.GetWeight();
897 bool isUnderline = styledText.mStyle.IsUnderlineEnabled();
898 bool hasFontFace = defaultStyle.GetFontName() != styledText.mStyle.GetFontName();
899 bool hasFontStyle = defaultStyle.GetFontStyle() != styledText.mStyle.GetFontStyle();
900 bool hasFontSize = fabsf( defaultStyle.GetFontPointSize() - styledText.mStyle.GetFontPointSize() ) > GetRangedEpsilon( defaultStyle.GetFontPointSize(), styledText.mStyle.GetFontPointSize() );
901 bool hasFontColor = defaultStyle.GetTextColor() != styledText.mStyle.GetTextColor();
903 bool hasSmooth = fabsf( defaultStyle.GetSmoothEdge() - styledText.mStyle.GetSmoothEdge() ) > GetRangedEpsilon( defaultStyle.GetSmoothEdge(), styledText.mStyle.GetSmoothEdge() );
904 bool hasShadowColor = defaultStyle.GetShadowColor() != styledText.mStyle.GetShadowColor();
905 bool hasShadowParams = defaultStyle.GetShadowOffset() != styledText.mStyle.GetShadowOffset();
906 bool hasGlowColor = defaultStyle.GetGlowColor() != styledText.mStyle.GetGlowColor();
907 bool hasGlowParams = fabsf( defaultStyle.GetGlowIntensity() - styledText.mStyle.GetGlowIntensity() ) > GetRangedEpsilon( defaultStyle.GetGlowIntensity(), styledText.mStyle.GetGlowIntensity() );
908 bool hasOutlineColor = defaultStyle.GetOutlineColor() != styledText.mStyle.GetOutlineColor();
909 bool hasOutlineParams = defaultStyle.GetOutlineThickness() != styledText.mStyle.GetOutlineThickness();
912 if( hasFontFace || hasFontStyle || hasFontSize || hasFontColor )
914 markupString += LESS_THAN + XHTML_FONT_TAG;
918 markupString += WHITE_SPACE + XHTML_FACE_PROPERTY + EQUAL + QUOTATION_MARK + styledText.mStyle.GetFontName() + QUOTATION_MARK; // face=''
923 markupString += WHITE_SPACE + XHTML_STYLE_PROPERTY + EQUAL + QUOTATION_MARK + styledText.mStyle.GetFontStyle() + QUOTATION_MARK; // style=''
928 markupString += WHITE_SPACE + XHTML_SIZE_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetFontPointSize() ) + QUOTATION_MARK; // size=''
933 markupString += WHITE_SPACE + XHTML_COLOR_PROPERTY + EQUAL + QUOTATION_MARK + Vector4ToColorString( styledText.mStyle.GetTextColor() ) + QUOTATION_MARK; // color=''
936 markupString += GREATER_THAN;
942 markupString += LESS_THAN + XHTML_I_TAG + GREATER_THAN;
948 markupString += LESS_THAN + XHTML_B_TAG + GREATER_THAN;
954 markupString += LESS_THAN + XHTML_U_TAG + GREATER_THAN;
960 markupString += LESS_THAN + XHTML_SMOOTH_EDGE_TAG + WHITE_SPACE + XHTML_PARAM_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetSmoothEdge() ) + QUOTATION_MARK + GREATER_THAN;
964 if( styledText.mStyle.IsShadowEnabled() )
966 markupString += LESS_THAN + XHTML_SHADOW_TAG;
970 markupString += WHITE_SPACE + XHTML_COLOR_PROPERTY + EQUAL + QUOTATION_MARK + Vector4ToColorString( styledText.mStyle.GetShadowColor() ) + QUOTATION_MARK;
973 if( hasShadowParams )
975 markupString += WHITE_SPACE + XHTML_PARAM_X_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetShadowOffset().x ) + QUOTATION_MARK;
976 markupString += WHITE_SPACE + XHTML_PARAM_Y_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetShadowOffset().y ) + QUOTATION_MARK;
979 markupString += GREATER_THAN;
983 if( styledText.mStyle.IsGlowEnabled() )
985 markupString += LESS_THAN + XHTML_GLOW_TAG;
989 markupString += WHITE_SPACE + XHTML_COLOR_PROPERTY + EQUAL + QUOTATION_MARK + Vector4ToColorString( styledText.mStyle.GetGlowColor() ) + QUOTATION_MARK; // color=''
994 markupString += WHITE_SPACE + XHTML_PARAM_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetGlowIntensity() ) + QUOTATION_MARK; // param=''
997 markupString += GREATER_THAN;
1001 if( styledText.mStyle.IsOutlineEnabled() )
1003 markupString += LESS_THAN + XHTML_OUTLINE_TAG;
1005 if( hasOutlineColor )
1007 markupString += WHITE_SPACE + XHTML_COLOR_PROPERTY + EQUAL + QUOTATION_MARK + Vector4ToColorString( styledText.mStyle.GetOutlineColor() ) + QUOTATION_MARK; // color = ''
1010 if( hasOutlineParams )
1012 markupString += WHITE_SPACE + XHTML_PARAM_X_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetOutlineThickness().x ) + QUOTATION_MARK; // paramx=''
1013 markupString += WHITE_SPACE + XHTML_PARAM_Y_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetOutlineThickness().y ) + QUOTATION_MARK; // paramy=''
1016 markupString += GREATER_THAN;
1020 if( styledText.mText[0] == lineSeparator[0] )
1022 markupString += LESS_THAN + XHTML_BR_TAG + WHITE_SPACE + SLASH + GREATER_THAN; // <br />
1026 markupString += styledText.mText.GetText();
1029 // Write outline close tag.
1030 if( styledText.mStyle.IsOutlineEnabled() )
1032 markupString += LESS_THAN + ( SLASH + XHTML_OUTLINE_TAG + GREATER_THAN ); // </outline>
1035 // Write glow close tag.
1036 if( styledText.mStyle.IsGlowEnabled() )
1038 markupString += LESS_THAN + ( SLASH + XHTML_GLOW_TAG + GREATER_THAN ); // </glow>
1041 // Write shadow close tag.
1042 if( styledText.mStyle.IsShadowEnabled() )
1044 markupString += LESS_THAN + ( SLASH + XHTML_SHADOW_TAG + GREATER_THAN ); // </shadow>
1047 // Write smooth close tag.
1050 markupString += LESS_THAN + ( SLASH + XHTML_SMOOTH_EDGE_TAG + GREATER_THAN ); // </smooth>
1053 // Write underline close tag.
1056 markupString += LESS_THAN + ( SLASH + XHTML_U_TAG + GREATER_THAN ); // </u>
1059 // Write bold close tag.
1062 markupString += LESS_THAN + ( SLASH + XHTML_B_TAG + GREATER_THAN ); // </b>
1065 // Write italics close tag.
1068 markupString += LESS_THAN + ( SLASH + XHTML_I_TAG + GREATER_THAN ); // </i>
1071 // Write font close tag.
1072 if( hasFontFace || hasFontStyle || hasFontSize || hasFontColor )
1074 markupString += LESS_THAN + ( SLASH + XHTML_FONT_TAG + GREATER_THAN ); // </font>
1079 void SetTextStyle( StyledTextArray& styledTextArray, const TextStyle& style, TextStyle::Mask mask )
1081 if( !styledTextArray.empty() )
1083 const size_t size = styledTextArray.size() - 1;
1084 SetTextStyleToRange( styledTextArray, style, mask, 0, size );
1088 void SetTextStyle( const Text& text, StyledTextArray& styledTextArray, const TextStyle& style, TextStyle::Mask mask )
1090 if( !text.IsEmpty() )
1092 const size_t size = text.GetLength();
1094 for( size_t i = 0; i < size; ++i )
1096 StyledText styledText;
1097 styledText.mText = Text( text[i] );
1098 styledText.mStyle = style;
1100 styledTextArray.push_back( styledText );
1103 SetTextStyleToRange( styledTextArray, style, mask, 0, size - 1 );
1107 void SetTextStyleToRange( StyledTextArray& styledTextArray, const TextStyle& style, TextStyle::Mask mask, std::size_t begin, std::size_t end )
1109 const size_t size = styledTextArray.size();
1110 DALI_ASSERT_ALWAYS( begin < size );
1111 DALI_ASSERT_ALWAYS( end < size );
1113 for( StyledTextArray::iterator it = styledTextArray.begin() + std::min(begin, end), endIt = styledTextArray.begin() + std::max(begin, end) + 1; it != endIt; ++it )
1115 StyledText& styledText( *it );
1117 styledText.mStyle.Copy( style, mask );
1121 } // namespace MarkupProcessor
1123 } // namespace Toolkit