From 565f93cb19bc3e1058fc057bea74c973489deab3 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Wed, 10 May 2017 18:45:25 +0100 Subject: [PATCH] Text style to return properties as string API previously broken when Map used Change-Id: I439a995cb1177c5b7ea6c81e45eba81d61759d68 --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 66 ++++++++++ dali-toolkit/internal/text/text-controller-impl.h | 6 +- dali-toolkit/internal/text/text-controller.cpp | 20 +++ dali-toolkit/internal/text/text-controller.h | 24 ++++ dali-toolkit/internal/text/text-effects-style.cpp | 146 +++++++++++++++++---- 5 files changed, 232 insertions(+), 30 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 6455402..ff32ccf 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -1847,3 +1847,69 @@ int utcDaliTextEditorHandles(void) END_TEST; } + +int utcDaliTextEditorUnderPropertyStringP(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorUnderPropertyStringP"); + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + std::string underlineSettings1( "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" ); + + Stage::GetCurrent().Add( editor ); + + editor.SetProperty( TextEditor::Property::UNDERLINE, underlineSettings1 ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::UNDERLINE ), underlineSettings1, TEST_LOCATION ); + + tet_infoline("Set underline settings with a map"); + // Check the input underline property + Property::Map underlineMapSet; + Property::Map underlineMapGet; + underlineMapSet.Insert( "enable", "true" ); + underlineMapSet.Insert( "color", "blue" ); + underlineMapSet.Insert( "height", "2" ); + + editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet ); + underlineMapGet = editor.GetProperty( TextEditor::Property::UNDERLINE ); + DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapSet, underlineMapGet ), true, TEST_LOCATION ); + + tet_infoline("Set underline settings with a string"); + editor.SetProperty( TextEditor::Property::UNDERLINE, underlineSettings1 ); + Property::Value value = editor.GetProperty( TextEditor::Property::UNDERLINE ); + std::string result; + value.Get(result); + DALI_TEST_EQUALS( result , underlineSettings1, TEST_LOCATION ); + + tet_infoline("Trying to set invalid underline settings, should not update and stay at previous settings"); + std::string underlineSettingsVoid( "{\"enable\":\"true\",\"coooolor\":\"blue\",\"heeeight\":\"4\"}" ); + editor.SetProperty( TextEditor::Property::UNDERLINE, underlineSettingsVoid ); + value = editor.GetProperty( TextEditor::Property::UNDERLINE ); + value.Get(result); + DALI_TEST_EQUALS( result , underlineSettings1, TEST_LOCATION ); + + END_TEST; +} + +int utcDaliTextEditorShadowPropertyStringP(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorUnderPropertyStringP Setting Shadow propeties by string"); + + TextEditor editor = TextEditor::New(); + + std::string shadowSettings( "{\"color\":\"green\",\"offset\":\"2 2\"}" ); + + Stage::GetCurrent().Add( editor ); + + editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" ); + + Property::Value value = editor.GetProperty( TextEditor::Property::SHADOW ); + std::string result; + value.Get(result); + + DALI_TEST_EQUALS( result, shadowSettings, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index f317fb3..43a7cf3 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -314,7 +314,9 @@ struct Controller::Impl mMarkupProcessorEnabled( false ), mClipboardHideEnabled( true ), mIsAutoScrollEnabled( false ), - mAutoScrollDirectionRTL( false ) + mAutoScrollDirectionRTL( false ), + mUnderlineSetByString( false ), + mShadowSetByString( false ) { mModel = Model::New(); @@ -721,6 +723,8 @@ public: bool mIsAutoScrollEnabled:1; ///< Whether auto text scrolling is enabled. CharacterDirection mAutoScrollDirectionRTL:1; ///< Direction of auto scrolling, true if rtl + bool mUnderlineSetByString:1; ///< Set when underline is set by string (legacy) instead of map + bool mShadowSetByString:1; ///< Set when shadow is set by string (legacy) instead of map }; } // namespace Text diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 2811804..7545481 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1418,6 +1418,26 @@ Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const return action; } +bool Controller::IsUnderlineSetByString() +{ + return mImpl->mUnderlineSetByString; +} + +void Controller::UnderlineSetByString( bool setByString ) +{ + mImpl->mUnderlineSetByString = setByString; +} + +bool Controller::IsShadowSetByString() +{ + return mImpl->mShadowSetByString; +} + +void Controller::ShadowSetByString( bool setByString ) +{ + mImpl->mShadowSetByString = setByString; +} + // public : Queries & retrieves. Layout::Engine& Controller::GetLayoutEngine() diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 7301e70..b9cbb2c 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -398,6 +398,30 @@ public: // Configure the text controller. */ NoTextTap::Action GetNoTextLongPressAction() const; + /** + * @brief Query if Underline settings were provided by string or map + * @return bool true if set by string + */ + bool IsUnderlineSetByString(); + + /** + * Set method underline setting were set by + * @param[in] bool, true if set by string + */ + void UnderlineSetByString( bool setByString ); + + /** + * @brief Query if shadow settings were provided by string or map + * @return bool true if set by string + */ + bool IsShadowSetByString(); + + /** + * Set method shadow setting were set by + * @param[in] bool, true if set by string + */ + void ShadowSetByString( bool setByString ); + public: // Update. /** diff --git a/dali-toolkit/internal/text/text-effects-style.cpp b/dali-toolkit/internal/text/text-effects-style.cpp index 44302d7..75fabd7 100644 --- a/dali-toolkit/internal/text/text-effects-style.cpp +++ b/dali-toolkit/internal/text/text-effects-style.cpp @@ -138,12 +138,39 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va bool heightDefined = false; float height = 0.f; - const bool empty = ParseUnderlineProperties( propertiesMap, - enabled, - colorDefined, - color, - heightDefined, - height ); + 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 = ParseUnderlineProperties( parsedStringMap, + enabled, + colorDefined, + color, + heightDefined, + height ); + + controller->UnderlineSetByString( !empty); + } + } + else + { + empty = ParseUnderlineProperties( propertiesMap, + enabled, + colorDefined, + color, + heightDefined, + height ); + + controller->UnderlineSetByString( false ); + } if( !empty ) { @@ -202,20 +229,40 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E const Vector4& color = controller->GetUnderlineColor(); const float height = controller->GetUnderlineHeight(); - Property::Map map; + if ( controller->IsUnderlineSetByString() ) + { + std::string underlineProperties = "{\"enable\":"; + const std::string enabledStr = enabled ? "true" : "false"; + underlineProperties += "\"" + enabledStr + "\","; + + std::string colorStr; + Vector4ToColorString( color, colorStr ); + underlineProperties += "\"color\":\"" + colorStr + "\","; + + std::string heightStr; + FloatToString( height, heightStr ); + underlineProperties += "\"height\":\"" + heightStr + "\"}"; + + value = underlineProperties; + } + else + { + Property::Map map; - const std::string enabledStr = enabled ? TRUE_TOKEN : FALSE_TOKEN; - map.Insert( ENABLE_KEY, enabledStr ); + 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 colorStr; + Vector4ToColorString( color, colorStr ); + map.Insert( COLOR_KEY, colorStr ); - std::string heightStr; - FloatToString( height, heightStr ); - map.Insert( HEIGHT_KEY, heightStr ); + std::string heightStr; + FloatToString( height, heightStr ); + map.Insert( HEIGHT_KEY, heightStr ); + + value = map; + } - value = map; break; } case EffectStyle::INPUT: @@ -244,11 +291,35 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value bool offsetDefined = false; Vector2 offset; - const bool empty = ParseShadowProperties( propertiesMap, - colorDefined, - color, - offsetDefined, - offset ); + bool empty = true; + + if ( propertiesMap.Empty() ) + { + // Map empty so check if a string provided + const std::string propertyString = value.Get(); + + Property::Map parsedStringMap; + Text::ParsePropertyString( propertyString, parsedStringMap ); + + empty = ParseShadowProperties( parsedStringMap, + colorDefined, + color, + offsetDefined, + offset ); + + controller->ShadowSetByString( !empty ); + + } + else + { + empty = ParseShadowProperties( propertiesMap, + colorDefined, + color, + offsetDefined, + offset ); + + controller->ShadowSetByString( false ); + } if( !empty ) { @@ -299,17 +370,34 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe const Vector4& color = controller->GetShadowColor(); const Vector2& offset = controller->GetShadowOffset(); - Property::Map map; + if ( controller->IsShadowSetByString() ) + { + std::string shadowProperties = "{"; - std::string colorStr; - Vector4ToColorString( color, colorStr ); - map.Insert( COLOR_KEY, colorStr ); + std::string colorStr; + Vector4ToColorString( color, colorStr ); + shadowProperties += "\"color\":\"" + colorStr + "\","; - std::string offsetStr; - Vector2ToString( offset, offsetStr ); - map.Insert( OFFSET_KEY, offsetStr ); + std::string offsetStr; + Vector2ToString( offset, offsetStr ); + shadowProperties += "\"offset\":\"" + offsetStr + "\"}"; - value = map; + value = shadowProperties; + } + else + { + Property::Map map; + + std::string colorStr; + Vector4ToColorString( color, colorStr ); + map.Insert( COLOR_KEY, colorStr ); + + std::string offsetStr; + Vector2ToString( offset, offsetStr ); + map.Insert( OFFSET_KEY, offsetStr ); + + value = map; + } break; } case EffectStyle::INPUT: -- 2.7.4