From 4c54a774d68f8491f82de8ff1da99aff3c773ad2 Mon Sep 17 00:00:00 2001 From: abedalrhman rasem Date: Wed, 23 Nov 2022 15:25:44 +0300 Subject: [PATCH] Spannable: Add BoldSpan BoldSpan: Span to change the font weight of characters. Example: =========================================================================================== Dali::Toolkit::Text::SpannableString ss =Dali::Toolkit::Text::SpannableString::New("Testing"); auto boldspan =Dali::Toolkit::Text::BoldSpan::New(); ss.AttachSpan(boldspan,Dali::Toolkit::Text::Range::New(0u, 3u)); Dali::Toolkit::Text::SetSpannedText(textLabel,ss); =========================================================================================== Change-Id: I583648a7bb850ec36b3dd4ade3d84995113d192f --- .../utc-Dali-Text-TextSpannable.cpp | 45 ++++++++- automated-tests/src/dali-toolkit/CMakeLists.txt | 1 + .../src/dali-toolkit/utc-Dali-Text-BoldSpan.cpp | 49 +++++++++ dali-toolkit/devel-api/file.list | 2 + dali-toolkit/devel-api/text/spans/bold-span.cpp | 61 +++++++++++ dali-toolkit/devel-api/text/spans/bold-span.h | 111 +++++++++++++++++++++ dali-toolkit/internal/file.list | 1 + .../text/spannable/spans/bold-span-impl.cpp | 64 ++++++++++++ .../internal/text/spannable/spans/bold-span-impl.h | 111 +++++++++++++++++++++ 9 files changed, 444 insertions(+), 1 deletion(-) create mode 100644 automated-tests/src/dali-toolkit/utc-Dali-Text-BoldSpan.cpp create mode 100644 dali-toolkit/devel-api/text/spans/bold-span.cpp create mode 100644 dali-toolkit/devel-api/text/spans/bold-span.h create mode 100644 dali-toolkit/internal/text/spannable/spans/bold-span-impl.cpp create mode 100644 dali-toolkit/internal/text/spannable/spans/bold-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 8aec3c1..911e0d8 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 @@ -38,7 +38,7 @@ #include #include #include - +#include using namespace Dali; using namespace Toolkit; @@ -105,6 +105,19 @@ Text::SpannableString CreateSpannableStringForCharacterSpacing() return spannableString; } +Text::SpannableString CreateSpannableStringForBoldSpan() +{ + Text::SpannableString spannableString = Text::SpannableString::New("Hello"); + DALI_TEST_CHECK(spannableString); + + auto boldspan = Dali::Toolkit::Text::BoldSpan::New(); + auto isBoldSpan = spannableString.AttachSpan(boldspan,Dali::Toolkit::Text::Range::New(0u, 3u)); + DALI_TEST_CHECK(isBoldSpan); + + return spannableString; + +} + void CheckColorIndices(const Text::ColorIndex* const colorIndicesBuffer, uint32_t numberOfIndices, std::vector indicesToCheck, @@ -398,4 +411,34 @@ int UtcDaliToolkitTextLabelSetSpannedText_CharacterSpacingSpan(void) const Vector characterSpacing = labelImpl.GetTextController()->GetTextModel()->GetCharacterSpacingGlyphRuns(); DALI_TEST_EQUALS(1, characterSpacing.Count(), TEST_LOCATION); END_TEST; +} + +int UtcDaliToolkitTextLabelSetSpannedText_BoldSpan(void) +{ + ToolkitTestApplication application; + + tet_infoline("UtcDaliToolkitTextLabelSetSpannedText_BoldSpan"); + + TextLabel textLabel = TextLabel::New(); + + DALI_TEST_CHECK(textLabel); + + application.GetScene().Add(textLabel); + + Text::SpannableString spannableString = CreateSpannableStringForBoldSpan(); + Text::SetSpannedText(textLabel, spannableString); + + application.SendNotification(); + application.Render(); + + Toolkit::Internal::TextLabel& labelImpl = GetImpl(textLabel); + + const Vector& validFonts = labelImpl.GetTextController()->GetTextModel()->GetFontRuns(); + + DALI_TEST_EQUALS(validFonts.Count(), 2, TEST_LOCATION); + 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; } \ 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 4d94c20..dfd0ba3 100755 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -44,6 +44,7 @@ SET(TC_SOURCES utc-Dali-Text-ForegroundColorSpan.cpp utc-Dali-Text-CharacterSpacingSpan.cpp utc-Dali-Text-FontSpan.cpp + utc-Dali-Text-BoldSpan.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-BoldSpan.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Text-BoldSpan.cpp new file mode 100644 index 0000000..c82643f --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-Text-BoldSpan.cpp @@ -0,0 +1,49 @@ +/* + * 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 UtcDaliToolkitTextBoldSpanNew(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliToolkitTextBoldSpanNew"); + + auto boldSpan = Text::BoldSpan::New(); + + DALI_TEST_CHECK(boldSpan); + + END_TEST; +} + +int UtcDaliToolkitTextBoldSpanDownCast(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliToolkitTextBoldSpanDownCast"); + + Text::BaseSpan baseSpan = Text::BoldSpan::New(); + DALI_TEST_CHECK(baseSpan); + + Text::BoldSpan boldSpan = Text::BoldSpan::DownCast(baseSpan); + DALI_TEST_CHECK(boldSpan); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index f35aae5..e17bd14 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -71,6 +71,7 @@ SET( devel_api_src_files ${devel_api_src_dir}/text/spans/character-spacing-span.cpp ${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}/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 @@ -255,6 +256,7 @@ SET( devel_api_text_header_files ${devel_api_src_dir}/text/spans/character-spacing-span.h ${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 ) SET( devel_api_tool_bar_header_files diff --git a/dali-toolkit/devel-api/text/spans/bold-span.cpp b/dali-toolkit/devel-api/text/spans/bold-span.cpp new file mode 100644 index 0000000..74e9d2a --- /dev/null +++ b/dali-toolkit/devel-api/text/spans/bold-span.cpp @@ -0,0 +1,61 @@ +/* + * 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 +{ + +BoldSpan BoldSpan::New() +{ + return Internal::BoldSpan::New(); +} + +BoldSpan::BoldSpan() = default; + +BoldSpan::BoldSpan(const BoldSpan& rhs) = default; + +BoldSpan::BoldSpan(BoldSpan&& rhs) = default; + +BoldSpan& BoldSpan::operator=(const BoldSpan& rhs) = default; + +BoldSpan& BoldSpan::operator=(BoldSpan&& rhs) = default; + +BoldSpan::~BoldSpan() = default; + +BoldSpan::BoldSpan(Internal::BoldSpan* internal) +: BaseSpan(internal) +{ +} + +BoldSpan BoldSpan::DownCast(BaseHandle handle) +{ + return BoldSpan(dynamic_cast(handle.GetObjectPtr())); +} + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/text/spans/bold-span.h b/dali-toolkit/devel-api/text/spans/bold-span.h new file mode 100644 index 0000000..9520bb6 --- /dev/null +++ b/dali-toolkit/devel-api/text/spans/bold-span.h @@ -0,0 +1,111 @@ +#ifndef DALI_TOOLKIT_TEXT_BOLD_SPAN_H +#define DALI_TOOLKIT_TEXT_BOLD_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 + +namespace Dali +{ +namespace Toolkit +{ +namespace Text +{ +namespace Internal DALI_INTERNAL +{ +class BoldSpan; +} + +/** + * @brief BoldSpan is a handle to an object that specifies the Bold for range of characters. + */ +class DALI_TOOLKIT_API BoldSpan : public BaseSpan +{ +public: + /** + * @brief Create an initialized BoldSpan. + * + * @return A handle to newly allocated Dali resource. + */ + static BoldSpan New(); + + /** + * @brief Creates an uninitialized BoldSpan handle. + * + * Calling member functions with an uninitialized BoldSpan handle is not allowed. + */ + BoldSpan(); + + /** + * @brief Copy constructor. + * @param[in] rhs A refrence to the copied handle. + */ + BoldSpan(const BoldSpan& rhs); + + /** + * @brief Move constructor. + * + * @param[in] rhs A refrence to the move handle. + */ + BoldSpan(BoldSpan&& rhs); + + /** + * @brief Assignment operator. + * @param[in] rhs A reference to the copied handle. + * @return A refrence to this. + */ + BoldSpan& operator=(const BoldSpan& rhs); + + /** + * @brief Assignment operator. + * @param[in] rhs rhs A reference to the move handle. + * @return A refrence to this. + */ + BoldSpan& operator=(BoldSpan&& rhs); + + /** + * @brief Non virtual destructor. + * + */ + ~BoldSpan(); + + /** + * @brief Downcasts to a BoldSpan handle. + * If handle is not a BoldSpan, the returned handle is left uninitialized. + * + * @param[in] handle Handle to an object. + * @return BoldSpan handle or an uninitialized handle + */ + static BoldSpan DownCast(BaseHandle handle); + + // Not intended for application developers + /** + * @brief This constructor is used internally to create an initialized BoldSpan handle. + * @param[in] boldSpan Pointer to internal BoldSpan. + */ + explicit DALI_INTERNAL BoldSpan(Internal::BoldSpan* boldSpan); +}; + +}// namespace Text + +}// namespace Toolkit + +}// namespace Dali + +#endif // DALI_TOOLKIT_TEXT_BOLDSPAN_H diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index a3f162d..1f184e2 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -165,6 +165,7 @@ SET( toolkit_src_files ${toolkit_src_dir}/text/spannable/spans/character-spacing-span-impl.cpp ${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/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/bold-span-impl.cpp b/dali-toolkit/internal/text/spannable/spans/bold-span-impl.cpp new file mode 100644 index 0000000..3f205a7 --- /dev/null +++ b/dali-toolkit/internal/text/spannable/spans/bold-span-impl.cpp @@ -0,0 +1,64 @@ +/* + * 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 +{ +BoldSpan::BoldSpan() +: BaseSpan() +{ +} + +BoldSpan::~BoldSpan() +{ +} + +Dali::Toolkit::Text::BoldSpan BoldSpan::New() +{ + BoldSpanPtr object = new BoldSpan(); + Dali::Toolkit::Text::BoldSpan handle = Dali::Toolkit::Text::BoldSpan(object.Get()); + return handle; +} + +void BoldSpan::CreateStyleCharacterRun(IntrusivePtr& logicalModel, const Dali::Toolkit::Text::Range& range) const +{ + FontDescriptionRun fontRun; + fontRun.weight = TextAbstraction::FontWeight::BOLD; + fontRun.weightDefined = true; + fontRun.characterRun.characterIndex = range.GetStartIndex(); + fontRun.characterRun.numberOfCharacters = range.GetNumberOfIndices(); + logicalModel->mFontDescriptionRuns.PushBack(fontRun); +} + +} // namespace Internal + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/internal/text/spannable/spans/bold-span-impl.h b/dali-toolkit/internal/text/spannable/spans/bold-span-impl.h new file mode 100644 index 0000000..f3a356d --- /dev/null +++ b/dali-toolkit/internal/text/spannable/spans/bold-span-impl.h @@ -0,0 +1,111 @@ +#ifndef DALI_TOOLKIT_INTERNAL_TEXT_BOLDSPAN_IMPL_H +#define DALI_TOOLKIT_INTERNAL_TEXT_BOLDSPAN_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 + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Text +{ +namespace Internal +{ +class BoldSpan; +using BoldSpanPtr = IntrusivePtr; + +/** + * @copydoc Dali::Toolkit::Text::BoldSpan + */ +class BoldSpan : public BaseSpan +{ +public: + /** + * @brief Creates a new BoldSpan object. + * + * @return Dali::Toolkit::Text::BoldSpan + */ + static Dali::Toolkit::Text::BoldSpan New(); + + /** + * @brief Construct a new Bold Span object + * + */ + BoldSpan(); + + ///< Deleted copy constructor + BoldSpan(const BoldSpan& rhs) = delete; + + ///< Deleted move constructor + BoldSpan(BoldSpan&& rhs) = delete; + + ///< Deleted copy assignment operator + BoldSpan& operator=(const BoldSpan& rhs) = delete; + + ///< Deleted move assignment operator + BoldSpan& operator=(BoldSpan&& rhs) = delete; + + /** + * @brief Destructor + * A reference counted object may only be deleted by calling Unreference(). + */ + ~BoldSpan() override; + + /** + * @copydoc Dali::Toolkit::Text::BaseSpan::CreateStyleCharacterRun + */ + void CreateStyleCharacterRun(IntrusivePtr& logicalModel, const Dali::Toolkit::Text::Range& range) const override; + +}; // class BoldSpan + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Internal::BoldSpan& GetImplementation(Dali::Toolkit::Text::BoldSpan& boldSpan) +{ + DALI_ASSERT_ALWAYS(boldSpan && "boldSpan handle is empty"); + + BaseObject& object = boldSpan.GetBaseObject(); + + return static_cast(object); +} + +inline const Internal::BoldSpan& GetImplementation(const Dali::Toolkit::Text::BoldSpan& boldSpan) +{ + DALI_ASSERT_ALWAYS(boldSpan && "boldSpan handle is empty"); + + const BaseObject& object = boldSpan.GetBaseObject(); + + return static_cast(object); +} + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali + +#endif //DALI_TOOLKIT_INTERNAL_TEXT_BOLDSPAN_IMPL_H \ No newline at end of file -- 2.7.4