From: Victor Cebollada Date: Fri, 11 Jul 2014 06:29:04 +0000 (+0100) Subject: TextStyle - Merge operation added. X-Git-Tag: dali_1.0.1~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f85f68d2e3b1e2ad27fd597312c18b972816f67;p=platform%2Fcore%2Fuifw%2Fdali-core.git TextStyle - Merge operation added. It copies from a given text-style all parameters which are not default. It's useful to merge parameters from different text-styles into one. Change-Id: I36e8d481225f09fd5736ae4b8da7a3b78879760b Signed-off-by: Victor Cebollada --- diff --git a/automated-tests/src/dali/utc-Dali-TextStyle.cpp b/automated-tests/src/dali/utc-Dali-TextStyle.cpp index e1aa8dd..82c750f 100644 --- a/automated-tests/src/dali/utc-Dali-TextStyle.cpp +++ b/automated-tests/src/dali/utc-Dali-TextStyle.cpp @@ -806,6 +806,67 @@ int UtcDaliTextStyleCopy(void) END_TEST; } +int UtcDaliTextStyleMerge(void) +{ + tet_infoline(" UtcDaliTextStyleMerge "); + + TestApplication application; + + TextStyle defaultStyle; + + TextStyle style; + + // Set a style different than default. + TextStyle style2; + style2.SetFontName( FONT_FAMILY ); + style2.SetFontStyle( FONT_STYLE ); + style2.SetFontPointSize( FONT_POINT_SIZE ); + style2.SetTextColor( TEXT_COLOR ); + + style2.SetWeight( TEXT_WEIGHT ); + style2.SetSmoothEdge( SMOOTH_EDGE ); + + style2.SetItalics( ITALICS, ITALICS_ANGLE ); + style2.SetUnderline( UNDERLINE, UNDERLINE_THICKNESS, UNDERLINE_POSITION ); + style2.SetShadow( SHADOW, SHADOW_COLOR, SHADOW_OFFSET, SHADOW_SIZE ); + style2.SetGlow( GLOW, GLOW_COLOR, GLOW_INTENSITY ); + style2.SetOutline( OUTLINE, OUTLINE_COLOR, OUTLINE_THICKNESS ); + style2.SetGradient( GRADIENT, GRADIENT_COLOR, GRADIENT_START_POINT, GRADIENT_END_POINT ); + + // Test not to merge the same object. To increase coverage. + + const TextStyle& same( style2 ); + + style2.Merge( same ); + + DALI_TEST_CHECK( same == style2 ); + + // Test merge two styles + + style.Merge( style2 ); + + DALI_TEST_CHECK( style == style2 ); + + // Test merge a default style + + style.Merge( defaultStyle ); + + DALI_TEST_CHECK( style == style2 ); + + // Tests to increase branch coverage. + + style = defaultStyle; + style.SetFontName( FONT_FAMILY ); + + TextStyle style3; + style3.Merge( style ); + + DALI_TEST_CHECK( style == style3 ); + + + END_TEST; +} + int UtcDaliTextStyleReset(void) { tet_infoline(" UtcDaliTextStyleReset "); diff --git a/dali/public-api/text/text-style.cpp b/dali/public-api/text/text-style.cpp index 3bdd915..69d1c41 100644 --- a/dali/public-api/text/text-style.cpp +++ b/dali/public-api/text/text-style.cpp @@ -816,6 +816,107 @@ void TextStyle::Copy( const TextStyle& textStyle, Mask mask ) } } +void TextStyle::Merge( const TextStyle& textStyle, Mask mask ) +{ + // If we're attemping to merge ourselves then just return + if ( this == &textStyle ) + { + return; + } + + // Check to see if we're merging from default style ? + if ( textStyle.mContainer == NULL ) + { + // nothing to merge. + return; + } + + if( mask & FONT ) + { + if( !textStyle.IsFontNameDefault() ) + { + SetFontName( textStyle.GetFontName() ); + } + } + if( mask & STYLE ) + { + if( !textStyle.IsFontStyleDefault() ) + { + SetFontStyle( textStyle.GetFontStyle() ); + } + } + if( mask & SIZE ) + { + if( !textStyle.IsFontSizeDefault() ) + { + SetFontPointSize( textStyle.GetFontPointSize() ); + } + } + if( mask & COLOR ) + { + if( !textStyle.IsTextColorDefault() ) + { + SetTextColor( textStyle.GetTextColor() ) ; + } + } + if( mask & WEIGHT ) + { + if( !textStyle.IsFontWeightDefault() ) + { + SetWeight( textStyle.GetWeight() ); + } + } + if( mask & SMOOTH ) + { + if( !textStyle.IsSmoothEdgeDefault() ) + { + SetSmoothEdge( textStyle.GetSmoothEdge() ); + } + } + if( mask & ITALICS ) + { + if( !textStyle.IsItalicsDefault() ) + { + SetItalics( textStyle.IsItalicsEnabled(), textStyle.GetItalicsAngle() ); + } + } + if( mask & UNDERLINE ) + { + if( !textStyle.IsUnderlineDefault() ) + { + SetUnderline( textStyle.IsUnderlineEnabled(), textStyle.GetUnderlineThickness(), textStyle.GetUnderlinePosition() ); + } + } + if( mask & SHADOW ) + { + if( !textStyle.IsShadowDefault() ) + { + SetShadow( textStyle.IsShadowEnabled(), textStyle.GetShadowColor(), textStyle.GetShadowOffset(), textStyle.GetShadowSize() ); + } + } + if( mask & GLOW ) + { + if( !textStyle.IsGlowDefault() ) + { + SetGlow( textStyle.IsGlowEnabled(), textStyle.GetGlowColor(), textStyle.GetGlowIntensity() ); + } + } + if( mask & OUTLINE ) + { + if( !textStyle.IsOutlineDefault() ) + { + SetOutline( textStyle.IsOutlineEnabled(), textStyle.GetOutlineColor(), textStyle.GetOutlineThickness() ); + } + } + if( mask & GRADIENT ) + { + if( !textStyle.IsGradientDefault() ) + { + SetGradient( textStyle.IsGradientEnabled(), textStyle.GetGradientColor(), textStyle.GetGradientStartPoint(), textStyle.GetGradientEndPoint() ); + } + } +} + void TextStyle::Reset( Mask mask ) { if( NULL == mContainer ) diff --git a/dali/public-api/text/text-style.h b/dali/public-api/text/text-style.h index e404a4f..f7cf48f 100644 --- a/dali/public-api/text/text-style.h +++ b/dali/public-api/text/text-style.h @@ -147,6 +147,14 @@ public: void Copy( const TextStyle& textStyle, Mask mask = ALL ); /** + * @brief Copies from the given text style those parameters specified in the given mask which are not default. + * + * @param[in] textStyle The given text style. + * @param[in] mask Specifies which text style parameters are going to be copied. By default all parateres are copied. + */ + void Merge( const TextStyle& textStyle, Mask mask = ALL ); + + /** * @brief Resets to default the text style parameters specified in the mask. * * @param[in] mask Specifies which text style parameters are going to be reset. By default all parateres are reset.