X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-effects-style.cpp;h=8d552d4b798644b99f844d6c8ac45124497e16ae;hp=e56eac30b85a8fc481c6c0a3072e946ce8acef3d;hb=3a6adcbec75784b051cb9ebaf204d72b553ea355;hpb=c09d7cc6fb3a76ae145ca9195e773d6174020088 diff --git a/dali-toolkit/internal/text/text-effects-style.cpp b/dali-toolkit/internal/text/text-effects-style.cpp old mode 100755 new mode 100644 index e56eac3..8d552d4 --- a/dali-toolkit/internal/text/text-effects-style.cpp +++ b/dali-toolkit/internal/text/text-effects-style.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,84 +19,87 @@ #include // INTERNAL INCLUDES +#include #include #include +#include +#include namespace Dali { - namespace Toolkit { - namespace Text { - namespace { -const std::string COLOR_KEY( "color" ); -const std::string OFFSET_KEY( "offset" ); -const std::string BLUR_RADIUS_KEY( "blurRadius" ); -const std::string WIDTH_KEY( "width" ); -const std::string HEIGHT_KEY( "height" ); -const std::string ENABLE_KEY( "enable" ); -const std::string TRUE_TOKEN( "true" ); -const std::string FALSE_TOKEN( "false" ); -} - -bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, - bool& colorDefined, - Vector4& color, - bool& offsetDefined, - Vector2& offset, - bool& blurRadiusDefined, - float& blurRadius ) +const std::string COLOR_KEY("color"); +const std::string OFFSET_KEY("offset"); +const std::string BLUR_RADIUS_KEY("blurRadius"); +const std::string WIDTH_KEY("width"); +const std::string HEIGHT_KEY("height"); +const std::string ENABLE_KEY("enable"); +const std::string TYPE_KEY("type"); +const std::string DASH_WIDTH_KEY("dashWidth"); +const std::string DASH_GAP_KEY("dashGap"); +const std::string TRUE_TOKEN("true"); +const std::string FALSE_TOKEN("false"); +} // namespace + +bool ParseShadowProperties(const Property::Map& shadowPropertiesMap, + bool& colorDefined, + Vector4& color, + bool& offsetDefined, + Vector2& offset, + bool& blurRadiusDefined, + float& blurRadius) { const unsigned int numberOfItems = shadowPropertiesMap.Count(); // Parses and applies the style. - for( unsigned int index = 0u; index < numberOfItems; ++index ) + for(unsigned int index = 0u; index < numberOfItems; ++index) { - const KeyValuePair& valueGet = shadowPropertiesMap.GetKeyValue( index ); + const KeyValuePair& valueGet = shadowPropertiesMap.GetKeyValue(index); - if( COLOR_KEY == valueGet.first.stringKey ) + if((DevelText::Shadow::Property::COLOR == valueGet.first.indexKey) || (COLOR_KEY == valueGet.first.stringKey)) { /// Color key. colorDefined = true; - if( valueGet.second.GetType() == Dali::Property::STRING ) + if(valueGet.second.GetType() == Dali::Property::STRING) { const std::string colorStr = valueGet.second.Get(); - Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + Text::ColorStringToVector4(colorStr.c_str(), colorStr.size(), color); } else { color = valueGet.second.Get(); } } - else if( OFFSET_KEY == valueGet.first.stringKey ) + else if((DevelText::Shadow::Property::OFFSET == valueGet.first.indexKey) || (OFFSET_KEY == valueGet.first.stringKey)) { /// Offset key. offsetDefined = true; - if( valueGet.second.GetType() == Dali::Property::STRING ) + if(valueGet.second.GetType() == Dali::Property::STRING) { const std::string offsetStr = valueGet.second.Get(); - StringToVector2( offsetStr.c_str(), offsetStr.size(), offset ); + StringToVector2(offsetStr.c_str(), offsetStr.size(), offset); } else { offset = valueGet.second.Get(); } } - else if( BLUR_RADIUS_KEY == valueGet.first.stringKey ) + else if((DevelText::Shadow::Property::BLUR_RADIUS == valueGet.first.indexKey) || (BLUR_RADIUS_KEY == valueGet.first.stringKey)) { /// Blur radius key. blurRadiusDefined = true; - if( valueGet.second.GetType() == Dali::Property::STRING ) + if(valueGet.second.GetType() == Dali::Property::STRING) { const std::string blurRadiusStr = valueGet.second.Get(); - blurRadius = StringToFloat( blurRadiusStr.c_str() ); + blurRadius = StringToFloat(blurRadiusStr.c_str()); } else { @@ -108,177 +111,353 @@ bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, return 0u == numberOfItems; } -bool ParseUnderlineProperties( const Property::Map& underlinePropertiesMap, - bool& enabled, - bool& colorDefined, - Vector4& color, - bool& heightDefined, - float& height ) +bool ParseUnderlineProperties(const Property::Map& underlinePropertiesMap, + bool& enabled, + bool& colorDefined, + Vector4& color, + bool& heightDefined, + float& height, + bool& typeDefined, + Text::Underline::Type& type, + bool& dashWidthDefined, + float& dashWidth, + bool& dashGapDefined, + float& dashGap) { const unsigned int numberOfItems = underlinePropertiesMap.Count(); // Parses and applies the style. - for( unsigned int index = 0u; index < numberOfItems; ++index ) + for(unsigned int index = 0u; index < numberOfItems; ++index) { - const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index ); + const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue(index); - if( ENABLE_KEY == valueGet.first.stringKey ) + if((DevelText::Underline::Property::ENABLE == valueGet.first.indexKey) || (ENABLE_KEY == valueGet.first.stringKey)) { /// Enable key. - if( valueGet.second.GetType() == Dali::Property::STRING ) + if(valueGet.second.GetType() == Dali::Property::STRING) { const std::string enableStr = valueGet.second.Get(); - enabled = Text::TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() ); + enabled = Text::TokenComparison(TRUE_TOKEN, enableStr.c_str(), enableStr.size()); } else { enabled = valueGet.second.Get(); } } - else if( COLOR_KEY == valueGet.first.stringKey ) + else if((DevelText::Underline::Property::COLOR == valueGet.first.indexKey) || (COLOR_KEY == valueGet.first.stringKey)) { /// Color key. colorDefined = true; - if( valueGet.second.GetType() == Dali::Property::STRING ) + if(valueGet.second.GetType() == Dali::Property::STRING) { const std::string colorStr = valueGet.second.Get(); - Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + Text::ColorStringToVector4(colorStr.c_str(), colorStr.size(), color); } else { color = valueGet.second.Get(); } } - else if( HEIGHT_KEY == valueGet.first.stringKey ) + else if((DevelText::Underline::Property::HEIGHT == valueGet.first.indexKey) || (HEIGHT_KEY == valueGet.first.stringKey)) { /// Height key. heightDefined = true; - if( valueGet.second.GetType() == Dali::Property::STRING ) + if(valueGet.second.GetType() == Dali::Property::STRING) { const std::string heightStr = valueGet.second.Get(); - height = StringToFloat( heightStr.c_str() ); + height = StringToFloat(heightStr.c_str()); } else { height = valueGet.second.Get(); } } + else if((DevelText::Underline::Property::TYPE == valueGet.first.indexKey) || (TYPE_KEY == valueGet.first.stringKey)) + { + /// Underline Type key. + typeDefined = true; + + if(valueGet.second.GetType() == Dali::Property::STRING) + { + const std::string typeStr = valueGet.second.Get(); + Text::UnderlineTypeStringToTypeValue(typeStr.c_str(), typeStr.size(), type); + } + else + { + type = valueGet.second.Get(); + } + } + else if((DevelText::Underline::Property::DASH_WIDTH == valueGet.first.indexKey) || (DASH_WIDTH_KEY == valueGet.first.stringKey)) + { + /// Dashed Underline Width key. + dashWidthDefined = true; + + if(valueGet.second.GetType() == Dali::Property::STRING) + { + const std::string dashWidthStr = valueGet.second.Get(); + dashWidth = StringToFloat(dashWidthStr.c_str()); + } + else + { + dashWidth = valueGet.second.Get(); + } + } + else if((DevelText::Underline::Property::DASH_GAP == valueGet.first.indexKey) || (DASH_GAP_KEY == valueGet.first.stringKey)) + { + /// Dashed Underline Gap key. + dashGapDefined = true; + + if(valueGet.second.GetType() == Dali::Property::STRING) + { + const std::string dashGapStr = valueGet.second.Get(); + dashGap = StringToFloat(dashGapStr.c_str()); + } + else + { + dashGap = valueGet.second.Get(); + } + } } return 0u == numberOfItems; } -bool ParseOutlineProperties( const Property::Map& underlinePropertiesMap, - bool& colorDefined, - Vector4& color, - bool& widthDefined, - unsigned int& width ) +bool ParseOutlineProperties(const Property::Map& underlinePropertiesMap, + bool& colorDefined, + Vector4& color, + bool& widthDefined, + uint16_t& width) { const unsigned int numberOfItems = underlinePropertiesMap.Count(); // Parses and applies the style. - for( unsigned int index = 0u; index < numberOfItems; ++index ) + for(unsigned int index = 0u; index < numberOfItems; ++index) { - const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index ); + const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue(index); - if( COLOR_KEY == valueGet.first.stringKey ) + if((DevelText::Outline::Property::COLOR == valueGet.first.indexKey) || (COLOR_KEY == valueGet.first.stringKey)) { /// Color key. colorDefined = true; - color = valueGet.second.Get(); + color = valueGet.second.Get(); } - else if( WIDTH_KEY == valueGet.first.stringKey ) + else if((DevelText::Outline::Property::WIDTH == valueGet.first.indexKey) || (WIDTH_KEY == valueGet.first.stringKey)) { /// Width key. widthDefined = true; - width = static_cast( valueGet.second.Get() ); + width = static_cast(valueGet.second.Get()); } } return 0u == numberOfItems; } -bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +bool ParseBackgroundProperties(const Property::Map& backgroundProperties, + bool& enabled, + bool& colorDefined, + Vector4& color) +{ + const unsigned int numberOfItems = backgroundProperties.Count(); + + // Parses and applies the style. + for(unsigned int index = 0u; index < numberOfItems; ++index) + { + const KeyValuePair& valueGet = backgroundProperties.GetKeyValue(index); + + if((DevelText::Background::Property::ENABLE == valueGet.first.indexKey) || (ENABLE_KEY == valueGet.first.stringKey)) + { + /// Enable key. + enabled = valueGet.second.Get(); + } + else if((DevelText::Background::Property::COLOR == valueGet.first.indexKey) || (COLOR_KEY == valueGet.first.stringKey)) + { + /// Color key. + colorDefined = true; + color = valueGet.second.Get(); + } + } + + return 0u == numberOfItems; +} + +bool ParseStrikethroughProperties(const Property::Map& strikethroughPropertiesMap, + bool& enabled, + bool& colorDefined, + Vector4& color, + bool& heightDefined, + float& height) +{ + const unsigned int numberOfItems = strikethroughPropertiesMap.Count(); + + // Parses and applies the style. + for(unsigned int index = 0u; index < numberOfItems; ++index) + { + const KeyValuePair& valueGet = strikethroughPropertiesMap.GetKeyValue(index); + + if((DevelText::Strikethrough::Property::ENABLE == valueGet.first.indexKey) || (ENABLE_KEY == valueGet.first.stringKey)) + { + /// Enable key. + if(valueGet.second.GetType() == Dali::Property::STRING) + { + const std::string enableStr = valueGet.second.Get(); + enabled = Text::TokenComparison(TRUE_TOKEN, enableStr.c_str(), enableStr.size()); + } + else + { + enabled = valueGet.second.Get(); + } + } + else if((DevelText::Strikethrough::Property::COLOR == valueGet.first.indexKey) || (COLOR_KEY == valueGet.first.stringKey)) + { + /// Color key. + colorDefined = true; + + if(valueGet.second.GetType() == Dali::Property::STRING) + { + const std::string colorStr = valueGet.second.Get(); + Text::ColorStringToVector4(colorStr.c_str(), colorStr.size(), color); + } + else + { + color = valueGet.second.Get(); + } + } + else if((DevelText::Strikethrough::Property::HEIGHT == valueGet.first.indexKey) || (HEIGHT_KEY == valueGet.first.stringKey)) + { + /// Height key. + heightDefined = true; + + if(valueGet.second.GetType() == Dali::Property::STRING) + { + const std::string heightStr = valueGet.second.Get(); + height = StringToFloat(heightStr.c_str()); + } + else + { + height = valueGet.second.Get(); + } + } + } + return 0u == numberOfItems; +} + +bool SetUnderlineProperties(ControllerPtr controller, const Property::Value& value, EffectStyle::Type type) { bool update = false; - if( controller ) + if(controller) { - switch( type ) + switch(type) { case EffectStyle::DEFAULT: { const Property::Map& propertiesMap = value.Get(); - bool enabled = false; - bool colorDefined = false; - Vector4 color; - bool heightDefined = false; - float height = 0.f; + bool enabled = false; + bool colorDefined = false; + Vector4 color; + bool heightDefined = false; + float height = 0.f; + bool typeDefined = false; + Text::Underline::Type type; + bool dashWidthDefined = false; + float dashWidth = 2.0f; + bool dashGapDefined = false; + float dashGap = 1.0f; bool empty = true; - if ( propertiesMap.Empty() ) + if(propertiesMap.Empty()) { // Map empty so check if a string provided const std::string propertyString = value.Get(); - if ( !propertyString.empty() ) + if(!propertyString.empty()) { Property::Map parsedStringMap; - Text::ParsePropertyString( propertyString, parsedStringMap ); - - empty = ParseUnderlineProperties( parsedStringMap, - enabled, - colorDefined, - color, - heightDefined, - height ); + Text::ParsePropertyString(propertyString, parsedStringMap); - controller->UnderlineSetByString( !empty ); - } - } - else - { - empty = ParseUnderlineProperties( propertiesMap, + empty = ParseUnderlineProperties(parsedStringMap, enabled, colorDefined, color, heightDefined, - height ); - - controller->UnderlineSetByString( false ); + height, + typeDefined, + type, + dashWidthDefined, + dashWidth, + dashGapDefined, + dashGap); + + controller->UnderlineSetByString(!empty); + } + } + else + { + empty = ParseUnderlineProperties(propertiesMap, + enabled, + colorDefined, + color, + heightDefined, + height, + typeDefined, + type, + dashWidthDefined, + dashWidth, + dashGapDefined, + dashGap); + + controller->UnderlineSetByString(false); } - if( !empty ) + if(!empty) { - if( enabled != controller->IsUnderlineEnabled() ) + if(enabled != controller->IsUnderlineEnabled()) { - controller->SetUnderlineEnabled( enabled ); + controller->SetUnderlineEnabled(enabled); update = true; } // Sets the default underline values. - if( colorDefined && ( controller->GetUnderlineColor() != color ) ) + if(colorDefined && (controller->GetUnderlineColor() != color)) + { + controller->SetUnderlineColor(color); + update = true; + } + + if(heightDefined && (fabsf(controller->GetUnderlineHeight() - height) > Math::MACHINE_EPSILON_1000)) + { + controller->SetUnderlineHeight(height); + update = true; + } + + if(typeDefined && (controller->GetUnderlineType() != type)) + { + controller->SetUnderlineType(type); + update = true; + } + + if(dashWidthDefined && (fabsf(controller->GetDashedUnderlineWidth() - dashWidth) > Math::MACHINE_EPSILON_1000)) { - controller->SetUnderlineColor( color ); + controller->SetDashedUnderlineWidth(dashWidth); update = true; } - if( heightDefined && ( fabsf( controller->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 ) ) + if(dashGapDefined && (fabsf(controller->GetDashedUnderlineGap() - dashGap) > Math::MACHINE_EPSILON_1000)) { - controller->SetUnderlineHeight( height ); + controller->SetDashedUnderlineGap(dashGap); update = true; } } else { // Disable underline. - if( controller->IsUnderlineEnabled() ) + if(controller->IsUnderlineEnabled()) { - controller->SetUnderlineEnabled( false ); + controller->SetUnderlineEnabled(false); update = true; } } @@ -288,40 +467,55 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va { const std::string& underlineProperties = value.Get(); - controller->SetInputUnderlineProperties( underlineProperties ); + controller->SetInputUnderlineProperties(underlineProperties); break; } } // switch - } // if( controller ) + } // if( controller ) return update; } -void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type ) +void GetUnderlineProperties(ControllerPtr controller, Property::Value& value, EffectStyle::Type type) { - if( controller ) + if(controller) { - switch( type ) + switch(type) { case EffectStyle::DEFAULT: { - const bool enabled = controller->IsUnderlineEnabled(); - const Vector4& color = controller->GetUnderlineColor(); - const float height = controller->GetUnderlineHeight(); - - if ( controller->IsUnderlineSetByString() ) + const bool enabled = controller->IsUnderlineEnabled(); + const Vector4& color = controller->GetUnderlineColor(); + const float height = controller->GetUnderlineHeight(); + const Text::Underline::Type type = controller->GetUnderlineType(); + const float dashWidth = controller->GetDashedUnderlineWidth(); + const float dashGap = controller->GetDashedUnderlineGap(); + + if(controller->IsUnderlineSetByString()) { - std::string underlineProperties = "{\"enable\":"; - const std::string enabledStr = enabled ? "true" : "false"; + std::string underlineProperties = "{\"enable\":"; + const std::string enabledStr = enabled ? "true" : "false"; underlineProperties += "\"" + enabledStr + "\","; std::string colorStr; - Vector4ToColorString( color, colorStr ); + Vector4ToColorString(color, colorStr); underlineProperties += "\"color\":\"" + colorStr + "\","; std::string heightStr; - FloatToString( height, heightStr ); - underlineProperties += "\"height\":\"" + heightStr + "\"}"; + FloatToString(height, heightStr); + underlineProperties += "\"height\":\"" + heightStr + "\","; + + std::string typeStr; + typeStr = GetUnderlineTypeToString(type); + underlineProperties += "\"type\":\"" + typeStr + "\","; + + std::string dashWidthStr; + FloatToString(dashWidth, dashWidthStr); + underlineProperties += "\"dashWidth\":\"" + dashWidthStr + "\","; + + std::string dashGapStr; + FloatToString(dashGap, dashGapStr); + underlineProperties += "\"dashGap\":\"" + dashGapStr + "\"}"; value = underlineProperties; } @@ -329,16 +523,12 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E { Property::Map map; - const std::string enabledStr = enabled ? TRUE_TOKEN : FALSE_TOKEN; - map.Insert( ENABLE_KEY, enabledStr ); - - std::string colorStr; - Vector4ToColorString( color, colorStr ); - map.Insert( COLOR_KEY, colorStr ); - - std::string heightStr; - FloatToString( height, heightStr ); - map.Insert( HEIGHT_KEY, heightStr ); + map.Insert(ENABLE_KEY, enabled); + map.Insert(COLOR_KEY, color); + map.Insert(HEIGHT_KEY, height); + map.Insert(TYPE_KEY, type); + map.Insert(DASH_WIDTH_KEY, dashWidth); + map.Insert(DASH_GAP_KEY, dashGap); value = map; } @@ -354,86 +544,85 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E } } -bool SetShadowProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +bool SetShadowProperties(ControllerPtr controller, const Property::Value& value, EffectStyle::Type type) { bool update = false; - if( controller ) + if(controller) { - switch( type ) + switch(type) { case EffectStyle::DEFAULT: { const Property::Map& propertiesMap = value.Get(); - bool colorDefined = false; + bool colorDefined = false; Vector4 color; - bool offsetDefined = false; + bool offsetDefined = false; Vector2 offset; - bool blurRadiusDefined = false; - float blurRadius; + bool blurRadiusDefined = false; + float blurRadius; bool empty = true; - if ( propertiesMap.Empty() ) + if(propertiesMap.Empty()) { - // Map empty so check if a string provided - const std::string propertyString = value.Get(); - - Property::Map parsedStringMap; - Text::ParsePropertyString( propertyString, parsedStringMap ); + // Map empty so check if a string provided + const std::string propertyString = value.Get(); - empty = ParseShadowProperties( parsedStringMap, - colorDefined, - color, - offsetDefined, - offset, - blurRadiusDefined, - blurRadius ); + Property::Map parsedStringMap; + Text::ParsePropertyString(propertyString, parsedStringMap); - controller->ShadowSetByString( !empty ); + empty = ParseShadowProperties(parsedStringMap, + colorDefined, + color, + offsetDefined, + offset, + blurRadiusDefined, + blurRadius); + controller->ShadowSetByString(!empty); } else { - empty = ParseShadowProperties( propertiesMap, - colorDefined, - color, - offsetDefined, - offset, - blurRadiusDefined, - blurRadius ); - - controller->ShadowSetByString( false ); + empty = ParseShadowProperties(propertiesMap, + colorDefined, + color, + offsetDefined, + offset, + blurRadiusDefined, + blurRadius); + + controller->ShadowSetByString(false); } - if( !empty ) + if(!empty) { // Sets the default shadow values. - if( colorDefined && ( controller->GetShadowColor() != color ) ) + if(colorDefined && (controller->GetShadowColor() != color)) { - controller->SetShadowColor( color ); + controller->SetShadowColor(color); update = true; } - if( offsetDefined && ( controller->GetShadowOffset() != offset ) ) + if(offsetDefined && (controller->GetShadowOffset() != offset)) { - controller->SetShadowOffset( offset ); + controller->SetShadowOffset(offset); update = true; } - if( blurRadiusDefined && ( controller->GetShadowBlurRadius() != blurRadius ) ) + if(blurRadiusDefined && (controller->GetShadowBlurRadius() != blurRadius)) { - controller->SetShadowBlurRadius( blurRadius ); + controller->SetShadowBlurRadius(blurRadius); update = true; } } else { // Disable shadow. - if( Vector2::ZERO != controller->GetShadowOffset() ) + if(Vector2::ZERO != controller->GetShadowOffset()) { - controller->SetShadowOffset( Vector2::ZERO ); + controller->SetShadowOffset(Vector2::ZERO); } } break; @@ -442,41 +631,41 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value { const std::string& shadowString = value.Get(); - controller->SetInputShadowProperties( shadowString ); + controller->SetInputShadowProperties(shadowString); break; } } // switch - } // if( controller ) + } // if( controller ) return update; } -void GetShadowProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type ) +void GetShadowProperties(ControllerPtr controller, Property::Value& value, EffectStyle::Type type) { - if( controller ) + if(controller) { - switch( type ) + switch(type) { case EffectStyle::DEFAULT: { - const Vector4& color = controller->GetShadowColor(); - const Vector2& offset = controller->GetShadowOffset(); - const float& blurRadius = controller->GetShadowBlurRadius(); + const Vector4& color = controller->GetShadowColor(); + const Vector2& offset = controller->GetShadowOffset(); + const float& blurRadius = controller->GetShadowBlurRadius(); - if ( controller->IsShadowSetByString() ) + if(controller->IsShadowSetByString()) { std::string shadowProperties = "{"; std::string colorStr; - Vector4ToColorString( color, colorStr ); + Vector4ToColorString(color, colorStr); shadowProperties += "\"color\":\"" + colorStr + "\","; std::string offsetStr; - Vector2ToString( offset, offsetStr ); + Vector2ToString(offset, offsetStr); shadowProperties += "\"offset\":\"" + offsetStr + "\","; std::string blurRadiusStr; - FloatToString( blurRadius, blurRadiusStr ); + FloatToString(blurRadius, blurRadiusStr); shadowProperties += "\"blurRadius\":\"" + blurRadiusStr + "\"}"; value = shadowProperties; @@ -485,9 +674,9 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe { Property::Map map; - map.Insert( COLOR_KEY, color ); - map.Insert( OFFSET_KEY, offset ); - map.Insert( BLUR_RADIUS_KEY, blurRadius ); + map.Insert(COLOR_KEY, color); + map.Insert(OFFSET_KEY, offset); + map.Insert(BLUR_RADIUS_KEY, blurRadius); value = map; } @@ -502,26 +691,26 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe } } -bool SetEmbossProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +bool SetEmbossProperties(ControllerPtr controller, const Property::Value& value, EffectStyle::Type type) { bool update = false; - if( controller ) + if(controller) { - const std::string properties = value.Get< std::string >(); + const std::string properties = value.Get(); - switch( type ) + switch(type) { case EffectStyle::DEFAULT: { // Stores the default emboss's properties string to be recovered by the GetEmbossProperties() function. - controller->SetDefaultEmbossProperties( properties ); + controller->SetDefaultEmbossProperties(properties); break; } case EffectStyle::INPUT: { // Stores the input emboss's properties string to be recovered by the GetEmbossProperties() function. - controller->SetInputEmbossProperties( properties ); + controller->SetInputEmbossProperties(properties); break; } } @@ -530,11 +719,11 @@ bool SetEmbossProperties( ControllerPtr controller, const Property::Value& value return update; } -void GetEmbossProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type ) +void GetEmbossProperties(ControllerPtr controller, Property::Value& value, EffectStyle::Type type) { - if( controller ) + if(controller) { - switch( type ) + switch(type) { case EffectStyle::DEFAULT: { @@ -550,68 +739,68 @@ void GetEmbossProperties( ControllerPtr controller, Property::Value& value, Effe } } -bool SetOutlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +bool SetOutlineProperties(ControllerPtr controller, const Property::Value& value, EffectStyle::Type type) { bool update = false; - if( controller ) + if(controller) { - switch( type ) + switch(type) { case EffectStyle::DEFAULT: { const Property::Map& propertiesMap = value.Get(); - bool colorDefined = false; - Vector4 color; - bool widthDefined = false; - unsigned int width = 0u; + bool colorDefined = false; + Vector4 color; + bool widthDefined = false; + uint16_t width = 0u; bool empty = true; - if ( propertiesMap.Empty() ) + if(propertiesMap.Empty()) { - // Map empty so check if a string provided - // This is purely to maintain backward compatibility, but we don't parse the string to be a property map. - const std::string propertyString = value.Get(); + // Map empty so check if a string provided + // This is purely to maintain backward compatibility, but we don't parse the string to be a property map. + const std::string propertyString = value.Get(); - // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function. - controller->SetDefaultOutlineProperties( propertyString ); + // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function. + controller->SetDefaultOutlineProperties(propertyString); - controller->OutlineSetByString( true ); + controller->OutlineSetByString(true); } else { - empty = ParseOutlineProperties( propertiesMap, - colorDefined, - color, - widthDefined, - width ); + empty = ParseOutlineProperties(propertiesMap, + colorDefined, + color, + widthDefined, + width); - controller->OutlineSetByString( false ); + controller->OutlineSetByString(false); } - if( !empty ) + if(!empty) { // Sets the default outline values. - if( colorDefined && ( controller->GetOutlineColor() != color ) ) + if(colorDefined && (controller->GetOutlineColor() != color)) { - controller->SetOutlineColor( color ); + controller->SetOutlineColor(color); update = true; } - if( widthDefined && ( controller->GetOutlineWidth() != width ) ) + if(widthDefined && (controller->GetOutlineWidth() != width)) { - controller->SetOutlineWidth( width ); + controller->SetOutlineWidth(width); update = true; } } else { // Disable outline - if( 0u != controller->GetOutlineWidth() ) + if(0u != controller->GetOutlineWidth()) { - controller->SetOutlineWidth( 0u ); + controller->SetOutlineWidth(0u); update = true; } } @@ -621,24 +810,24 @@ bool SetOutlineProperties( ControllerPtr controller, const Property::Value& valu { const std::string& outlineProperties = value.Get(); - controller->SetInputOutlineProperties( outlineProperties ); + controller->SetInputOutlineProperties(outlineProperties); break; } } // switch - } // if( controller ) + } // if( controller ) return update; } -void GetOutlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type ) +void GetOutlineProperties(ControllerPtr controller, Property::Value& value, EffectStyle::Type type) { - if( controller ) + if(controller) { - switch( type ) + switch(type) { case EffectStyle::DEFAULT: { - if ( controller->IsOutlineSetByString() ) + if(controller->IsOutlineSetByString()) { value = controller->GetDefaultOutlineProperties(); break; @@ -646,17 +835,11 @@ void GetOutlineProperties( ControllerPtr controller, Property::Value& value, Eff else { const Vector4& color = controller->GetOutlineColor(); - const unsigned int width = controller->GetOutlineWidth(); + const uint16_t width = controller->GetOutlineWidth(); Property::Map map; - - std::string colorStr; - Vector4ToColorString( color, colorStr ); - map.Insert( COLOR_KEY, colorStr ); - - std::string widthStr; - UintToString( width, widthStr ); - map.Insert( WIDTH_KEY, widthStr ); + map.Insert(COLOR_KEY, color); + map.Insert(WIDTH_KEY, static_cast(width)); value = map; @@ -672,6 +855,243 @@ void GetOutlineProperties( ControllerPtr controller, Property::Value& value, Eff } } +bool SetBackgroundProperties(ControllerPtr controller, const Property::Value& value, EffectStyle::Type type) +{ + bool update = false; + + if(controller) + { + switch(type) + { + case EffectStyle::DEFAULT: + { + const Property::Map& propertiesMap = value.Get(); + + bool enabled = false; + bool colorDefined = false; + Vector4 color; + + bool empty = true; + + if(!propertiesMap.Empty()) + { + empty = ParseBackgroundProperties(propertiesMap, + enabled, + colorDefined, + color); + } + + if(!empty) + { + if(enabled != controller->IsBackgroundEnabled()) + { + controller->SetBackgroundEnabled(enabled); + update = true; + } + + if(colorDefined && (controller->GetBackgroundColor() != color)) + { + controller->SetBackgroundColor(color); + update = true; + } + } + else + { + // Disable background. + if(controller->IsBackgroundEnabled()) + { + controller->SetBackgroundEnabled(false); + update = true; + } + } + break; + } + case EffectStyle::INPUT: + { + // Text background is not supported while inputting yet + break; + } + } // switch + } // if( controller ) + + return update; +} + +void GetBackgroundProperties(ControllerPtr controller, Property::Value& value, EffectStyle::Type type) +{ + if(controller) + { + switch(type) + { + case EffectStyle::DEFAULT: + { + const bool enabled = controller->IsBackgroundEnabled(); + const Vector4& color = controller->GetBackgroundColor(); + + Property::Map map; + map.Insert(ENABLE_KEY, enabled); + map.Insert(COLOR_KEY, color); + + value = map; + + break; + } + case EffectStyle::INPUT: + { + // Text background is not supported while inputting yet + break; + } + } + } +} + +bool SetStrikethroughProperties(ControllerPtr controller, const Property::Value& value, EffectStyle::Type type) +{ + bool update = false; + + if(controller) + { + switch(type) + { + case EffectStyle::DEFAULT: + { + const Property::Map& propertiesMap = value.Get(); + + bool enabled = false; + bool colorDefined = false; + Vector4 color; + bool heightDefined = false; + float height = 0.f; + + bool empty = true; + + if(propertiesMap.Empty()) + { + // Map empty so check if a string provided + const std::string propertyString = value.Get(); + + if(!propertyString.empty()) + { + Property::Map parsedStringMap; + Text::ParsePropertyString(propertyString, parsedStringMap); + + empty = ParseStrikethroughProperties(parsedStringMap, + enabled, + colorDefined, + color, + heightDefined, + height); + + controller->StrikethroughSetByString(!empty); + } + } + else + { + empty = ParseStrikethroughProperties(propertiesMap, + enabled, + colorDefined, + color, + heightDefined, + height); + + controller->StrikethroughSetByString(false); + } + + if(!empty) + { + if(enabled != controller->IsStrikethroughEnabled()) + { + controller->SetStrikethroughEnabled(enabled); + update = true; + } + + // Sets the default strikethrough values. + if(colorDefined && (controller->GetStrikethroughColor() != color)) + { + controller->SetStrikethroughColor(color); + update = true; + } + if(heightDefined && (fabsf(controller->GetStrikethroughHeight() - height) > Math::MACHINE_EPSILON_1000)) + { + controller->SetStrikethroughHeight(height); + update = true; + } + } + else + { + // Disable strikethrough. + if(controller->IsStrikethroughEnabled()) + { + controller->SetStrikethroughEnabled(false); + update = true; + } + } + break; + } + case EffectStyle::INPUT: + { + const std::string& strikethroughProperties = value.Get(); + + controller->SetInputStrikethroughProperties(strikethroughProperties); + update = true; + break; + } + } // switch + } // if( controller ) + + return update; +} + +void GetStrikethroughProperties(ControllerPtr controller, Property::Value& value, EffectStyle::Type type) +{ + if(controller) + { + switch(type) + { + case EffectStyle::DEFAULT: + { + const bool enabled = controller->IsStrikethroughEnabled(); + const Vector4& color = controller->GetStrikethroughColor(); + const float height = controller->GetStrikethroughHeight(); + + if(controller->IsStrikethroughSetByString()) + { + std::string strikethroughProperties = "{\"enable\":"; + const std::string enabledStr = enabled ? "true" : "false"; + strikethroughProperties += "\"" + enabledStr + "\","; + + std::string colorStr; + Vector4ToColorString(color, colorStr); + strikethroughProperties += "\"color\":\"" + colorStr + "\","; + + std::string heightStr; + FloatToString(height, heightStr); + strikethroughProperties += "\"height\":\"" + heightStr + "\"}"; + + value = strikethroughProperties; + } + else + { + Property::Map map; + + map.Insert(ENABLE_KEY, enabled); + map.Insert(COLOR_KEY, color); + map.Insert(HEIGHT_KEY, height); + + value = map; + } + + break; + } + case EffectStyle::INPUT: + { + value = controller->GetInputStrikethroughProperties(); + break; + } + } + } +} + } // namespace Text } // namespace Toolkit