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 styledTextArray.push_back( StyledText( Text( markupString ), TextStyle() ) );
556 TextStyle defaultStyle;
557 std::stack<TextStyle> styleStack;
559 styleStack.push( defaultStyle );
560 TextStyle currentStyle = styleStack.top();
561 std::string textToBeStored;
562 TextStyle styleToBeStored( currentStyle );
563 for( std::string::const_iterator it = markupString.begin(), endIt = markupString.end(); it != endIt; ++it )
566 bool isEndTag = false;
567 std::vector<Property> tagProperties;
568 if( IsTag( it, endIt, tag, isEndTag, tagProperties ) )
570 if( CaseInsensitiveComparison( XHTML_I_TAG, tag ) )
574 TextStyle newStyle( currentStyle );
575 newStyle.SetItalics( true );
576 styleStack.push( newStyle );
577 currentStyle = styleStack.top();
582 currentStyle = styleStack.top();
585 else if( CaseInsensitiveComparison( XHTML_U_TAG, tag ) )
589 TextStyle newStyle( currentStyle );
590 newStyle.SetUnderline( true );
591 styleStack.push( newStyle );
592 currentStyle = styleStack.top();
597 currentStyle = styleStack.top();
600 else if( CaseInsensitiveComparison( XHTML_B_TAG, tag ) )
604 TextStyle newStyle( currentStyle );
605 newStyle.SetWeight( TextStyle::BOLD );
606 styleStack.push( newStyle );
607 currentStyle = styleStack.top();
612 currentStyle = styleStack.top();
615 else if( CaseInsensitiveComparison( XHTML_BR_TAG, tag ) )
619 AddText( textToBeStored, styleToBeStored, styledTextArray );
620 AddNewLineChar( currentStyle, styledTextArray );
621 textToBeStored.clear();
624 else if( CaseInsensitiveComparison( XHTML_FONT_TAG, tag ) )
628 TextStyle newStyle( currentStyle );
629 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
631 const Property& property( *it );
632 if( CaseInsensitiveComparison( XHTML_FACE_PROPERTY, property.name ) )
634 newStyle.SetFontName( property.value );
636 else if( CaseInsensitiveComparison( XHTML_STYLE_PROPERTY, property.name ) )
638 newStyle.SetFontStyle( property.value );
640 else if( CaseInsensitiveComparison( XHTML_COLOR_PROPERTY, property.name ) )
643 ColorStringToVector4( property.value, color );
644 newStyle.SetTextColor( color );
646 else if( CaseInsensitiveComparison( XHTML_SIZE_PROPERTY, property.name ) )
648 newStyle.SetFontPointSize( PointSize( StringToFloat( property.value ) ) );
651 styleStack.push( newStyle );
652 currentStyle = styleStack.top();
657 currentStyle = styleStack.top();
660 else if( CaseInsensitiveComparison( XHTML_SHADOW_TAG, tag ) )
664 TextStyle newStyle( currentStyle );
665 Vector4 color( TextStyle::DEFAULT_SHADOW_COLOR );
666 Vector2 offset( TextStyle::DEFAULT_SHADOW_OFFSET );
667 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
669 const Property& property( *it );
670 if( CaseInsensitiveComparison( XHTML_PARAM_X_PROPERTY, property.name ) )
672 offset.x = StringToFloat( property.value );
674 else if( CaseInsensitiveComparison( XHTML_PARAM_Y_PROPERTY, property.name ) )
676 offset.y = StringToFloat( property.value );
678 else if( CaseInsensitiveComparison( XHTML_COLOR_PROPERTY, property.name ) )
680 ColorStringToVector4( property.value, color );
683 newStyle.SetShadow( true, color, offset );
684 styleStack.push( newStyle );
685 currentStyle = styleStack.top();
690 currentStyle = styleStack.top();
692 } // <shadow></shadow>
693 else if( CaseInsensitiveComparison( XHTML_GLOW_TAG, tag ) )
697 TextStyle newStyle( currentStyle );
698 Vector4 color( TextStyle::DEFAULT_GLOW_COLOR );
699 float intensity = TextStyle::DEFAULT_GLOW_INTENSITY;
700 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
702 const Property& property( *it );
703 if( CaseInsensitiveComparison( XHTML_PARAM_PROPERTY, property.name ) )
705 intensity = StringToFloat( property.value );
707 else if( CaseInsensitiveComparison( XHTML_COLOR_PROPERTY, property.name ) )
709 ColorStringToVector4( property.value, color );
712 newStyle.SetGlow( true, color, intensity );
713 styleStack.push( newStyle );
714 currentStyle = styleStack.top();
719 currentStyle = styleStack.top();
722 else if( CaseInsensitiveComparison( XHTML_OUTLINE_TAG, tag ) )
726 TextStyle newStyle( currentStyle );
727 Vector4 color( TextStyle::DEFAULT_OUTLINE_COLOR );
728 Vector2 thickness( TextStyle::DEFAULT_OUTLINE_THICKNESS );
729 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
731 const Property& property( *it );
732 if( CaseInsensitiveComparison( XHTML_PARAM_X_PROPERTY, property.name ) )
734 thickness.x = StringToFloat( property.value );
736 else if( CaseInsensitiveComparison( XHTML_PARAM_Y_PROPERTY, property.name ) )
738 thickness.y = StringToFloat( property.value );
740 else if( CaseInsensitiveComparison( XHTML_COLOR_PROPERTY, property.name ) )
742 ColorStringToVector4( property.value, color );
745 newStyle.SetOutline( true, color, thickness );
746 styleStack.push( newStyle );
747 currentStyle = styleStack.top();
752 currentStyle = styleStack.top();
754 } // <outline></outline>
755 else if( CaseInsensitiveComparison( XHTML_SMOOTH_EDGE_TAG, tag ) )
759 TextStyle newStyle( currentStyle );
760 for( std::vector<Property>::const_iterator it = tagProperties.begin(), endIt = tagProperties.end(); it != endIt; ++it )
762 const Property& property( *it );
763 if( CaseInsensitiveComparison( XHTML_PARAM_PROPERTY, property.name ) )
765 newStyle.SetSmoothEdge( StringToFloat( property.value ) );
768 styleStack.push( newStyle );
769 currentStyle = styleStack.top();
774 currentStyle = styleStack.top();
776 } // <smooth></smooth>
777 } // end if( IsTag() )
780 char character( *it );
782 // Adding < or > special character.
783 if( ( BACK_SLASH == character ) && ( it + 1 != endIt ) )
785 const char nextChar( *( it + 1 ) );
786 if( ( LESS_THAN == nextChar ) || ( GREATER_THAN == nextChar ) )
788 character = nextChar;
792 else if( ( LINE_SEPARATOR_CR == character ) && ( it + 1 != endIt ) )
794 if( LINE_SEPARATOR_LF == *( it + 1 ) )
796 character = LINE_SEPARATOR_LF;
801 if( styleToBeStored != currentStyle )
803 if( !textToBeStored.empty() )
805 AddText( textToBeStored, styleToBeStored, styledTextArray );
806 textToBeStored.clear();
808 styleToBeStored = currentStyle;
810 textToBeStored.insert( textToBeStored.end(), character );
813 if( !textToBeStored.empty() )
815 AddText( textToBeStored, styleToBeStored, styledTextArray );
816 textToBeStored.clear();
820 void GetPlainString( const StyledTextArray& styledTextArray, std::string& plainString )
822 // First step is put all simultaneous characters with same style together.
823 for( StyledTextArray::const_iterator it = styledTextArray.begin(), endIt = styledTextArray.end(); it != endIt; ++it )
825 const StyledText& styledText( *it );
826 plainString += styledText.mText.GetText();
830 void GetMarkupString( const StyledTextArray& styledTextArray, std::string& markupString )
832 const std::string WHITE_SPACE( " " );
834 TextStyle previousStyle;
835 StyledText newStyledText;
836 StyledTextArray compressedStyledTextArray;
838 markupString.clear();
840 // First step is put all simultaneous characters with same style together.
841 for( StyledTextArray::const_iterator it = styledTextArray.begin(), endIt = styledTextArray.end(); it != endIt; ++it )
843 const StyledText& styledText( *it );
845 if( previousStyle != styledText.mStyle )
847 if( !newStyledText.mText.IsEmpty() )
849 compressedStyledTextArray.push_back( newStyledText );
851 newStyledText = StyledText();
852 newStyledText.mStyle = styledText.mStyle;
855 if( !styledText.mText.IsEmpty() )
857 const char character = styledText.mText.GetText()[0];
858 if( ( character == LESS_THAN ) || ( character == GREATER_THAN ) )
860 newStyledText.mText.Append( Text( std::string( &BACK_SLASH, 1 ) ) );
864 newStyledText.mText.Append( styledText.mText );
866 previousStyle = newStyledText.mStyle;
869 //Add the last characters.
870 if( !newStyledText.mText.IsEmpty() )
872 compressedStyledTextArray.push_back( newStyledText );
875 // Write markup string.
876 const std::string lineSeparatorStr( &LINE_SEPARATOR_LF );
877 const Text lineSeparator( lineSeparatorStr );
879 const TextStyle defaultStyle;
880 for( StyledTextArray::const_iterator it = compressedStyledTextArray.begin(), endIt = compressedStyledTextArray.end(); it != endIt; ++it )
882 const StyledText& styledText( *it );
884 bool isItalics = styledText.mStyle.GetItalics();
885 bool isBold = defaultStyle.GetWeight() != styledText.mStyle.GetWeight();
886 bool isUnderline = styledText.mStyle.GetUnderline();
887 bool hasFontFace = defaultStyle.GetFontName() != styledText.mStyle.GetFontName();
888 bool hasFontStyle = defaultStyle.GetFontStyle() != styledText.mStyle.GetFontStyle();
889 bool hasFontSize = fabsf( defaultStyle.GetFontPointSize() - styledText.mStyle.GetFontPointSize() ) > GetRangedEpsilon( defaultStyle.GetFontPointSize(), styledText.mStyle.GetFontPointSize() );
890 bool hasFontColor = defaultStyle.GetTextColor() != styledText.mStyle.GetTextColor();
892 bool hasSmooth = fabsf( defaultStyle.GetSmoothEdge() - styledText.mStyle.GetSmoothEdge() ) > GetRangedEpsilon( defaultStyle.GetSmoothEdge(), styledText.mStyle.GetSmoothEdge() );
893 bool hasShadowColor = defaultStyle.GetShadowColor() != styledText.mStyle.GetShadowColor();
894 bool hasShadowParams = defaultStyle.GetShadowOffset() != styledText.mStyle.GetShadowOffset();
895 bool hasGlowColor = defaultStyle.GetGlowColor() != styledText.mStyle.GetGlowColor();
896 bool hasGlowParams = fabsf( defaultStyle.GetGlowIntensity() - styledText.mStyle.GetGlowIntensity() ) > GetRangedEpsilon( defaultStyle.GetGlowIntensity(), styledText.mStyle.GetGlowIntensity() );
897 bool hasOutlineColor = defaultStyle.GetOutlineColor() != styledText.mStyle.GetOutlineColor();
898 bool hasOutlineParams = defaultStyle.GetOutlineThickness() != styledText.mStyle.GetOutlineThickness();
901 if( hasFontFace || hasFontStyle || hasFontSize || hasFontColor )
903 markupString += LESS_THAN + XHTML_FONT_TAG;
907 markupString += WHITE_SPACE + XHTML_FACE_PROPERTY + EQUAL + QUOTATION_MARK + styledText.mStyle.GetFontName() + QUOTATION_MARK; // face=''
912 markupString += WHITE_SPACE + XHTML_STYLE_PROPERTY + EQUAL + QUOTATION_MARK + styledText.mStyle.GetFontStyle() + QUOTATION_MARK; // style=''
917 markupString += WHITE_SPACE + XHTML_SIZE_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetFontPointSize() ) + QUOTATION_MARK; // size=''
922 markupString += WHITE_SPACE + XHTML_COLOR_PROPERTY + EQUAL + QUOTATION_MARK + Vector4ToColorString( styledText.mStyle.GetTextColor() ) + QUOTATION_MARK; // color=''
925 markupString += GREATER_THAN;
931 markupString += LESS_THAN + XHTML_I_TAG + GREATER_THAN;
937 markupString += LESS_THAN + XHTML_B_TAG + GREATER_THAN;
943 markupString += LESS_THAN + XHTML_U_TAG + GREATER_THAN;
949 markupString += LESS_THAN + XHTML_SMOOTH_EDGE_TAG + WHITE_SPACE + XHTML_PARAM_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetSmoothEdge() ) + QUOTATION_MARK + GREATER_THAN;
953 if( styledText.mStyle.GetShadow() )
955 markupString += LESS_THAN + XHTML_SHADOW_TAG;
959 markupString += WHITE_SPACE + XHTML_COLOR_PROPERTY + EQUAL + QUOTATION_MARK + Vector4ToColorString( styledText.mStyle.GetShadowColor() ) + QUOTATION_MARK;
962 if( hasShadowParams )
964 markupString += WHITE_SPACE + XHTML_PARAM_X_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetShadowOffset().x ) + QUOTATION_MARK;
965 markupString += WHITE_SPACE + XHTML_PARAM_Y_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetShadowOffset().y ) + QUOTATION_MARK;
968 markupString += GREATER_THAN;
972 if( styledText.mStyle.GetGlow() )
974 markupString += LESS_THAN + XHTML_GLOW_TAG;
978 markupString += WHITE_SPACE + XHTML_COLOR_PROPERTY + EQUAL + QUOTATION_MARK + Vector4ToColorString( styledText.mStyle.GetGlowColor() ) + QUOTATION_MARK; // color=''
983 markupString += WHITE_SPACE + XHTML_PARAM_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetGlowIntensity() ) + QUOTATION_MARK; // param=''
986 markupString += GREATER_THAN;
990 if( styledText.mStyle.GetOutline() )
992 markupString += LESS_THAN + XHTML_OUTLINE_TAG;
994 if( hasOutlineColor )
996 markupString += WHITE_SPACE + XHTML_COLOR_PROPERTY + EQUAL + QUOTATION_MARK + Vector4ToColorString( styledText.mStyle.GetOutlineColor() ) + QUOTATION_MARK; // color = ''
999 if( hasOutlineParams )
1001 markupString += WHITE_SPACE + XHTML_PARAM_X_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetOutlineThickness().x ) + QUOTATION_MARK; // paramx=''
1002 markupString += WHITE_SPACE + XHTML_PARAM_Y_PROPERTY + EQUAL + QUOTATION_MARK + FloatToString( styledText.mStyle.GetOutlineThickness().y ) + QUOTATION_MARK; // paramy=''
1005 markupString += GREATER_THAN;
1009 if( styledText.mText[0] == lineSeparator[0] )
1011 markupString += LESS_THAN + XHTML_BR_TAG + WHITE_SPACE + SLASH + GREATER_THAN; // <br />
1015 markupString += styledText.mText.GetText();
1018 // Write outline close tag.
1019 if( styledText.mStyle.GetOutline() )
1021 markupString += LESS_THAN + ( SLASH + XHTML_OUTLINE_TAG + GREATER_THAN ); // </outline>
1024 // Write glow close tag.
1025 if( styledText.mStyle.GetGlow() )
1027 markupString += LESS_THAN + ( SLASH + XHTML_GLOW_TAG + GREATER_THAN ); // </glow>
1030 // Write shadow close tag.
1031 if( styledText.mStyle.GetShadow() )
1033 markupString += LESS_THAN + ( SLASH + XHTML_SHADOW_TAG + GREATER_THAN ); // </shadow>
1036 // Write smooth close tag.
1039 markupString += LESS_THAN + ( SLASH + XHTML_SMOOTH_EDGE_TAG + GREATER_THAN ); // </smooth>
1042 // Write underline close tag.
1045 markupString += LESS_THAN + ( SLASH + XHTML_U_TAG + GREATER_THAN ); // </u>
1048 // Write bold close tag.
1051 markupString += LESS_THAN + ( SLASH + XHTML_B_TAG + GREATER_THAN ); // </b>
1054 // Write italics close tag.
1057 markupString += LESS_THAN + ( SLASH + XHTML_I_TAG + GREATER_THAN ); // </i>
1060 // Write font close tag.
1061 if( hasFontFace || hasFontStyle || hasFontSize || hasFontColor )
1063 markupString += LESS_THAN + ( SLASH + XHTML_FONT_TAG + GREATER_THAN ); // </font>
1068 void SetTextStyle( StyledTextArray& styledTextArray, const TextStyle& style, const TextStyle::Mask mask )
1070 if( !styledTextArray.empty() )
1072 const size_t size = styledTextArray.size() - 1;
1073 SetTextStyleToRange( styledTextArray, style, mask, 0, size );
1077 void SetTextStyle( const Text& text, StyledTextArray& styledTextArray, const TextStyle& style, const TextStyle::Mask mask )
1079 if( !text.IsEmpty() )
1081 const size_t size = text.GetLength();
1083 for( size_t i = 0; i < size; ++i )
1085 StyledText styledText;
1086 styledText.mText = Text( text[i] );
1087 styledText.mStyle = style;
1089 styledTextArray.push_back( styledText );
1092 SetTextStyleToRange( styledTextArray, style, mask, 0, size - 1 );
1096 void SetTextStyleToRange( StyledTextArray& styledTextArray, const TextStyle& style, const TextStyle::Mask mask, const std::size_t begin, const std::size_t end )
1098 const size_t size = styledTextArray.size();
1099 DALI_ASSERT_ALWAYS( begin < size );
1100 DALI_ASSERT_ALWAYS( end < size );
1102 for( StyledTextArray::iterator it = styledTextArray.begin() + std::min(begin, end), endIt = styledTextArray.begin() + std::max(begin, end) + 1; it != endIt; ++it )
1104 StyledText& styledText( *it );
1106 styledText.mStyle.Copy( style, mask );
1110 } // namespace MarkupProcessor
1112 } // namespace Toolkit