This needs to be done to pass the UTC in the TextVisual patch currently in developement.
Change-Id: I517fba6b78115d9bf77ea0998c54e500475102a6
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
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)
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;
+}
--- /dev/null
+/*
+ * 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 <iostream>
+
+#include <stdlib.h>
+#include <limits>
+
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <toolkit-text-model.h>
+#include <dali-toolkit/internal/text/markup-processor.h>
+#include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
+#include <dali-toolkit/internal/text/color-run.h>
+#include <dali-toolkit/internal/text/font-description-run.h>
+#include <dali-toolkit/internal/text/text-definitions.h>
+#include <dali-toolkit/internal/text/text-io.h>
+
+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;
+}
DALI_TEST_EQUALS( editor.GetProperty<float>( 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<std::string>( 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<std::string>( 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<std::string>( 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<std::string>( TextEditor::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
+ editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" );
+ DALI_TEST_EQUALS( editor.GetProperty<std::string>( 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" );
DALI_TEST_EQUALS( field.GetProperty<std::string>( 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<std::string>( 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<std::string>( 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<std::string>( 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<std::string>( TextField::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
+ field.SetProperty( TextField::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" );
+ DALI_TEST_EQUALS( field.GetProperty<std::string>( 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" );
// The underline color is changed as well.
DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::UNDERLINE_COLOR ), Color::BLUE, TEST_LOCATION );
+ DALI_TEST_EQUALS( label.GetProperty<std::string>( 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<Vector2>( TextLabel::Property::SHADOW_OFFSET ), Vector2( 3.0f, 3.0f ), TEST_LOCATION );
DALI_TEST_EQUALS( label.GetProperty<float>( 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<std::string>( 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<std::string>( TextLabel::Property::UNDERLINE ), std::string("{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}"), TEST_LOCATION );
+
+ label.SetProperty( TextLabel::Property::UNDERLINE, "" );
+ DALI_TEST_EQUALS( label.GetProperty<std::string>( 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<std::string>( TextLabel::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
+ label.SetProperty( TextLabel::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" );
+ DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"2 2\"}"), TEST_LOCATION );
+
+ label.SetProperty( TextLabel::Property::SHADOW, "" );
+ DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"0 0\"}"), TEST_LOCATION );
// Check the emboss property
label.SetProperty( TextLabel::Property::EMBOSS, "Emboss properties" );
// EXTERNAL INCLUDES
#include <dali/public-api/common/constants.h>
+#include <dali/public-api/math/vector2.h>
#include <stdlib.h>
+#include <sstream>
+#include <iomanip>
namespace Dali
{
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" );
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;
}
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 )
return static_cast<float>( 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<float>( ( color & 0xFF000000 ) >> 24u ) / 255.f;
}
}
+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<unsigned int>( 255.f * value.a );
+ const unsigned int red = static_cast<unsigned int>( 255.f * value.r );
+ const unsigned int green = static_cast<unsigned int>( 255.f * value.g );
+ const unsigned int blue = static_cast<unsigned int>( 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
namespace Dali
{
+struct Vector2;
struct Vector4;
namespace Toolkit
/**
* @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.
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.
* @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.
*/
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
}
}
-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
*/
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
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 );
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 )
return mImpl->mEventData->mInputStyle.shadowProperties;
}
- return GetDefaultShadowProperties();
+ return EMPTY_STRING;
}
void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
return mImpl->mEventData->mInputStyle.underlineProperties;
}
- return GetDefaultUnderlineProperties();
+ return EMPTY_STRING;
}
void Controller::SetInputEmbossProperties( const std::string& embossProperties )
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.
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.
{
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 )
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<std::string>();
// Parses and applies the style.
Property::Map map;
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<std::string>();
+ enabled = TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() );
+ }
+
+ /// Color key.
Property::Value* colorValue = map.Find( COLOR_KEY );
Vector4 color;
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<std::string>();
+ const std::string heightStr = heightValue->Get<std::string>();
- 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.
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;
}
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;
+ }
}
}
}
{
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:
{
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 );
{
const std::string offsetStr = offsetValue->Get<std::string>();
- StringOffsetToVector2( offsetStr, offset );
+ StringToVector2( offsetStr.c_str(), offsetStr.size(), offset );
}
switch( type )
}
}
}
+ 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;
{
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: