BackgroundSpan: Span to change the back groundSpan of characters.
Example:
===========================================================================================
Dali::Toolkit::Text::SpannableString ss =
Dali::Toolkit::Text::SpannableString::New("Testing");
auto greenSpan = Dali::Toolkit::Text::BackgroundColorSpan::New(Color::GREEN);
ss.AttachSpan(
greenSpan,
Dali::Toolkit::Text::Range::New(0u, 3u));
Dali::Toolkit::Text::SetSpannedText(textLabel,ss);
==========================================================================================
Change-Id: I3f5414ee5268799ad8e174db4b693c70f4b9b1b3
#include <dali-toolkit/devel-api/text/spans/character-spacing-span.h>
#include <dali-toolkit/devel-api/text/spans/bold-span.h>
#include <dali-toolkit/devel-api/text/spans/italic-span.h>
+#include <dali-toolkit/devel-api/text/spans/background-color-span.h>
using namespace Dali;
using namespace Toolkit;
return spannableString;
}
+Text::SpannableString CreateSpannableStringForBackgroundColorSpan()
+{
+
+ Text::SpannableString spannableString = Text::SpannableString::New("Hello مرحبا");
+
+ DALI_TEST_CHECK(spannableString);
+
+ auto isAddedGreen = spannableString.AttachSpan(
+ Text::BackgroundColorSpan::New(Color::GREEN),
+ Text::Range::New(5u, 7u));
+ DALI_TEST_CHECK(isAddedGreen);
+
+ return spannableString;
+}
+
void CheckColorIndices(const Text::ColorIndex* const colorIndicesBuffer,
uint32_t numberOfIndices,
std::vector<uint32_t> indicesToCheck,
DALI_TEST_EQUALS(validFonts[0].characterRun.characterIndex,0, TEST_LOCATION);
DALI_TEST_EQUALS(validFonts[0].characterRun.GetEndCharacterIndex(),3, TEST_LOCATION);
DALI_TEST_EQUALS(validFonts[0].isBoldRequired, true, TEST_LOCATION);
-
END_TEST;
}
DALI_TEST_EQUALS(validFontsItalic[0].characterRun.GetEndCharacterIndex(), 3, TEST_LOCATION);
DALI_TEST_EQUALS(validFontsItalic[0].isItalicRequired, true, TEST_LOCATION);
END_TEST;
-}
\ No newline at end of file
+}
+
+int UtcDaliToolkitTextLabelSetSpannedText_BackgroundColorSpan(void)
+{
+
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliToolkitTextLabelSetSpannedText_BackgroundColorSpan");
+
+ TextLabel textLabel = TextLabel::New();
+ DALI_TEST_CHECK(textLabel);
+
+ application.GetScene().Add(textLabel);
+
+ Text::SpannableString spannableString = CreateSpannableStringForBackgroundColorSpan();
+ Text::SetSpannedText(textLabel, spannableString);
+
+ application.SendNotification();
+ application.Render();
+
+ Toolkit::Internal::TextLabel& labelImpl = GetImpl(textLabel);
+ const Text::ColorIndex* const backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
+
+ CheckColorIndices(backgroundColorIndicesBuffer, 4u, {0u, 5u, 7u, 10u}, {0u, 1u, 1u, 0u});
+
+ END_TEST;
+}
+
utc-Dali-Text-FontSpan.cpp
utc-Dali-Text-BoldSpan.cpp
utc-Dali-Text-ItalicSpan.cpp
+ utc-Dali-Text-BackgroundColorSpan.cpp
utc-Dali-Text-Range.cpp
utc-Dali-Text-SpannableString.cpp
utc-Dali-Text-UnderlineSpan.cpp
--- /dev/null
+/*
+ * 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.
+ * 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 <stdlib.h>
+#include <unistd.h>
+#include <iostream>
+
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/text/spans/background-color-span.h>
+
+using namespace Dali;
+using namespace Toolkit;
+
+int UtcDaliToolkitTextBackgroundColorSpanNew(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliToolkitTextBackgroundColorSpanNew");
+
+ auto greenSpan = Text::BackgroundColorSpan::New(Color::GREEN);
+ DALI_TEST_CHECK(greenSpan);
+
+ END_TEST;
+}
+
+int UtcDaliToolkitTextGetBackgroundColor(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliToolkitTextGetBackgroundColor");
+
+ auto greenSpan = Text::BackgroundColorSpan::New(Color::GREEN);
+ DALI_TEST_CHECK(greenSpan);
+ DALI_TEST_EQUALS(Color::GREEN, greenSpan.GetBackgroundColor(), TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliToolkitTextIsBackgroundColorDefined(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliToolkitTextIsBackgroundColorDefined");
+
+ auto greenSpan = Text::BackgroundColorSpan::New(Color::GREEN);
+ DALI_TEST_CHECK(greenSpan);
+ DALI_TEST_EQUALS(true, greenSpan.IsBackgroundColorDefined(), TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliToolkitTextBackgroundColorSpanDownCast(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline("UtcDaliToolkitTextBackgroundColorSpanDownCast");
+
+ Text::BaseSpan baseSpan = Text::BackgroundColorSpan::New(Color::GREEN);
+ DALI_TEST_CHECK(baseSpan);
+
+ Text::BackgroundColorSpan greenSpan = Text::BackgroundColorSpan::DownCast(baseSpan);
+ DALI_TEST_CHECK(greenSpan);
+
+ END_TEST;
+}
${devel_api_src_dir}/text/spans/underline-span.cpp
${devel_api_src_dir}/text/spans/bold-span.cpp
${devel_api_src_dir}/text/spans/italic-span.cpp
+ ${devel_api_src_dir}/text/spans/background-color-span.cpp
${devel_api_src_dir}/transition-effects/cube-transition-cross-effect.cpp
${devel_api_src_dir}/transition-effects/cube-transition-effect.cpp
${devel_api_src_dir}/transition-effects/cube-transition-fold-effect.cpp
${devel_api_src_dir}/text/spans/underline-span.h
${devel_api_src_dir}/text/spans/bold-span.h
${devel_api_src_dir}/text/spans/italic-span.h
+ ${devel_api_src_dir}/text/spans/background-color-span.h
)
SET( devel_api_tool_bar_header_files
--- /dev/null
+/*
+ * 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.
+ * 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.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/text/spans/background-color-span.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/spannable/spans/background-color-span-impl.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+BackgroundColorSpan BackgroundColorSpan::New(const Vector4 &color)
+{
+ return Internal::BackgroundColorSpan::New(color);
+}
+
+BackgroundColorSpan::BackgroundColorSpan(Internal::BackgroundColorSpan* internal)
+: BaseSpan(internal)
+{
+}
+
+BackgroundColorSpan::BackgroundColorSpan() = default;
+
+BackgroundColorSpan::BackgroundColorSpan(const BackgroundColorSpan& rhs) = default;
+
+BackgroundColorSpan::BackgroundColorSpan(BackgroundColorSpan&& rhs) = default;
+
+BackgroundColorSpan& BackgroundColorSpan::operator=(const BackgroundColorSpan& rhs) = default;
+
+BackgroundColorSpan& BackgroundColorSpan::operator=(BackgroundColorSpan&& rhs) = default;
+
+BackgroundColorSpan::~BackgroundColorSpan() = default;
+
+//Methods
+const Vector4 BackgroundColorSpan::GetBackgroundColor() const
+{
+ return GetImplementation(*this).GetBackgroundColor();
+}
+
+bool BackgroundColorSpan::IsBackgroundColorDefined() const
+{
+ return GetImplementation(*this).IsBackgroundColorDefined();
+}
+
+BackgroundColorSpan BackgroundColorSpan::DownCast(BaseHandle handle)
+{
+ return BackgroundColorSpan(dynamic_cast<Dali::Toolkit::Text::Internal::BackgroundColorSpan*>(handle.GetObjectPtr()));
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_TOOLKIT_TEXT_BACKGROUND_COLOR_SPAN_H
+#define DALI_TOOLKIT_TEXT_BACKGROUND_COLOR_SPAN_H
+
+/*
+ * 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.
+ * 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/devel-api/text/spans/base-span.h>
+#include <dali/public-api/math/vector4.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+namespace Internal DALI_INTERNAL
+{
+class BackgroundColorSpan;
+}
+
+/**
+ * @brief BackgroundColorSpan is a handle to an object that specifies the background-color for range of characters.
+ */
+class DALI_TOOLKIT_API BackgroundColorSpan : public BaseSpan
+{
+public:
+ /**
+ * @brief Create an initialized BackgroundColorSpan.
+ *
+ * @param[in] color The background color.
+ *
+ * @return A handle to a newly allocated Dali resource
+ */
+ static BackgroundColorSpan New(const Vector4 &color);
+
+ /**
+ * @brief Creates an uninitialized BackgroundColorSpan handle.
+ *
+ * Calling member functions with an uninitialized BackgroundColorSpan handle is not allowed.
+ */
+ BackgroundColorSpan();
+
+ /**
+ * @brief Copy constructor.
+ * @param[in] rhs A reference to the copied handle
+ */
+ BackgroundColorSpan(const BackgroundColorSpan& rhs);
+
+ /**
+ * @brief Move constructor.
+ * @param[in] rhs A reference to the handle to move
+ */
+ BackgroundColorSpan(BackgroundColorSpan&& rhs);
+
+ /**
+ * @brief Assignment operator.
+ * @param[in] rhs A reference to the copied handle
+ * @return A reference to this
+ */
+ BackgroundColorSpan& operator=(const BackgroundColorSpan& rhs);
+
+ /**
+ * @brief Move assignment operator.
+ * @param[in] rhs A reference to the moved handle
+ * @return A reference to this
+ */
+ BackgroundColorSpan& operator=(BackgroundColorSpan&& rhs);
+
+ /**
+ * @brief Non virtual destructor.
+ */
+ ~BackgroundColorSpan();
+
+ /**
+ * @brief Downcasts to a BackgroundColorSpan handle.
+ * If handle is not a BackgroundColorSpan, the returned handle is left uninitialized.
+ *
+ * @param[in] handle Handle to an object
+ * @return BackgroundColorSpan handle or an uninitialized handle
+ */
+ static BackgroundColorSpan DownCast(BaseHandle handle);
+
+public: //Methods
+ /**
+ * @brief Retrive the background-color.
+ *
+ * @return A background-color value.
+ */
+ const Vector4 GetBackgroundColor() const;
+
+ /**
+ * @brief Retrieve whether the background-color is defined.
+ *
+ * @return The return is true if background-color is defined, otherwise false.
+ */
+ bool IsBackgroundColorDefined() const;
+
+public: // Not intended for application developers
+ /// @cond internal
+ /**
+ * @brief This constructor is used internally to Create an initialized BackgroundColorSpan handle.
+ *
+ * @param[in] colorSpan Pointer to internal BackgroundColorSpan
+ */
+ explicit DALI_INTERNAL BackgroundColorSpan(Internal::BackgroundColorSpan* colorSpan);
+ /// @endcond
+};
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_TEXT_BACKGROUND_COLOR_SPAN_H
${toolkit_src_dir}/text/spannable/spans/underline-span-impl.cpp
${toolkit_src_dir}/text/spannable/spans/bold-span-impl.cpp
${toolkit_src_dir}/text/spannable/spans/italic-span-impl.cpp
+ ${toolkit_src_dir}/text/spannable/spans/background-color-span-impl.cpp
${toolkit_src_dir}/text/spannable/span-ranges-container-impl.cpp
${toolkit_src_dir}/text/hyphenator.cpp
${toolkit_src_dir}/text/text-enumerations-impl.cpp
--- /dev/null
+/*
+ * 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.
+ * 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.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/text/spannable/spans/background-color-span-impl.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/color-run.h>
+#include <dali-toolkit/internal/text/markup-tags-and-attributes.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+namespace Internal
+{
+struct BackgroundColorSpan::Impl
+{
+ Vector4 mBackgroundColor; ///< The color of the characters.
+ bool mBackgroundColorDefined : 1; ///< Whether the background color is defined.
+};
+
+BackgroundColorSpan::BackgroundColorSpan()
+: BaseSpan()
+{
+ mImpl = std::make_unique<Impl>();
+}
+
+BackgroundColorSpan ::~BackgroundColorSpan()
+{
+}
+
+Dali::Toolkit::Text::BackgroundColorSpan BackgroundColorSpan::New(const Vector4 &color)
+{
+ BackgroundColorSpanPtr object = new BackgroundColorSpan();
+ object->SetBackgroundColor(color);
+ Dali::Toolkit::Text::BackgroundColorSpan handle = Dali::Toolkit::Text::BackgroundColorSpan(object.Get());
+
+ return handle;
+}
+
+//Methods
+const Vector4 BackgroundColorSpan::GetBackgroundColor() const
+{
+ return mImpl->mBackgroundColor;
+}
+
+bool BackgroundColorSpan::IsBackgroundColorDefined() const
+{
+ return mImpl->mBackgroundColorDefined;
+}
+
+void BackgroundColorSpan::SetBackgroundColor(const Vector4 &color)
+{
+ mImpl->mBackgroundColor = color;
+ mImpl->mBackgroundColorDefined = true;
+}
+
+void BackgroundColorSpan::CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const
+{
+ ColorRun backgroundColorRun;
+ backgroundColorRun.characterRun.characterIndex = range.GetStartIndex();
+ backgroundColorRun.characterRun.numberOfCharacters = range.GetNumberOfIndices();
+ backgroundColorRun.color = mImpl->mBackgroundColor;
+ logicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
+}
+
+} // namespace Internal
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_TOOLKIT_INTERNAL_TEXT_BACKGROUND_COLOR_SPAN_IMPL_H
+#define DALI_TOOLKIT_INTERNAL_TEXT_BACKGROUND_COLOR_SPAN_IMPL_H
+
+/*
+ * 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.
+ * 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.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali-toolkit/devel-api/text/spans/background-color-span.h>
+#include <memory>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/logical-model-impl.h>
+#include <dali-toolkit/internal/text/spannable/spans/base-span-impl.h>
+#include <dali/public-api/math/vector4.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+namespace Internal
+{
+class BackgroundColorSpan;
+using BackgroundColorSpanPtr = IntrusivePtr<BackgroundColorSpan>;
+
+/**
+ * @copydoc Dali::Toolkit::Text::BackgroundColorSpan
+ */
+class BackgroundColorSpan : public BaseSpan
+{
+public:
+ /**
+ * @brief Creates a new BackgroundColorSpan object.
+ */
+ static Dali::Toolkit::Text::BackgroundColorSpan New(const Vector4 &color);
+
+ /**
+ * Default Constructor
+ */
+ BackgroundColorSpan();
+
+ ///< Deleted copy constructor
+ BackgroundColorSpan(const BackgroundColorSpan&) = delete;
+
+ ///< Deleted move constructor
+ BackgroundColorSpan(BackgroundColorSpan&&) = delete;
+
+ ///< Deleted copy assignment operator
+ BackgroundColorSpan& operator=(const BackgroundColorSpan&) = delete;
+
+ ///< Deleted move assignment operator
+ BackgroundColorSpan& operator=(BackgroundColorSpan&&) = delete;
+
+ /**
+ * @brief Destructor
+ *
+ * A reference counted object may only be deleted by calling Unreference()
+ */
+ ~BackgroundColorSpan() override;
+
+public: //Methods
+ /**
+ * @copydoc Dali::Toolkit::Text::BackgroundColorSpan::GetBackgroundColor()
+ */
+ const Vector4 GetBackgroundColor() const;
+
+ /**
+ * @copydoc Dali::Toolkit::Text::BackgroundColorSpan::IsBackgroundColorDefined()
+ */
+ bool IsBackgroundColorDefined() const;
+
+public: //Methods. Not intended for application developers
+ /**
+ * @brief Set the background-color.
+ *
+ * @param[in] color The background-color.
+ */
+ void SetBackgroundColor(const Vector4 &color);
+
+public: //Methods for internal only
+ /**
+ * @copydoc Dali::Toolkit::Text::BaseSpan::CreateStyleCharacterRun
+ */
+ void CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const override;
+
+private:
+ struct Impl;
+ std::unique_ptr<Impl> mImpl{nullptr};
+
+}; // class BackgroundColorSpan
+
+} // namespace Internal
+
+// Helpers for public-api forwarding methods
+
+inline Internal::BackgroundColorSpan& GetImplementation(Dali::Toolkit::Text::BackgroundColorSpan& BackgroundColorSpan)
+{
+ DALI_ASSERT_ALWAYS(BackgroundColorSpan && "BackgroundColorSpan handle is empty");
+
+ BaseObject& object = BackgroundColorSpan.GetBaseObject();
+
+ return static_cast<Internal::BackgroundColorSpan&>(object);
+}
+
+inline const Internal::BackgroundColorSpan& GetImplementation(const Dali::Toolkit::Text::BackgroundColorSpan& BackgroundColorSpan)
+{
+ DALI_ASSERT_ALWAYS(BackgroundColorSpan && "BackgroundColorSpan handle is empty");
+
+ const BaseObject& object = BackgroundColorSpan.GetBaseObject();
+
+ return static_cast<const Internal::BackgroundColorSpan&>(object);
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_INTERNAL_TEXT_BACKGROUND_COLOR_SPAN_IMPL_H
\ No newline at end of file
const bool markupStrikethroughEnabled = markupOrSpannedText && mController->GetTextModel()->IsMarkupStrikethroughSet();
const bool underlineEnabled = mController->GetTextModel()->IsUnderlineEnabled() || markupUnderlineEnabled;
const bool strikethroughEnabled = mController->GetTextModel()->IsStrikethroughEnabled() || markupStrikethroughEnabled;
- const bool styleEnabled = (shadowEnabled || outlineEnabled || backgroundEnabled || markupOrSpannedText);
+ const bool backgroundMarkupSet = mController->GetTextModel()->IsMarkupBackgroundColorSet();
+ const bool styleEnabled = (shadowEnabled || outlineEnabled || backgroundEnabled || markupOrSpannedText || backgroundMarkupSet);
const bool isOverlayStyle = underlineEnabled || strikethroughEnabled;
AddRenderer(control, relayoutSize, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle);