${toolkit_src_dir}/text/markup-processor-span.cpp
${toolkit_src_dir}/text/markup-processor-strikethrough.cpp
${toolkit_src_dir}/text/markup-processor-helper-functions.cpp
+ ${toolkit_src_dir}/text/markup-processor-attribute-helper-functions.cpp
${toolkit_src_dir}/text/multi-language-support.cpp
${toolkit_src_dir}/text/hidden-text.cpp
${toolkit_src_dir}/text/input-filter.cpp
--- /dev/null
+/*
+ * Copyright (c) 2015 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.
+ *
+ */
+
+// FILE HEADER
+#include <dali-toolkit/internal/text/markup-processor-attribute-helper-functions.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
+
+// EXTERNAL INCLUDES
+#include <memory.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+void CopyAttributeValueFromBuffer(const Attribute& attribute, const Length maxLengthAttributeValue, char* value)
+{
+ const Length length = attribute.valueLength > maxLengthAttributeValue ? maxLengthAttributeValue : attribute.valueLength;
+ memcpy(value, attribute.valueBuffer, length);
+ value[length] = 0;
+}
+
+float ProcessFloatAttribute(const Attribute& attribute)
+{
+ return StringToFloat(attribute.valueBuffer);
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_ATTRIBUTE_HELPER_FUNCTIONS_H
+#define DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_ATTRIBUTE_HELPER_FUNCTIONS_H
+
+/*
+ * Copyright (c) 2021 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/text-definitions.h>
+
+// EXTERNAL INCLUDES
+#include <functional>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+struct Attribute;
+
+/**
+ * @brief Copy the value from attribute buffer to value.
+ *
+ * @param[in] attribute the value of attribute.
+ * @param[in] maxLengthAttributeValue the maximum length of any of the possible value for attribute
+ * @param[out] value the value container.
+ *
+ */
+void CopyAttributeValueFromBuffer(const Attribute& attribute, const Length maxLengthAttributeValue, char* value);
+
+/**
+ * @brief Process the float attribute value from buffer.
+ *
+ * @param[in] attribute the float attribute.
+ *
+ * @return The float value.
+ */
+float ProcessFloatAttribute(const Attribute& attribute);
+
+/**
+ * @brief Process the Enumeration attribute value from buffer.
+ *
+ * @param[in] attribute the Enumeration attribute.
+ * @param[in] maxLengthAttributeValue the maximum length of any of the possible value for attribute
+ * @param[in] funcStringToEnum the function converts string value to enum value
+ * @param[out] enumValue the enum value
+ *
+ * @return True if the enum value was processed successfully
+ *
+ */
+template<typename T>
+bool ProcessEnumerationAttribute(const Attribute& attribute,
+ const Length maxLengthAttributeValue,
+ std::function<T(const char* const)> funcStringToEnum,
+ T& enumValue)
+{
+ char* value = new char[maxLengthAttributeValue + 1u];
+
+ CopyAttributeValueFromBuffer(attribute, maxLengthAttributeValue, value);
+
+ enumValue = funcStringToEnum(value); // @TODO: the functions that process Enum value should be refactored to return bool from Scripting::GetEnumeration
+
+ delete[] value;
+
+ return true;
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_ATTRIBUTE_HELPER_FUNCTIONS_H
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/font-description-run.h>
+#include <dali-toolkit/internal/text/markup-processor-attribute-helper-functions.h>
#include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
#include <dali-toolkit/internal/text/text-font-style.h>
void ProcessFontSize(const Attribute& attribute, FontDescriptionRun& fontRun)
{
// 64.f is used to convert from point size to 26.6 pixel format.
- fontRun.size = static_cast<PointSize26Dot6>(StringToFloat(attribute.valueBuffer) * PIXEL_FORMAT_64_FACTOR);
+ fontRun.size = static_cast<PointSize26Dot6>(ProcessFloatAttribute(attribute) * PIXEL_FORMAT_64_FACTOR);
fontRun.sizeDefined = true;
}
void ProcessFontWeight(const Attribute& attribute, FontDescriptionRun& fontRun)
{
- char value[MAX_FONT_ATTRIBUTE_SIZE + 1u];
- processFontAttributeValue(value, attribute);
-
- fontRun.weight = StringToWeight(value);
- fontRun.weightDefined = true;
+ fontRun.weightDefined = ProcessEnumerationAttribute<FontWeight>(attribute, MAX_FONT_ATTRIBUTE_SIZE, &StringToWeight, fontRun.weight);
}
void ProcessFontWidth(const Attribute& attribute, FontDescriptionRun& fontRun)
{
- char value[MAX_FONT_ATTRIBUTE_SIZE + 1u];
- processFontAttributeValue(value, attribute);
-
- fontRun.width = StringToWidth(value);
- fontRun.widthDefined = true;
+ fontRun.widthDefined = ProcessEnumerationAttribute<FontWidth>(attribute, MAX_FONT_ATTRIBUTE_SIZE, &StringToWidth, fontRun.width);
}
void ProcessFontSlant(const Attribute& attribute, FontDescriptionRun& fontRun)
{
- char value[MAX_FONT_ATTRIBUTE_SIZE + 1u];
- processFontAttributeValue(value, attribute);
-
- fontRun.slant = StringToSlant(value);
- fontRun.slantDefined = true;
+ fontRun.slantDefined = ProcessEnumerationAttribute<FontSlant>(attribute, MAX_FONT_ATTRIBUTE_SIZE, &StringToSlant, fontRun.slant);
}
void ProcessFontTag(const Tag& tag, FontDescriptionRun& fontRun)
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 unsigned int MAX_FLOAT_ATTRIBUTE_SIZE = 17u; ///< The maximum length of any of the possible float values. +99999.999999999f (sign, five digits, dot, nine digits, f)
+
const char WEB_COLOR_TOKEN('#');
const char* const HEX_COLOR_TOKEN("0x");
const char* const ALPHA_ONE("FF");
*/
void UnderlineTypeStringToTypeValue(const char* const typeStr, Length length, Text::Underline::Type& retType);
+/**
+ * @brief Converts a string into a float value.
+ *
+ * @param[in] floatStr A float packed inside a string.
+ *
+ * @return The float value.
+ */
+float StringToFloat(const char* const floatStr);
+
} // namespace Text
} // namespace Toolkit