From: Victor Cebollada Date: Mon, 17 Oct 2016 13:51:57 +0000 (+0100) Subject: Convert the Underline and Shadow deprecated APIs to the new ones. X-Git-Tag: dali_1.2.11~5^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=c6fbedbc9a4dc72411836315807169aef2a6670b Convert the Underline and Shadow deprecated APIs to the new ones. This needs to be done to pass the UTC in the TextVisual patch currently in developement. Change-Id: I517fba6b78115d9bf77ea0998c54e500475102a6 Signed-off-by: Victor Cebollada --- diff --git a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt index 05380dd..4a9a003 100644 --- a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt @@ -20,6 +20,7 @@ SET(TC_SOURCES utc-Dali-Text-Controller.cpp utc-Dali-VisualFactoryResolveUrl.cpp utc-Dali-Visuals.cpp + utc-Dali-Text-Markup.cpp ) # Append list of test harness files (Won't get parsed for test cases) diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp index c67f622..ae91f4c 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp @@ -328,3 +328,39 @@ int UtcDaliTextControllerTextPopupButtonTouched(void) tet_result(TET_PASS); END_TEST; } + +int UtcDaliTextControllerGetInputShadowProperty(void) +{ + tet_infoline(" UtcDaliTextControllerGetInputShadowProperty"); + ToolkitTestApplication application; + + // Creates a text controller. + ControllerPtr controller = Controller::New(); + + DALI_TEST_CHECK( controller ); + + const std::string& shadowProperties = controller->GetInputShadowProperties(); + + DALI_TEST_CHECK( shadowProperties.empty() ); + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextControllerGetInputUnderlineProperty(void) +{ + tet_infoline(" UtcDaliTextControllerGetInputUnderlineProperty"); + ToolkitTestApplication application; + + // Creates a text controller. + ControllerPtr controller = Controller::New(); + + DALI_TEST_CHECK( controller ); + + const std::string& underlineProperties = controller->GetInputUnderlineProperties(); + + DALI_TEST_CHECK( underlineProperties.empty() ); + + tet_result(TET_PASS); + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Markup.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Markup.cpp new file mode 100644 index 0000000..23f7e51 --- /dev/null +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Markup.cpp @@ -0,0 +1,453 @@ +/* + * Copyright (c) 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Dali; +using namespace Toolkit; +using namespace Text; + +namespace +{ + /////////////////////////////////////////////////////////// + + struct TokenComparisonData + { + std::string description; + std::string string1; ///< must be in lower case!!!! + std::string string2; + bool expectedResult; + }; + + bool TokenComparisonTest( const TokenComparisonData& data ) + { + std::cout << " testing " << data.description << std::endl; + + const bool result = TokenComparison( data.string1, + data.string2.c_str(), + data.string2.size() ); + + if( result != data.expectedResult ) + { + std::cout << " different conparison result : " << result << ", expected : " << data.expectedResult << std::endl; + std::cout << " comparing : [" << data.string1 << "] and [" << data.string2 << "]" << std::endl; + + return false; + } + + return true; + } + + /////////////////////////////////////////////////////////// + + struct ColorStringToVector4Data + { + std::string description; + std::string colorStr; + Vector4 expectedColor; + }; + + bool ColorStringToVector4Test( const ColorStringToVector4Data& data ) + { + std::cout << " testing " << data.description << std::endl; + + Vector4 color; + ColorStringToVector4( data.colorStr.c_str(), data.colorStr.size(), color ); + + if( color != data.expectedColor ) + { + std::cout << " different color : " << color << ", expected : " << data.expectedColor << std::endl; + return false; + } + + return true; + } + + /////////////////////////////////////////////////////////// + + struct Vector4ToColorStringData + { + std::string description; + Vector4 color; + std::string expectedColorStr; + }; + + bool Vector4ToColorStringTest( const Vector4ToColorStringData& data ) + { + std::cout << " testing " << data.description << std::endl; + + std::string colorStr; + Vector4ToColorString( data.color, colorStr ); + + if( colorStr != data.expectedColorStr ) + { + std::cout << " different color : [" << colorStr << "], expected : [" << data.expectedColorStr << "]" << std::endl; + return false; + } + + return true; + } + + /////////////////////////////////////////////////////////// + + struct StringToVector2Data + { + std::string description; + std::string vector2Str; + Vector2 expectedVector2; + }; + + bool StringToVector2Test( const StringToVector2Data& data ) + { + std::cout << " testing " << data.description << std::endl; + + Vector2 vector2; + StringToVector2( data.vector2Str.c_str(), data.vector2Str.size(), vector2 ); + + if( vector2 != data.expectedVector2 ) + { + std::cout << " different vector2 : " << vector2 << ", expected : " << data.expectedVector2 << std::endl; + return false; + } + + return true; + } + + /////////////////////////////////////////////////////////// + + + struct Vector2ToStringData + { + std::string description; + Vector2 vector2; + std::string expectedVector2Str; + }; + + bool Vector2ToStringTest( const Vector2ToStringData& data ) + { + std::cout << " testing " << data.description << std::endl; + + std::string vector2Str; + Vector2ToString( data.vector2, vector2Str ); + + if( vector2Str != data.expectedVector2Str ) + { + std::cout << " different vector2 : [" << vector2Str << "], expected : [" << data.expectedVector2Str << "]" << std::endl; + return false; + } + + return true; + } + +} // namespace + +int UtcDaliTextTokenComparison(void) +{ + tet_infoline(" UtcDaliTextTokenComparison"); + + const TokenComparisonData data[] = + { + { + "void texts", + "", + "", + true + }, + { + "different size text", + "hello", + "world!", + false + }, + { + "different texts", + "hello", + "world", + false + }, + { + "same texts", + "world", + "wOrLD", + true + }, + { + "some punctuation characters, numbers, ...", + "hello0123456789.![?]", + "Hello0123456789.![?]", + true + } + + }; + const unsigned int numberOfTests = 5u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + ToolkitTestApplication application; + if( !TokenComparisonTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextColorStringToVector4(void) +{ + tet_infoline(" UtcDaliTextColorStringToVector4"); + + const ColorStringToVector4Data data[] = + { + { + "black string", + "bLack", + Color::BLACK + }, + { + "white string", + "White", + Color::WHITE + }, + { + "red string", + "reD", + Color::RED + }, + { + "green string", + "green", + Color::GREEN + }, + { + "blue string", + "blue", + Color::BLUE + }, + { + "yellow string", + "yeLloW", + Color::YELLOW + }, + { + "magenta string", + "MagEnta", + Color::MAGENTA + }, + { + "cyan string", + "CyaN", + Color::CYAN + }, + { + "transparent string", + "transparent", + Color::TRANSPARENT + }, + { + "3 component web color", + "#F00", + Color::RED + }, + { + "6 component web color", + "#fF0000", + Color::RED + }, + { + "hex color red (ARGB)", + "0xffff0000", + Color::RED + }, + { + "hex color green (ARGB)", + "0xFf00FF00", + Color::GREEN + }, + { + "undefined color", + "undefined", + Vector4::ZERO + }, + }; + const unsigned int numberOfTests = 14u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + ToolkitTestApplication application; + if( !ColorStringToVector4Test( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextVector4ToColorString(void) +{ + tet_infoline(" UtcDaliTextVector4ToColorString"); + + const Vector4ToColorStringData data[] = + { + { + "black color", + Color::BLACK, + "black" + }, + { + "white string", + Color::WHITE, + "white" + }, + { + "red string", + Color::RED, + "red" + }, + { + "green string", + Color::GREEN, + "green" + }, + { + "blue string", + Color::BLUE, + "blue" + }, + { + "yellow string", + Color::YELLOW, + "yellow" + }, + { + "magenta string", + Color::MAGENTA, + "magenta", + }, + { + "cyan string", + Color::CYAN, + "cyan" + }, + { + "transparent string", + Color::TRANSPARENT, + "transparent" + }, + { + "hex color", + Vector4( 0.4f, 0.5f, 0.6f, 1.f ), + "0xff667f99" + }, + }; + const unsigned int numberOfTests = 10u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + ToolkitTestApplication application; + if( !Vector4ToColorStringTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextStringToVector2(void) +{ + tet_infoline(" UtcDaliTextStringToVector2"); + const StringToVector2Data data[] = + { + { + "void text", + "", + Vector2::ZERO + }, + { + "zero zero", + "0 0", + Vector2::ZERO + }, + { + "five four", + "5 4", + Vector2(5.f, 4.f) + } + }; + const unsigned int numberOfTests = 3u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + ToolkitTestApplication application; + if( !StringToVector2Test( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextVector2ToString(void) +{ + tet_infoline(" UtcDaliTextVector2ToString"); + const Vector2ToStringData data[] = + { + { + "zero zero", + Vector2::ZERO, + "0 0", + }, + { + "five four", + Vector2(5.f, 4.f), + "5 4", + } + }; + const unsigned int numberOfTests = 2u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + ToolkitTestApplication application; + if( !Vector2ToStringTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 83744f3..b6b638c 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -441,16 +441,16 @@ int UtcDaliTextEditorSetPropertyP(void) DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); // Check the underline property - editor.SetProperty( TextEditor::Property::UNDERLINE, "Underline properties" ); - DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::UNDERLINE, "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::UNDERLINE ), std::string("{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}"), TEST_LOCATION ); // Check the input underline property editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" ); DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION ); // Check the shadow property - editor.SetProperty( TextEditor::Property::SHADOW, "Shadow properties" ); - DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" ); + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"2 2\"}"), TEST_LOCATION ); // Check the input shadow property editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 0335e4e..80ed1d7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -612,16 +612,16 @@ int UtcDaliTextFieldSetPropertyP(void) DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION ); // Check the underline property - field.SetProperty( TextField::Property::UNDERLINE, "Underline properties" ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION ); + field.SetProperty( TextField::Property::UNDERLINE, "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::UNDERLINE ), std::string("{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}"), TEST_LOCATION ); // Check the input underline property field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION ); // Check the shadow property - field.SetProperty( TextField::Property::SHADOW, "Shadow properties" ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION ); + field.SetProperty( TextField::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"2 2\"}"), TEST_LOCATION ); // Check the input shadow property field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 5f9a710..c185ee2 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -222,6 +222,8 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) // The underline color is changed as well. DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::UNDERLINE_COLOR ), Color::BLUE, TEST_LOCATION ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::UNDERLINE ), std::string("{\"enable\":\"false\",\"color\":\"blue\",\"height\":\"0\"}"), TEST_LOCATION ); + // Check that shadow parameters can be correctly set label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 3.0f, 3.0f ) ); DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::SHADOW_OFFSET ), Vector2( 3.0f, 3.0f ), TEST_LOCATION ); @@ -266,12 +268,18 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); // Check the underline property - label.SetProperty( TextLabel::Property::UNDERLINE, "Underline properties" ); - DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION ); + label.SetProperty( TextLabel::Property::UNDERLINE, "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::UNDERLINE ), std::string("{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}"), TEST_LOCATION ); + + label.SetProperty( TextLabel::Property::UNDERLINE, "" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::UNDERLINE ), std::string("{\"enable\":\"false\",\"color\":\"red\",\"height\":\"1\"}"), TEST_LOCATION ); // Check the shadow property - label.SetProperty( TextLabel::Property::SHADOW, "Shadow properties" ); - DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION ); + label.SetProperty( TextLabel::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"2 2\"}"), TEST_LOCATION ); + + label.SetProperty( TextLabel::Property::SHADOW, "" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"0 0\"}"), TEST_LOCATION ); // Check the emboss property label.SetProperty( TextLabel::Property::EMBOSS, "Emboss properties" ); diff --git a/dali-toolkit/internal/text/markup-processor-helper-functions.cpp b/dali-toolkit/internal/text/markup-processor-helper-functions.cpp index 3c02c27..8af6140 100644 --- a/dali-toolkit/internal/text/markup-processor-helper-functions.cpp +++ b/dali-toolkit/internal/text/markup-processor-helper-functions.cpp @@ -20,7 +20,10 @@ // EXTERNAL INCLUDES #include +#include #include +#include +#include namespace Dali { @@ -33,9 +36,10 @@ namespace Text namespace { -const char WHITE_SPACE = 0x20; // ASCII value of the white space. -const char LAST_UPPER_CASE = 0x5b; // ASCII value of the one after the last upper case character (Z). -const char TO_LOWER_CASE = 32; // Value to add to a upper case character to transform it into a lower case. +const char WHITE_SPACE = 0x20; // ASCII value of the white space. +const char FIRST_UPPER_CASE = 0x41; // ASCII value of the one after the first upper case character (A). +const char LAST_UPPER_CASE = 0x5b; // ASCII value of the one after the last upper case character (Z). +const char TO_LOWER_CASE = 32; // Value to add to a upper case character to transform it into a lower case. const char WEB_COLOR_TOKEN( '#' ); const char* const HEX_COLOR_TOKEN( "0x" ); @@ -65,8 +69,9 @@ bool TokenComparison( const std::string& string1, const char* const stringBuffer for( std::size_t index = 0; index < stringSize; ++index ) { - char character = *( stringBuffer2 + index ); - if( *( stringBuffer1 + index ) != ( ( ( character < LAST_UPPER_CASE ) && ( '0' != character ) ) ? character + TO_LOWER_CASE : character ) ) + const char character = *( stringBuffer2 + index ); + const bool toLower = ( character < LAST_UPPER_CASE ) && ( character >= FIRST_UPPER_CASE ); + if( *( stringBuffer1 + index ) != ( toLower ? character + TO_LOWER_CASE : character ) ) { return false; } @@ -75,10 +80,16 @@ bool TokenComparison( const std::string& string1, const char* const stringBuffer return true; } -void SkipWhiteSpace( const char*& markupStringBuffer, - const char* const markupStringEndBuffer ) +void SkipWhiteSpace( const char*& stringBuffer, + const char* const stringEndBuffer ) { - for( ; ( WHITE_SPACE >= *markupStringBuffer ) && ( markupStringBuffer < markupStringEndBuffer ); ++markupStringBuffer ); + for( ; ( WHITE_SPACE >= *stringBuffer ) && ( stringBuffer < stringEndBuffer ); ++stringBuffer ); +} + +void JumpToWhiteSpace( const char*& stringBuffer, + const char* const stringEndBuffer ) +{ + for( ; ( WHITE_SPACE != *stringBuffer ) && ( stringBuffer < stringEndBuffer ); ++stringBuffer ); } unsigned int StringToHex( const char* const uintStr ) @@ -91,6 +102,13 @@ float StringToFloat( const char* const floatStr ) return static_cast( strtod( floatStr, NULL ) ); } +void FloatToString( float value, std::string& floatStr ) +{ + std::stringstream ss; + ss << value; + floatStr = ss.str(); +} + void UintColorToVector4( unsigned int color, Vector4& retColor ) { retColor.a = static_cast( ( color & 0xFF000000 ) >> 24u ) / 255.f; @@ -160,6 +178,112 @@ void ColorStringToVector4( const char* const colorStr, Length length, Vector4& r } } +void Vector4ToColorString( const Vector4& value, std::string& vector2Str ) +{ + if( Color::BLACK == value ) + { + vector2Str = BLACK_COLOR; + return; + } + + if( Color::WHITE == value ) + { + vector2Str = WHITE_COLOR; + return; + } + + if( Color::RED == value ) + { + vector2Str = RED_COLOR; + return; + } + + if( Color::GREEN == value ) + { + vector2Str = GREEN_COLOR; + return; + } + + if( Color::BLUE == value ) + { + vector2Str = BLUE_COLOR; + return; + } + + if( Color::YELLOW == value ) + { + vector2Str = YELLOW_COLOR; + return; + } + + if( Color::MAGENTA == value ) + { + vector2Str = MAGENTA_COLOR; + return; + } + + if( Color::CYAN == value ) + { + vector2Str = CYAN_COLOR; + return; + } + + if( Color::TRANSPARENT == value ) + { + vector2Str = TRANSPARENT_COLOR; + return; + } + + const unsigned int alpha = static_cast( 255.f * value.a ); + const unsigned int red = static_cast( 255.f * value.r ); + const unsigned int green = static_cast( 255.f * value.g ); + const unsigned int blue = static_cast( 255.f * value.b ); + + std::stringstream ss; + const unsigned int size = 2u * sizeof( unsigned char ); + + ss << "0x" + << std::setfill('0') << std::setw( size ) + << std::hex << alpha + << std::setfill('0') << std::setw( size ) + << std::hex << red + << std::setfill('0') << std::setw( size ) + << std::hex << green + << std::setfill('0') << std::setw( size ) + << std::hex << blue; + vector2Str = ss.str(); +} + +void StringToVector2( const char* const vectorStr, Length length, Vector2& vector2 ) +{ + // Points to the first character of the string. + const char* strBuffer = vectorStr; + + // Points to the first character of the 'x' value. + const char* const xBuffer = strBuffer; + + // Jumps to the next white space. + JumpToWhiteSpace( strBuffer, strBuffer + length ); + + // Points to the first character of the 'y' value. + const char* const yBuffer = strBuffer; + + // Converts the shadow's offset to float. + vector2.x = StringToFloat( xBuffer ); + vector2.y = StringToFloat( yBuffer ); +} + +void Vector2ToString( const Vector2& value, std::string& vector2Str ) +{ + FloatToString( value.x, vector2Str ); + vector2Str += " "; + + std::string yStr; + FloatToString( value.y, yStr ); + + vector2Str += yStr; +} + } // namespace Text } // namespace Toolkit diff --git a/dali-toolkit/internal/text/markup-processor-helper-functions.h b/dali-toolkit/internal/text/markup-processor-helper-functions.h index 62be6c8..45f586c 100644 --- a/dali-toolkit/internal/text/markup-processor-helper-functions.h +++ b/dali-toolkit/internal/text/markup-processor-helper-functions.h @@ -28,6 +28,7 @@ namespace Dali { +struct Vector2; struct Vector4; namespace Toolkit @@ -78,11 +79,20 @@ bool TokenComparison( const std::string& string1, const char* const stringBuffer /** * @brief Skips any unnecessary white space. * - * @param[in,out] markupStringBuffer The mark-up string buffer. It's a const iterator pointing the current character. - * @param[in] markupStringEndBuffer Pointer to one character after the end of the mark-up string buffer. + * @param[in,out] stringBuffer The string buffer. It's a const iterator pointing the current character. + * @param[in] stringEndBuffer Pointer to one character after the end of the string buffer. */ -void SkipWhiteSpace( const char*& markupStringBuffer, - const char* const markupStringEndBuffer ); +void SkipWhiteSpace( const char*& stringBuffer, + const char* const stringEndBuffer ); + +/** + * @Brief Jumps to the next white space. + * + * @param[in,out] stringBuffer The string buffer. It's a const iterator pointing the current character. + * @param[in] stringEndBuffer Pointer to one character after the end of the string buffer. + */ +void JumpToWhiteSpace( const char*& stringBuffer, + const char* const stringEndBuffer ); /** * @brief Converts a string into an hexadecimal unsigned int. @@ -103,6 +113,14 @@ unsigned int StringToHex( const char* const uintStr ); float StringToFloat( const char* const floatStr ); /** + * @brief Converts a float into a string. + * + * @param[in] value The float value. + * @param[out] floatStr The string. + */ +void FloatToString( float value, std::string& floatStr ); + +/** * @brief Converts an ARGB color packed in 4 byte unsigned int into a Vector4 color used in Dali. * * @param[in] color An ARGB color packed in an unsigned int. @@ -114,7 +132,7 @@ void UintColorToVector4( unsigned int color, Vector4& retColor ); * @brief Converts a color packed inside a string into an ARGB Vector4 color. * * The string color could be in hexadecimal ( 0xFF0000FF ), webcolor ( #0000FF or #00F ) or some constant values: - * black, white, red, green, blue, yellow, magenta, cyan, transparent. + * black, white, red, green, blue, yellow, magenta, cyan or transparent. * * @param[in] colorStr A color packed inside a string. * @param[in] length The length of the color string. @@ -122,6 +140,35 @@ void UintColorToVector4( unsigned int color, Vector4& retColor ); */ void ColorStringToVector4( const char* const colorStr, Length length, Vector4& retColor ); +/** + * @brief Converts a color packed in a Vector4 into a string. + * + * Constant colors will be converted to the strings black, white, red, green, blue, yellow, magenta, cyan or transparent. + * + * If is not a constant color it will be converted to a string with hexadecimal ARGB content. + * + * @param[in] value The color value. + * @param[out] colorStr The string. + */ +void Vector4ToColorString( const Vector4& value, std::string& vector2Str ); + +/** + * @brief Converts a two dimension vector packed inside a string into a Vector2. + * + * @param[in] vectorStr The two dimension vector packed inside a string. + * @param[in] length The length of the string. + * @param[out] vector2 The Vector2. + */ +void StringToVector2( const char* const vectorStr, Length length, Vector2& vector2 ); + +/** + * @brief Converts a Vector2 into a string. + * + * @param[in] value The vector2 value. + * @param[out] vector2Str The string. + */ +void Vector2ToString( const Vector2& value, std::string& vector2Str ); + } // namespace Text } // namespace Toolkit diff --git a/dali-toolkit/internal/text/property-string-parser.cpp b/dali-toolkit/internal/text/property-string-parser.cpp index 42b1050..2aa05e9 100644 --- a/dali-toolkit/internal/text/property-string-parser.cpp +++ b/dali-toolkit/internal/text/property-string-parser.cpp @@ -79,27 +79,6 @@ void ParsePropertyString( const std::string& property, Property::Map& map ) } } -void StringOffsetToVector2( const std::string& offsetStr, - Vector2& offset ) -{ - offset = Vector2::ZERO; - - unsigned int wsIndex = 0u; - for( std::string::const_iterator it = offsetStr.begin(), - endIt = offsetStr.end(); - it != endIt; - ++it, ++wsIndex ) - { - if( *it == ' ' ) - { - break; - } - } - - offset[0] = StringToFloat( offsetStr.c_str() ); - offset[1] = StringToFloat( offsetStr.c_str() + wsIndex ); -} - } //namespace Text } //namespace Toolkit diff --git a/dali-toolkit/internal/text/property-string-parser.h b/dali-toolkit/internal/text/property-string-parser.h index b6ebf27..19d78b7 100644 --- a/dali-toolkit/internal/text/property-string-parser.h +++ b/dali-toolkit/internal/text/property-string-parser.h @@ -56,16 +56,6 @@ void CreatePropertyMap( const TreeNode* const node, Property::Map& map ); */ void ParsePropertyString( const std::string& property, Property::Map& map ); -/** - * @brief Converts an offset packed inside a string into a Vector2. - * - * @param[in] offsetStr The offset packed inside a string. - * @param[out] offset The offset packed in a Vector2. - * - */ -void StringOffsetToVector2( const std::string& offsetStr, - Vector2& offset ); - } //namespace Text } //namespace Toolkit diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 91f8673..59040fd 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -758,26 +758,6 @@ const Vector4& Controller::GetShadowColor() const return mImpl->mVisualModel->GetShadowColor(); } -void Controller::SetDefaultShadowProperties( const std::string& shadowProperties ) -{ - if( NULL == mImpl->mShadowDefaults ) - { - mImpl->mShadowDefaults = new ShadowDefaults(); - } - - mImpl->mShadowDefaults->properties = shadowProperties; -} - -const std::string& Controller::GetDefaultShadowProperties() const -{ - if( NULL != mImpl->mShadowDefaults ) - { - return mImpl->mShadowDefaults->properties; - } - - return EMPTY_STRING; -} - void Controller::SetUnderlineColor( const Vector4& color ) { mImpl->mVisualModel->SetUnderlineColor( color ); @@ -814,26 +794,6 @@ float Controller::GetUnderlineHeight() const return mImpl->mVisualModel->GetUnderlineHeight(); } -void Controller::SetDefaultUnderlineProperties( const std::string& underlineProperties ) -{ - if( NULL == mImpl->mUnderlineDefaults ) - { - mImpl->mUnderlineDefaults = new UnderlineDefaults(); - } - - mImpl->mUnderlineDefaults->properties = underlineProperties; -} - -const std::string& Controller::GetDefaultUnderlineProperties() const -{ - if( NULL != mImpl->mUnderlineDefaults ) - { - return mImpl->mUnderlineDefaults->properties; - } - - return EMPTY_STRING; -} - void Controller::SetDefaultEmbossProperties( const std::string& embossProperties ) { if( NULL == mImpl->mEmbossDefaults ) @@ -1278,7 +1238,7 @@ const std::string& Controller::GetInputShadowProperties() const return mImpl->mEventData->mInputStyle.shadowProperties; } - return GetDefaultShadowProperties(); + return EMPTY_STRING; } void Controller::SetInputUnderlineProperties( const std::string& underlineProperties ) @@ -1296,7 +1256,7 @@ const std::string& Controller::GetInputUnderlineProperties() const return mImpl->mEventData->mInputStyle.underlineProperties; } - return GetDefaultUnderlineProperties(); + return EMPTY_STRING; } void Controller::SetInputEmbossProperties( const std::string& embossProperties ) diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index f99d5a9..26a0ccb 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -499,22 +499,6 @@ public: // Default style & Input style const Vector4& GetShadowColor() const; /** - * @brief Sets the shadow's properties string. - * - * @note The string is stored to be recovered. - * - * @param[in] shadowProperties The shadow's properties string. - */ - void SetDefaultShadowProperties( const std::string& shadowProperties ); - - /** - * @brief Retrieves the shadow's properties string. - * - * @return The shadow's properties string. - */ - const std::string& GetDefaultShadowProperties() const; - - /** * @brief Set the underline color. * * @param[in] color color of underline. @@ -557,22 +541,6 @@ public: // Default style & Input style float GetUnderlineHeight() const; /** - * @brief Sets the underline's properties string. - * - * @note The string is stored to be recovered. - * - * @param[in] underlineProperties The underline's properties string. - */ - void SetDefaultUnderlineProperties( const std::string& underlineProperties ); - - /** - * @brief Retrieves the underline's properties string. - * - * @return The underline's properties string. - */ - const std::string& GetDefaultUnderlineProperties() const; - - /** * @brief Sets the emboss's properties string. * * @note The string is stored to be recovered. diff --git a/dali-toolkit/internal/text/text-effects-style.cpp b/dali-toolkit/internal/text/text-effects-style.cpp index 31580a2..1578329 100644 --- a/dali-toolkit/internal/text/text-effects-style.cpp +++ b/dali-toolkit/internal/text/text-effects-style.cpp @@ -35,7 +35,9 @@ namespace { const std::string COLOR_KEY( "color" ); const std::string OFFSET_KEY( "offset" ); -const std::string THICKNESS_KEY( "thickness" ); +const std::string HEIGHT_KEY( "height" ); +const std::string ENABLE_KEY( "enable" ); +const std::string TRUE_TOKEN( "true" ); } bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) @@ -44,23 +46,7 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va if( controller ) { - const std::string properties = value.Get< std::string >(); - - switch( type ) - { - case EffectStyle::DEFAULT: - { - // Stores the default underline's properties string to be recovered by the GetUnderlineProperties() function. - controller->SetDefaultUnderlineProperties( properties ); - break; - } - case EffectStyle::INPUT: - { - // Stores the input underline's properties string to be recovered by the GetUnderlineProperties() function. - controller->SetInputUnderlineProperties( properties ); - break; - } - } + const std::string properties = value.Get(); // Parses and applies the style. Property::Map map; @@ -68,7 +54,18 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va if( !map.Empty() ) { - /// Color key + /// Enable key. + Property::Value* enableValue = map.Find( ENABLE_KEY ); + + bool enabled = false; + const bool enabledDefined = enableValue != NULL; + if( enabledDefined ) + { + const std::string enableStr = enableValue->Get(); + enabled = TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() ); + } + + /// Color key. Property::Value* colorValue = map.Find( COLOR_KEY ); Vector4 color; @@ -80,25 +77,25 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); } - /// Thickness key - Property::Value* thicknessValue = map.Find( THICKNESS_KEY ); + /// Height key. + Property::Value* heightValue = map.Find( HEIGHT_KEY ); - float thickness = 0.f; - const bool thicknessDefined = thicknessValue != NULL; - if( thicknessDefined ) + float height = 0.f; + const bool heightDefined = heightValue != NULL; + if( heightDefined ) { - const std::string thicknessStr = thicknessValue->Get(); + const std::string heightStr = heightValue->Get(); - thickness = StringToFloat( thicknessStr.c_str() ); + height = StringToFloat( heightStr.c_str() ); } switch( type ) { case EffectStyle::DEFAULT: { - if( !controller->IsUnderlineEnabled() ) + if( enabled != controller->IsUnderlineEnabled() ) { - controller->SetUnderlineEnabled( true ); + controller->SetUnderlineEnabled( enabled ); update = true; } // Sets the default underline values. @@ -108,9 +105,9 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va update = true; } - if( thicknessDefined && fabsf( controller->GetUnderlineHeight() - thickness ) > Math::MACHINE_EPSILON_1000 ) + if( heightDefined && fabsf( controller->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 ) { - controller->SetUnderlineHeight( thickness ); + controller->SetUnderlineHeight( height ); update = true; } break; @@ -125,11 +122,25 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va } else { - // Disable underline. - if( controller->IsUnderlineEnabled() ) + switch( type ) { - controller->SetUnderlineEnabled( false ); - update = true; + case EffectStyle::DEFAULT: + { + // Disable underline. + if( controller->IsUnderlineEnabled() ) + { + controller->SetUnderlineEnabled( false ); + update = true; + } + break; + } + case EffectStyle::INPUT: + { + // Sets the input underline values. + // TODO: to be implemented. + controller->SetInputUnderlineProperties( properties ); + break; + } } } } @@ -145,7 +156,23 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E { case EffectStyle::DEFAULT: { - value = controller->GetDefaultUnderlineProperties(); + const bool enabled = controller->IsUnderlineEnabled(); + const Vector4& color = controller->GetUnderlineColor(); + const float height = controller->GetUnderlineHeight(); + + 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; break; } case EffectStyle::INPUT: @@ -165,22 +192,6 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value { const std::string properties = value.Get< std::string >(); - switch( type ) - { - case EffectStyle::DEFAULT: - { - // Stores the default shadow's properties string to be recovered by the GetShadowProperties() function. - controller->SetDefaultShadowProperties( properties ); - break; - } - case EffectStyle::INPUT: - { - // Stores the input shadow's properties string to be recovered by the GetShadowProperties() function. - controller->SetInputShadowProperties( properties ); - break; - } - } - // Parses and applies the style. Property::Map map; ParsePropertyString( properties, map ); @@ -208,7 +219,7 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value { const std::string offsetStr = offsetValue->Get(); - StringOffsetToVector2( offsetStr, offset ); + StringToVector2( offsetStr.c_str(), offsetStr.size(), offset ); } switch( type ) @@ -237,6 +248,28 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value } } } + else + { + switch( type ) + { + case EffectStyle::DEFAULT: + { + // Disable shadow. + if( Vector2::ZERO != controller->GetShadowOffset() ) + { + controller->SetShadowOffset( Vector2::ZERO ); + } + break; + } + case EffectStyle::INPUT: + { + // Sets the input shadow values. + // TODO: to be implemented. + controller->SetInputShadowProperties( properties ); + break; + } + } + } } return update; @@ -250,7 +283,20 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe { case EffectStyle::DEFAULT: { - value = controller->GetDefaultShadowProperties(); + const Vector4& color = controller->GetShadowColor(); + const Vector2& offset = controller->GetShadowOffset(); + + std::string shadowProperties = "{"; + + std::string colorStr; + Vector4ToColorString( color, colorStr ); + shadowProperties += "\"color\":\"" + colorStr + "\","; + + std::string offsetStr; + Vector2ToString( offset, offsetStr ); + shadowProperties += "\"offset\":\"" + offsetStr + "\"}"; + + value = shadowProperties; break; } case EffectStyle::INPUT: