From 8177827cf40d243367b4c92ea8d5e3c40d42f3ae Mon Sep 17 00:00:00 2001 From: "Jinho, Lee" Date: Fri, 19 May 2017 16:08:54 +0900 Subject: [PATCH] Text style to return properties(FONT_STYLE) as string Change-Id: I0365eed729f5beef330b0a1bd2c356fbd0c050bc --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 22 +++++ .../src/dali-toolkit/utc-Dali-TextLabel.cpp | 6 +- dali-toolkit/internal/text/text-controller-impl.h | 4 +- dali-toolkit/internal/text/text-controller.cpp | 10 ++ dali-toolkit/internal/text/text-controller.h | 12 +++ dali-toolkit/internal/text/text-font-style.cpp | 107 ++++++++++++++++----- 6 files changed, 131 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 ff32ccf..5cacd19 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -1913,3 +1913,25 @@ int utcDaliTextEditorShadowPropertyStringP(void) END_TEST; } + +int utcDaliTextEditorFontStylePropertyStringP(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorFontStylePropertyStringP Setting FontStyle propeties by string"); + + TextEditor editor = TextEditor::New(); + + std::string fontStyleSettings( "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" ); + + Stage::GetCurrent().Add( editor ); + + editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" ); + + Property::Value value = editor.GetProperty( TextEditor::Property::FONT_STYLE ); + std::string result; + value.Get(result); + + DALI_TEST_EQUALS( result, fontStyleSettings, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 5671523..4c1e449 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -251,11 +251,11 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) fontStyleMapSet.Insert( "weight", "thin" ); fontStyleMapSet.Insert( "width", "expanded" ); fontStyleMapSet.Insert( "slant", "oblique" ); + const std::string strFontStyle = "{\"weight\":\"thin\",\"width\":\"expanded\",\"slant\":\"oblique\"}"; label.SetProperty( TextLabel::Property::FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"expanded\",\"slant\":\"oblique\"}" ); - fontStyleMapGet = label.GetProperty( TextLabel::Property::FONT_STYLE ); - DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + std::string getFontStyle = label.GetProperty( TextLabel::Property::FONT_STYLE ); + DALI_TEST_EQUALS( getFontStyle, strFontStyle, TEST_LOCATION ); label.SetProperty( TextLabel::Property::POINT_SIZE, 10.f ); DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 43a7cf3..3014edb 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -316,7 +316,8 @@ struct Controller::Impl mIsAutoScrollEnabled( false ), mAutoScrollDirectionRTL( false ), mUnderlineSetByString( false ), - mShadowSetByString( false ) + mShadowSetByString( false ), + mFontStyleSetByString( false ) { mModel = Model::New(); @@ -725,6 +726,7 @@ public: 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 + bool mFontStyleSetByString:1; ///< Set when font style 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 d02f9aa..a502200 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1438,6 +1438,16 @@ void Controller::ShadowSetByString( bool setByString ) mImpl->mShadowSetByString = setByString; } +bool Controller::IsFontStyleSetByString() +{ + return mImpl->mFontStyleSetByString; +} + +void Controller::FontStyleSetByString( bool setByString ) +{ + mImpl->mFontStyleSetByString = 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 b9cbb2c..7562394 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -422,6 +422,18 @@ public: // Configure the text controller. */ void ShadowSetByString( bool setByString ); + /** + * @brief Query if font style settings were provided by string or map + * @return bool true if set by string + */ + bool IsFontStyleSetByString(); + + /** + * Set method font style setting were set by + * @param[in] bool, true if set by string + */ + void FontStyleSetByString( bool setByString ); + public: // Update. /** diff --git a/dali-toolkit/internal/text/text-font-style.cpp b/dali-toolkit/internal/text/text-font-style.cpp index 6a57337..249157e 100644 --- a/dali-toolkit/internal/text/text-font-style.cpp +++ b/dali-toolkit/internal/text/text-font-style.cpp @@ -114,10 +114,13 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu const std::string& fontStyleProperties = value.Get(); ParsePropertyString( fontStyleProperties, map ); + controller->FontStyleSetByString( true ); + } else { map = value.Get(); + controller->FontStyleSetByString( false ); } if( !map.Empty() ) @@ -243,6 +246,7 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon if( controller ) { const bool isDefaultStyle = FontStyle::DEFAULT == type; + const bool isSetbyString = controller->IsFontStyleSetByString(); bool weightDefined = false; bool widthDefined = false; @@ -294,46 +298,97 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon } } - Property::Map map; - - if( weightDefined ) + if( !isSetbyString ) { - if( TextAbstraction::FontWeight::NONE != weight ) + Property::Map map; + + if( weightDefined ) { - const std::string weightStr( GetEnumerationName( weight, - FONT_WEIGHT_STRING_TABLE, - FONT_WEIGHT_STRING_TABLE_COUNT ) ); + if( TextAbstraction::FontWeight::NONE != weight ) + { + const std::string weightStr( GetEnumerationName( weight, + FONT_WEIGHT_STRING_TABLE, + FONT_WEIGHT_STRING_TABLE_COUNT ) ); - map.Insert( WEIGHT_KEY, weightStr ); + map.Insert( WEIGHT_KEY, weightStr ); + } } - } - if( widthDefined ) - { - if( TextAbstraction::FontWidth::NONE != width ) + if( widthDefined ) + { + if( TextAbstraction::FontWidth::NONE != width ) + { + const std::string widthStr( GetEnumerationName( width, + FONT_WIDTH_STRING_TABLE, + FONT_WIDTH_STRING_TABLE_COUNT ) ); + + map.Insert( WIDTH_KEY, widthStr ); + } + } + + if( slantDefined ) { - const std::string widthStr( GetEnumerationName( width, - FONT_WIDTH_STRING_TABLE, - FONT_WIDTH_STRING_TABLE_COUNT ) ); + if( TextAbstraction::FontSlant::NONE != slant ) + { + const std::string slantStr( GetEnumerationName( slant, + FONT_SLANT_STRING_TABLE, + FONT_SLANT_STRING_TABLE_COUNT ) ); - map.Insert( WIDTH_KEY, widthStr ); + map.Insert( SLANT_KEY, slantStr ); + } } - } - if( slantDefined ) + value = map; + } // SetbyMAP + else { - if( TextAbstraction::FontSlant::NONE != slant ) + std::string fontStyleProperties = "{"; + + if( weightDefined ) { - const std::string slantStr( GetEnumerationName( slant, - FONT_SLANT_STRING_TABLE, - FONT_SLANT_STRING_TABLE_COUNT ) ); + if( TextAbstraction::FontWeight::NONE != weight ) + { + const std::string weightStr( GetEnumerationName( weight, + FONT_WEIGHT_STRING_TABLE, + FONT_WEIGHT_STRING_TABLE_COUNT ) ); - map.Insert( SLANT_KEY, slantStr ); + fontStyleProperties += "\"weight\":\"" + weightStr + "\","; + } } - } - value = map; - } + if( widthDefined ) + { + if( TextAbstraction::FontWidth::NONE != width ) + { + const std::string widthStr( GetEnumerationName( width, + FONT_WIDTH_STRING_TABLE, + FONT_WIDTH_STRING_TABLE_COUNT ) ); + fontStyleProperties += "\"width\":\"" + widthStr + "\","; + } + } + + if( slantDefined ) + { + if( TextAbstraction::FontSlant::NONE != slant ) + { + const std::string slantStr( GetEnumerationName( slant, + FONT_SLANT_STRING_TABLE, + FONT_SLANT_STRING_TABLE_COUNT ) ); + + fontStyleProperties += "\"slant\":\"" + slantStr + "\""; + } + } + + // If last character is comma, it will be removed. + if((*fontStyleProperties.rbegin()) == ',' ) + { + fontStyleProperties = fontStyleProperties.substr( 0, fontStyleProperties.size()-1 ); + } + fontStyleProperties += "}"; + + value = fontStyleProperties; + } // SetbyString + }// controller } FontWeight StringToWeight( const char* const weightStr ) -- 2.7.4