From 4add9c5440ce9d639ec4ad7378285b1da2f31f04 Mon Sep 17 00:00:00 2001 From: abedalrhman rasem Date: Wed, 30 Nov 2022 10:04:32 +0300 Subject: [PATCH] Spannable: Add ItalicSpan ItalicSpan: Span to change the font slant of characters. Example: =========================================================================================== Dali::Toolkit::Text::SpannableString ss = Dali::Toolkit::Text::SpannableString::New("Testing italic span"); auto italicSpan =Dali::Toolkit::Text::ItalicSpan::New(); ss.AttachSpan(italicSpan,Dali::Toolkit::Text::Range::New(0u, 8u)); Dali::Toolkit::Text::SetSpannedText(textLabel,ss); ========================================================================================== Change-Id: I9832203ed07433be292ca2dc66d82899ced288ce --- .../utc-Dali-Text-TextSpannable.cpp | 40 ++++++++ automated-tests/src/dali-toolkit/CMakeLists.txt | 1 + .../src/dali-toolkit/utc-Dali-Text-ItalicSpan.cpp | 48 +++++++++ dali-toolkit/devel-api/file.list | 2 + dali-toolkit/devel-api/text/spans/italic-span.cpp | 62 ++++++++++++ dali-toolkit/devel-api/text/spans/italic-span.h | 111 ++++++++++++++++++++ dali-toolkit/internal/file.list | 1 + .../text/spannable/spans/italic-span-impl.cpp | 62 ++++++++++++ .../text/spannable/spans/italic-span-impl.h | 112 +++++++++++++++++++++ 9 files changed, 439 insertions(+) create mode 100644 automated-tests/src/dali-toolkit/utc-Dali-Text-ItalicSpan.cpp create mode 100644 dali-toolkit/devel-api/text/spans/italic-span.cpp create mode 100644 dali-toolkit/devel-api/text/spans/italic-span.h create mode 100644 dali-toolkit/internal/text/spannable/spans/italic-span-impl.cpp create mode 100644 dali-toolkit/internal/text/spannable/spans/italic-span-impl.h diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-TextSpannable.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-TextSpannable.cpp index 911e0d8..fdfde16 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-TextSpannable.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-TextSpannable.cpp @@ -39,6 +39,7 @@ #include #include #include +#include using namespace Dali; using namespace Toolkit; @@ -118,6 +119,19 @@ Text::SpannableString CreateSpannableStringForBoldSpan() } +Text::SpannableString CreateSpannableStringForItalicSpan() +{ + Text::SpannableString spannableString = Text::SpannableString::New("Hello"); + DALI_TEST_CHECK(spannableString); + + auto isAddedItalic = spannableString.AttachSpan( + Text::ItalicSpan::New(), + Text::Range::New(0u, 3u)); + DALI_TEST_CHECK(isAddedItalic); + + return spannableString; +} + void CheckColorIndices(const Text::ColorIndex* const colorIndicesBuffer, uint32_t numberOfIndices, std::vector indicesToCheck, @@ -441,4 +455,30 @@ int UtcDaliToolkitTextLabelSetSpannedText_BoldSpan(void) DALI_TEST_EQUALS(validFonts[0].isBoldRequired, true, TEST_LOCATION); END_TEST; +} + +int UtcDaliToolkitTextLabelSetSpannedText_ItalicSpan(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliToolkitTextLabelSetSpannedText_ItalicSpan"); + + TextLabel textLabel = TextLabel::New(); + DALI_TEST_CHECK(textLabel); + + application.GetScene().Add(textLabel); + + Text::SpannableString spannableString = CreateSpannableStringForItalicSpan(); + + Text::SetSpannedText(textLabel, spannableString); + application.SendNotification(); + application.Render(); + + Toolkit::Internal::TextLabel& labelImpl = GetImpl(textLabel); + const Vector& validFontsItalic = labelImpl.GetTextController()->GetTextModel()->GetFontRuns(); + + DALI_TEST_EQUALS(validFontsItalic.Count(), 2, TEST_LOCATION); + DALI_TEST_EQUALS(validFontsItalic[0].characterRun.characterIndex, 0, TEST_LOCATION); + 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 diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index dfd0ba3..1fd489a 100755 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -45,6 +45,7 @@ SET(TC_SOURCES utc-Dali-Text-CharacterSpacingSpan.cpp utc-Dali-Text-FontSpan.cpp utc-Dali-Text-BoldSpan.cpp + utc-Dali-Text-ItalicSpan.cpp utc-Dali-Text-Range.cpp utc-Dali-Text-SpannableString.cpp utc-Dali-Text-UnderlineSpan.cpp diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Text-ItalicSpan.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Text-ItalicSpan.cpp new file mode 100644 index 0000000..91511f1 --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-Text-ItalicSpan.cpp @@ -0,0 +1,48 @@ +/* + * 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 +#include +#include + +using namespace Dali; +using namespace Toolkit; + +int UtcDaliToolkitTextItalicSpanNew(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliToolkitTextItalicSpanNew"); + + auto italicSpan = Text::ItalicSpan::New(); + DALI_TEST_CHECK(italicSpan); + + END_TEST; +} + +int UtcDaliToolkitTextItalicSpanDownCast(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliToolkitTextItalicSpanDownCast"); + + Text::BaseSpan baseSpan = Text::ItalicSpan::New(); + + DALI_TEST_CHECK(baseSpan); + Text::ItalicSpan italicSpan = Text::ItalicSpan::DownCast(baseSpan); + + DALI_TEST_CHECK(italicSpan); + END_TEST; +} \ No newline at end of file diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index e17bd14..b7d6919 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -72,6 +72,7 @@ SET( devel_api_src_files ${devel_api_src_dir}/text/spans/font-span.cpp ${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}/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 @@ -257,6 +258,7 @@ SET( devel_api_text_header_files ${devel_api_src_dir}/text/spans/font-span.h ${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 ) SET( devel_api_tool_bar_header_files diff --git a/dali-toolkit/devel-api/text/spans/italic-span.cpp b/dali-toolkit/devel-api/text/spans/italic-span.cpp new file mode 100644 index 0000000..5685684 --- /dev/null +++ b/dali-toolkit/devel-api/text/spans/italic-span.cpp @@ -0,0 +1,62 @@ +/* + * 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 + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Text +{ +ItalicSpan ItalicSpan::New() +{ + return Internal::ItalicSpan::New(); +} + +ItalicSpan::ItalicSpan() = default; + +ItalicSpan::ItalicSpan(const ItalicSpan& rhs) = default; + +ItalicSpan::ItalicSpan(ItalicSpan&& rhs) = default; + +ItalicSpan& ItalicSpan::operator=(const ItalicSpan& rhs) = default; + +ItalicSpan& ItalicSpan::operator=(ItalicSpan&& rhs) = default; + +ItalicSpan::~ItalicSpan() = default; + + +ItalicSpan ItalicSpan::DownCast(BaseHandle handle) +{ + return ItalicSpan(dynamic_cast(handle.GetObjectPtr())); +} + +ItalicSpan::ItalicSpan(Internal::ItalicSpan* internal) +: BaseSpan(internal) +{ +} + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/text/spans/italic-span.h b/dali-toolkit/devel-api/text/spans/italic-span.h new file mode 100644 index 0000000..010eb4e --- /dev/null +++ b/dali-toolkit/devel-api/text/spans/italic-span.h @@ -0,0 +1,111 @@ +#ifndef DALI_TOOLKIT_TEXT_ITALICSPAN_H +#define DALI_TOOLKIT_TEXT_ITALICSPAN_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 + +namespace Dali +{ +namespace Toolkit +{ +namespace Text +{ +namespace Internal DALI_INTERNAL +{ +class ItalicSpan; +} + +/** + * @brief ItalicSpan is a handle to an object that specifies the Italic font for range of characters. + */ +class DALI_TOOLKIT_API ItalicSpan : public BaseSpan +{ +public: + /** + * @brief Create an Initialized ItalicSpan. + * + * @return A handle to a newly allocated Dali resource. + */ + static ItalicSpan New(); + + /** + * @brief Creates an uninitialized ItalicSpan handle. + * + * Calling member functions with an uninitialized ItalicSpan handle is not allowed. + */ + ItalicSpan(); + + /** + * @brief Copy constructor. + * @param[in] rhs A reference to the copied handle. + */ + ItalicSpan(const ItalicSpan& rhs); + + /** + * @brief Move constructor. + * @param rhs A reference to the handle to move. + */ + ItalicSpan(ItalicSpan&& rhs); + + /** + * @brief Assignment operator. + * @param[in] rhs A reference to the copied handle + * @return A reference to this + */ + ItalicSpan& operator=(const ItalicSpan& rhs); + + /** + * @brief Move assignment operator. + * @param[in] rhs A reference to the moved handle. + * @return A reference to this. + */ + ItalicSpan& operator=(ItalicSpan&& rhs); + + /** + * @brief Non virtual destructor. + */ + ~ItalicSpan(); + + /** + * @brief Downcasts to a ItalicSpan handle. + * If handle is not a ItalicSpan, the returned handle is left uninitialized. + * + * @param[in] handle Handle to an object. + * @return ItalicSpan handle or an uninitialized handle. + */ + static ItalicSpan DownCast(BaseHandle handle); + + // Not intended for application developers. + /** + * @brief This constructor is used internally to Create an initialized ItalicSpan handle. + * + * @param[in] italicSpan Pointer to internal ItalicSpan. + */ + explicit DALI_INTERNAL ItalicSpan(Internal::ItalicSpan* italicSpan); + +}; + +}// namespace Text + +} // namespace Toolkit + +} // namespace Dali + +#endif //DALI_TOOLKIT_TEXT_ITALICSPAN_H \ No newline at end of file diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index 1f184e2..7018aa1 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -166,6 +166,7 @@ SET( toolkit_src_files ${toolkit_src_dir}/text/spannable/spans/font-span-impl.cpp ${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/span-ranges-container-impl.cpp ${toolkit_src_dir}/text/hyphenator.cpp ${toolkit_src_dir}/text/text-enumerations-impl.cpp diff --git a/dali-toolkit/internal/text/spannable/spans/italic-span-impl.cpp b/dali-toolkit/internal/text/spannable/spans/italic-span-impl.cpp new file mode 100644 index 0000000..4f6ce4b --- /dev/null +++ b/dali-toolkit/internal/text/spannable/spans/italic-span-impl.cpp @@ -0,0 +1,62 @@ +/* + * 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 + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Text +{ +namespace Internal +{ +ItalicSpan::ItalicSpan():BaseSpan() +{ +} + +ItalicSpan::~ItalicSpan() +{ +} + +Dali::Toolkit::Text::ItalicSpan ItalicSpan::New() +{ + ItalicSpanPtr object = new ItalicSpan(); + Dali::Toolkit::Text::ItalicSpan handle = Dali::Toolkit::Text::ItalicSpan(object.Get()); + return handle; +} +void ItalicSpan::CreateStyleCharacterRun(IntrusivePtr& logicalModel, const Dali::Toolkit::Text::Range& range) const +{ + FontDescriptionRun fontRun; + fontRun.slant = TextAbstraction::FontSlant::ITALIC; + fontRun.slantDefined = true; + fontRun.characterRun.characterIndex = range.GetStartIndex(); + fontRun.characterRun.numberOfCharacters = range.GetNumberOfIndices(); + logicalModel->mFontDescriptionRuns.PushBack(fontRun); +} + +} // namespace Internal + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali \ No newline at end of file diff --git a/dali-toolkit/internal/text/spannable/spans/italic-span-impl.h b/dali-toolkit/internal/text/spannable/spans/italic-span-impl.h new file mode 100644 index 0000000..5279038 --- /dev/null +++ b/dali-toolkit/internal/text/spannable/spans/italic-span-impl.h @@ -0,0 +1,112 @@ +#ifndef DALI_TOOLKIT_INTERNAL_TEXT_ITALIC_SPAN_IMPL_H +#define DALI_TOOLKIT_INTERNAL_TEXT_ITALIC_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 +#include + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Text +{ +namespace Internal +{ +class ItalicSpan; +using ItalicSpanPtr = IntrusivePtr; + +/** + * @copydoc Dali::Toolkit::Text::ItalicSpan + */ +class ItalicSpan : public BaseSpan +{ +public: + /** + * @brief Creates a new ItalicSpan object. + */ + static Dali::Toolkit::Text::ItalicSpan New(); + + /** + * Default Constructor + */ + ItalicSpan(); + + ///< Deleted copy constructor + ItalicSpan(const ItalicSpan&) = delete; + + ///< Deleted move constructor + ItalicSpan(ItalicSpan&&) = delete; + + ///< Deleted copy assignment operator + ItalicSpan& operator=(const ItalicSpan&) = delete; + + ///< Deleted move assignment operator + ItalicSpan& operator=(ItalicSpan&&) = delete; + + /** + * @brief Destructor. + * + * A reference counted object may only be deleted by calling Unreference(). + */ + ~ItalicSpan() override; + + //Methods for internal only + /** + * @copydoc Dali::Toolkit::Text::BaseSpan::CreateStyleCharacterRun + */ + void CreateStyleCharacterRun(IntrusivePtr& logicalModel, const Dali::Toolkit::Text::Range& range) const override; + +}; // class ItalicSpan + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Internal::ItalicSpan& GetImplementation(Dali::Toolkit::Text::ItalicSpan& italicSpan) +{ + DALI_ASSERT_ALWAYS(italicSpan && "italicSpan handle is empty"); + + BaseObject& object = italicSpan.GetBaseObject(); + + return static_cast(object); +} + +inline const Internal::ItalicSpan& GetImplementation(const Dali::Toolkit::Text::ItalicSpan& italicSpan) +{ + DALI_ASSERT_ALWAYS(italicSpan && "italicSpan handle is empty"); + + const BaseObject& object = italicSpan.GetBaseObject(); + + return static_cast(object); +} + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali + + +#endif // DALI_TOOLKIT_INTERNAL_TEXT_ITALIC_SPAN_IMPL_H \ No newline at end of file -- 2.7.4