/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
// FILE HEADER
#include <dali-toolkit/internal/text/text-effects-style.h>
+// EXTERNAL INCLUDES
+#include <dali/public-api/math/math-utils.h>
+
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/controls/text-controls/text-style-properties-devel.h>
-#include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
+#include <dali-toolkit/internal/text/markup-processor/markup-processor-helper-functions.h>
#include <dali-toolkit/internal/text/property-string-parser.h>
+#include <dali-toolkit/internal/text/text-enumerations-impl.h>
namespace Dali
{
const std::string WIDTH_KEY("width");
const std::string HEIGHT_KEY("height");
const std::string ENABLE_KEY("enable");
+const std::string TYPE_KEY("type");
+const std::string DASH_WIDTH_KEY("dashWidth");
+const std::string DASH_GAP_KEY("dashGap");
const std::string TRUE_TOKEN("true");
const std::string FALSE_TOKEN("false");
} // namespace
return 0u == numberOfItems;
}
-bool ParseUnderlineProperties(const Property::Map& underlinePropertiesMap,
- bool& enabled,
- bool& colorDefined,
- Vector4& color,
- bool& heightDefined,
- float& height)
+bool ParseUnderlineProperties(const Property::Map& underlinePropertiesMap,
+ bool& enabled,
+ bool& colorDefined,
+ Vector4& color,
+ bool& heightDefined,
+ float& height,
+ bool& typeDefined,
+ Text::Underline::Type& type,
+ bool& dashWidthDefined,
+ float& dashWidth,
+ bool& dashGapDefined,
+ float& dashGap)
{
const unsigned int numberOfItems = underlinePropertiesMap.Count();
height = valueGet.second.Get<float>();
}
}
+ else if((DevelText::Underline::Property::TYPE == valueGet.first.indexKey) || (TYPE_KEY == valueGet.first.stringKey))
+ {
+ /// Underline Type key.
+ typeDefined = true;
+
+ if(valueGet.second.GetType() == Dali::Property::STRING)
+ {
+ const std::string typeStr = valueGet.second.Get<std::string>();
+ Text::UnderlineTypeStringToTypeValue(typeStr.c_str(), typeStr.size(), type);
+ }
+ else
+ {
+ type = valueGet.second.Get<Text::Underline::Type>();
+ }
+ }
+ else if((DevelText::Underline::Property::DASH_WIDTH == valueGet.first.indexKey) || (DASH_WIDTH_KEY == valueGet.first.stringKey))
+ {
+ /// Dashed Underline Width key.
+ dashWidthDefined = true;
+
+ if(valueGet.second.GetType() == Dali::Property::STRING)
+ {
+ const std::string dashWidthStr = valueGet.second.Get<std::string>();
+ dashWidth = StringToFloat(dashWidthStr.c_str());
+ }
+ else
+ {
+ dashWidth = valueGet.second.Get<float>();
+ }
+ }
+ else if((DevelText::Underline::Property::DASH_GAP == valueGet.first.indexKey) || (DASH_GAP_KEY == valueGet.first.stringKey))
+ {
+ /// Dashed Underline Gap key.
+ dashGapDefined = true;
+
+ if(valueGet.second.GetType() == Dali::Property::STRING)
+ {
+ const std::string dashGapStr = valueGet.second.Get<std::string>();
+ dashGap = StringToFloat(dashGapStr.c_str());
+ }
+ else
+ {
+ dashGap = valueGet.second.Get<float>();
+ }
+ }
}
return 0u == numberOfItems;
{
const Property::Map& propertiesMap = value.Get<Property::Map>();
- bool enabled = false;
- bool colorDefined = false;
- Vector4 color;
- bool heightDefined = false;
- float height = 0.f;
+ bool enabled = false;
+ bool colorDefined = false;
+ Vector4 color;
+ bool heightDefined = false;
+ float height = 0.f;
+ bool typeDefined = false;
+ Text::Underline::Type type;
+ bool dashWidthDefined = false;
+ float dashWidth = 2.0f;
+ bool dashGapDefined = false;
+ float dashGap = 1.0f;
bool empty = true;
colorDefined,
color,
heightDefined,
- height);
+ height,
+ typeDefined,
+ type,
+ dashWidthDefined,
+ dashWidth,
+ dashGapDefined,
+ dashGap);
controller->UnderlineSetByString(!empty);
}
colorDefined,
color,
heightDefined,
- height);
+ height,
+ typeDefined,
+ type,
+ dashWidthDefined,
+ dashWidth,
+ dashGapDefined,
+ dashGap);
controller->UnderlineSetByString(false);
}
controller->SetUnderlineHeight(height);
update = true;
}
+
+ if(typeDefined && (controller->GetUnderlineType() != type))
+ {
+ controller->SetUnderlineType(type);
+ update = true;
+ }
+
+ if(dashWidthDefined && (fabsf(controller->GetDashedUnderlineWidth() - dashWidth) > Math::MACHINE_EPSILON_1000))
+ {
+ controller->SetDashedUnderlineWidth(dashWidth);
+ update = true;
+ }
+
+ if(dashGapDefined && (fabsf(controller->GetDashedUnderlineGap() - dashGap) > Math::MACHINE_EPSILON_1000))
+ {
+ controller->SetDashedUnderlineGap(dashGap);
+ update = true;
+ }
}
else
{
{
case EffectStyle::DEFAULT:
{
- const bool enabled = controller->IsUnderlineEnabled();
- const Vector4& color = controller->GetUnderlineColor();
- const float height = controller->GetUnderlineHeight();
+ const bool enabled = controller->IsUnderlineEnabled();
+ const Vector4& color = controller->GetUnderlineColor();
+ const float height = controller->GetUnderlineHeight();
+ const Text::Underline::Type type = controller->GetUnderlineType();
+ const float dashWidth = controller->GetDashedUnderlineWidth();
+ const float dashGap = controller->GetDashedUnderlineGap();
if(controller->IsUnderlineSetByString())
{
std::string heightStr;
FloatToString(height, heightStr);
- underlineProperties += "\"height\":\"" + heightStr + "\"}";
+ underlineProperties += "\"height\":\"" + heightStr + "\",";
+
+ std::string typeStr;
+ typeStr = GetUnderlineTypeToString(type);
+ underlineProperties += "\"type\":\"" + typeStr + "\",";
+
+ std::string dashWidthStr;
+ FloatToString(dashWidth, dashWidthStr);
+ underlineProperties += "\"dashWidth\":\"" + dashWidthStr + "\",";
+
+ std::string dashGapStr;
+ FloatToString(dashGap, dashGapStr);
+ underlineProperties += "\"dashGap\":\"" + dashGapStr + "\"}";
value = underlineProperties;
}
map.Insert(ENABLE_KEY, enabled);
map.Insert(COLOR_KEY, color);
map.Insert(HEIGHT_KEY, height);
+ map.Insert(TYPE_KEY, type);
+ map.Insert(DASH_WIDTH_KEY, dashWidth);
+ map.Insert(DASH_GAP_KEY, dashGap);
value = map;
}
update = true;
}
- if(blurRadiusDefined && (controller->GetShadowBlurRadius() != blurRadius))
+ if(blurRadiusDefined && (!Dali::Equals(controller->GetShadowBlurRadius(), blurRadius)))
{
controller->SetShadowBlurRadius(blurRadius);
update = true;
Text::ParsePropertyString(propertyString, parsedStringMap);
empty = ParseStrikethroughProperties(parsedStringMap,
- enabled,
- colorDefined,
- color,
- heightDefined,
- height);
+ enabled,
+ colorDefined,
+ color,
+ heightDefined,
+ height);
controller->StrikethroughSetByString(!empty);
}
if(controller->IsStrikethroughSetByString())
{
std::string strikethroughProperties = "{\"enable\":";
- const std::string enabledStr = enabled ? "true" : "false";
+ const std::string enabledStr = enabled ? "true" : "false";
strikethroughProperties += "\"" + enabledStr + "\",";
std::string colorStr;
}
}
+Underline::Type StringToUnderlineType(const char* const underlineTypeStr)
+{
+ Underline::Type underlineType = Text::Underline::SOLID;
+ Scripting::GetEnumeration<Underline::Type>(underlineTypeStr,
+ UNDERLINE_TYPE_STRING_TABLE,
+ UNDERLINE_TYPE_STRING_TABLE_COUNT,
+ underlineType);
+
+ return underlineType;
+}
+
} // namespace Text
} // namespace Toolkit