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
#include <dali-toolkit/public-api/text/text-enumerations.h>
#include <toolkit-text-utils.h>
#include <dali-toolkit/devel-api/text/spans/character-spacing-span.h>
-
+#include <dali-toolkit/devel-api/text/spans/bold-span.h>
using namespace Dali;
using namespace Toolkit;
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<uint32_t> indicesToCheck,
Toolkit::Internal::TextLabel& labelImpl = GetImpl(textLabel);
const Vector<Dali::Toolkit::Text::CharacterSpacingGlyphRun> 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<Text::FontRun>& 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
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
--- /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 <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/text/spans/bold-span.h>
+
+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;
+}
${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
${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
--- /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/bold-span.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/spannable/spans/bold-span-impl.h>
+
+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<Dali::Toolkit::Text::Internal::BoldSpan*>(handle.GetObjectPtr()));
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#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 <dali-toolkit/devel-api/text/spans/base-span.h>
+
+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
${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
--- /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/bold-span-impl.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/font-description-run.h>
+
+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>& 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
--- /dev/null
+#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 <dali-toolkit/devel-api/text/spans/bold-span.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/spannable/spans/base-span-impl.h>
+#include <dali-toolkit/internal/text/logical-model-impl.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+namespace Internal
+{
+class BoldSpan;
+using BoldSpanPtr = IntrusivePtr<BoldSpan>;
+
+/**
+ * @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>& 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<Internal::BoldSpan&>(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<const Internal::BoldSpan&>(object);
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif //DALI_TOOLKIT_INTERNAL_TEXT_BOLDSPAN_IMPL_H
\ No newline at end of file