Add GetSpanType API 55/286155/2
authorssabah <s.sabah@samsung.com>
Wed, 28 Dec 2022 20:33:19 +0000 (23:33 +0300)
committershrouq Sabah <s.sabah@samsung.com>
Wed, 11 Jan 2023 09:04:37 +0000 (09:04 +0000)
Add GetSpanType and SpanType enum
This API help casting from BaseSpan to one of sub classes

Change-Id: I75399a5dfba6d74148951fdd14b57889b86c738f

15 files changed:
automated-tests/src/dali-toolkit/utc-Dali-Text-BaseSpan.cpp
dali-toolkit/devel-api/file.list
dali-toolkit/devel-api/text/spans/base-span.cpp
dali-toolkit/devel-api/text/spans/base-span.h
dali-toolkit/devel-api/text/spans/span-enumerations.h [new file with mode: 0644]
dali-toolkit/internal/text/spannable/spans/background-color-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/base-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/base-span-impl.h
dali-toolkit/internal/text/spannable/spans/bold-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/character-spacing-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/font-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/foreground-color-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/italic-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/strikethrough-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/underline-span-impl.cpp

index d7d1e15602327bf2afef4bcd63fb63f6e2a13b41..f15754669a69d62cf9ae177f0b693e4cecc050fb 100644 (file)
 
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/text/spans/background-color-span.h>
+#include <dali-toolkit/devel-api/text/spans/bold-span.h>
+#include <dali-toolkit/devel-api/text/spans/character-spacing-span.h>
+#include <dali-toolkit/devel-api/text/spans/font-span.h>
 #include <dali-toolkit/devel-api/text/spans/foreground-color-span.h>
+#include <dali-toolkit/devel-api/text/spans/italic-span.h>
+#include <dali-toolkit/devel-api/text/spans/strikethrough-span.h>
+#include <dali-toolkit/devel-api/text/spans/underline-span.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -39,3 +46,47 @@ int UtcDaliToolkitTextBaseSpanDownCast(void)
 
   END_TEST;
 }
+
+int UtcDaliToolkitTextBaseSpanGetSpanType(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextBaseSpanGetSpanType");
+
+  Text::BaseSpan foregroundColorSpan = Text::ForegroundColorSpan::New(Color::GREEN);
+  DALI_TEST_CHECK(foregroundColorSpan);
+  DALI_TEST_EQUALS(foregroundColorSpan.GetSpanType(), Dali::Toolkit::Text::SpanType::Value::FOREGROUND_COLOR, TEST_LOCATION);
+
+  Text::BaseSpan backgroundColorSpan = Text::BackgroundColorSpan::New(Color::GREEN);
+  DALI_TEST_CHECK(backgroundColorSpan);
+  DALI_TEST_EQUALS(backgroundColorSpan.GetSpanType(), Dali::Toolkit::Text::SpanType::Value::BACKGROUND_COLOR, TEST_LOCATION);
+
+  Text::BaseSpan fontSpan = Text::FontSpan::New("TizenSans",
+                                                45.0f,
+                                                Dali::TextAbstraction::FontWeight::BOLD,
+                                                Dali::TextAbstraction::FontWidth::SEMI_CONDENSED,
+                                                Dali::TextAbstraction::FontSlant::OBLIQUE);
+  DALI_TEST_CHECK(fontSpan);
+  DALI_TEST_EQUALS(fontSpan.GetSpanType(), Dali::Toolkit::Text::SpanType::Value::FONT, TEST_LOCATION);
+
+  Text::BaseSpan boldSpan = Dali::Toolkit::Text::BoldSpan::New();
+  DALI_TEST_CHECK(boldSpan);
+  DALI_TEST_EQUALS(boldSpan.GetSpanType(), Dali::Toolkit::Text::SpanType::Value::BOLD, TEST_LOCATION);
+
+  Text::BaseSpan italicSpan = Text::ItalicSpan::New();
+  DALI_TEST_CHECK(italicSpan);
+  DALI_TEST_EQUALS(italicSpan.GetSpanType(), Dali::Toolkit::Text::SpanType::Value::ITALIC, TEST_LOCATION);
+
+  Text::BaseSpan underlineSpan = Text::UnderlineSpan::NewDashed(Color::GREEN, 5.0f, 2.0f, 3.0f);
+  DALI_TEST_CHECK(underlineSpan);
+  DALI_TEST_EQUALS(underlineSpan.GetSpanType(), Dali::Toolkit::Text::SpanType::Value::UNDERLINE, TEST_LOCATION);
+
+  Text::BaseSpan strikethroughSpan = Text::StrikethroughSpan::New(Color::GREEN, 5.0f);
+  DALI_TEST_CHECK(strikethroughSpan);
+  DALI_TEST_EQUALS(strikethroughSpan.GetSpanType(), Dali::Toolkit::Text::SpanType::Value::STRIKETHROUGH, TEST_LOCATION);
+
+  Text::BaseSpan characterSpacingSpan = Text::CharacterSpacingSpan::New(5.2f);
+  DALI_TEST_CHECK(characterSpacingSpan);
+  DALI_TEST_EQUALS(characterSpacingSpan.GetSpanType(), Dali::Toolkit::Text::SpanType::Value::CHARACTER_SPACING, TEST_LOCATION);
+
+  END_TEST;
+}
index 248ab7f015027ec7509b44df750096796daa02b7..43d805bf202b0d8e3a2079f3ba5c666b6bc3c60b 100755 (executable)
@@ -263,6 +263,7 @@ SET( devel_api_text_header_files
   ${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
+  ${devel_api_src_dir}/text/spans/span-enumerations.h
 )
 
 SET( devel_api_tool_bar_header_files
index 6afcfd7920bf14317ad3257a8a1ada784139bac1..47b09a17a6b2beb9ba0e3fe594d7e4d44907fd9d 100644 (file)
@@ -49,6 +49,11 @@ BaseSpan BaseSpan::DownCast(BaseHandle handle)
   return BaseSpan(dynamic_cast<Dali::Toolkit::Text::Internal::BaseSpan*>(handle.GetObjectPtr()));
 }
 
+const Dali::Toolkit::Text::SpanType::Value BaseSpan::GetSpanType() const
+{
+  return GetImplementation(*this).GetSpanType();
+}
+
 } // namespace Text
 
 } // namespace Toolkit
index 535870cbc8b9b17f599aa3d9140da223560a3f9d..87578206588e7b7d1207aac0de19b4eb0b244037 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali-toolkit/devel-api/text/spans/span-enumerations.h>
 #include <dali-toolkit/public-api/dali-toolkit-common.h>
 #include <dali/public-api/object/base-handle.h>
 
@@ -90,6 +91,13 @@ public:
    */
   ~BaseSpan();
 
+  /**
+   * @brief Retrive the span type.
+   *
+   * @return A span type value.
+   */
+  const Dali::Toolkit::Text::SpanType::Value GetSpanType() const;
+
   /**
    * @brief Downcasts to a BaseSpan handle.
    * If handle is not a BaseSpan, the returned handle is left uninitialized.
diff --git a/dali-toolkit/devel-api/text/spans/span-enumerations.h b/dali-toolkit/devel-api/text/spans/span-enumerations.h
new file mode 100644 (file)
index 0000000..37a2bca
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef DALI_SPAN_ENUMERATIONS_H
+#define DALI_SPAN_ENUMERATIONS_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 <cstdint>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+namespace SpanType
+{
+/**
+ * @brief Enumeration for type of the span.
+ */
+enum class Value : uint8_t
+{
+  BASE = 0,
+  FOREGROUND_COLOR,
+  BACKGROUND_COLOR,
+  FONT,
+  BOLD,
+  ITALIC,
+  UNDERLINE,
+  STRIKETHROUGH,
+  CHARACTER_SPACING
+
+};
+} // namespace SpanType
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_SPAN_ENUMERATIONS_H
index 555759ac6fb6ba67373ce9b475d3d4f6a2ff3af1..1bdf94f390f81f5a0d563ecd9f53eb89d0ac1cf2 100644 (file)
@@ -37,7 +37,7 @@ struct BackgroundColorSpan::Impl
 };
 
 BackgroundColorSpan::BackgroundColorSpan()
-: BaseSpan()
+: BaseSpan(Dali::Toolkit::Text::SpanType::Value::BACKGROUND_COLOR)
 {
   mImpl = std::make_unique<Impl>();
 }
index 5f6498ef6622f1b7c8dc96bed9f44d38918ecf8e..5c1897db05258811109a15c74f70b48212a2cc00 100644 (file)
@@ -26,14 +26,26 @@ namespace Text
 {
 namespace Internal
 {
-BaseSpan::BaseSpan()
+struct BaseSpan::Impl
 {
+  Dali::Toolkit::Text::SpanType::Value mSpanTypeValue; ///< The span type value.
+};
+
+BaseSpan::BaseSpan(Dali::Toolkit::Text::SpanType::Value spanType)
+{
+  mImpl                 = std::make_unique<Impl>();
+  mImpl->mSpanTypeValue = spanType;
 }
 
 BaseSpan::~BaseSpan()
 {
 }
 
+const Dali::Toolkit::Text::SpanType::Value BaseSpan::GetSpanType() const
+{
+  return mImpl->mSpanTypeValue;
+}
+
 } // namespace Internal
 
 } // namespace Text
index a10902e08867f4d3dd32e4aabac3133c70714c4c..8317e0a0d3ac89693ed7732fd14f9d877b9a9946 100644 (file)
@@ -58,7 +58,7 @@ protected:
   /**
    * @brief Default Constructor
    */
-  BaseSpan();
+  BaseSpan(Dali::Toolkit::Text::SpanType::Value spanType);
 
   /**
    * @brief Virtual destructor.
@@ -67,6 +67,13 @@ protected:
    */
   virtual ~BaseSpan();
 
+public:
+  /**
+   * @copydoc Dali::Toolkit::Text::SpanType::Value GetSpanType
+   */
+
+  const Dali::Toolkit::Text::SpanType::Value GetSpanType() const;
+
 public: //Methods for internal only
   /**
    * @brief Create an instance for specific style character run and add it to its logicalModel run.
@@ -76,6 +83,10 @@ public: //Methods for internal only
    */
   virtual void CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const = 0;
 
+private:
+  struct Impl;
+  std::unique_ptr<Impl> mImpl{nullptr};
+
 }; // class BaseSpan
 
 } // namespace Internal
index 3f205a712c4839cdef6effc81aea676b22aecf21..0f054f7f095287e99036c15c14c1dd2d87a777a5 100644 (file)
@@ -30,7 +30,7 @@ namespace Text
 namespace Internal
 {
 BoldSpan::BoldSpan()
-: BaseSpan()
+: BaseSpan(Dali::Toolkit::Text::SpanType::Value::BOLD)
 {
 }
 
index 89ea379eae2aec63c978cbd8ccd9fe832771f3e6..484b4b42db70ac8d6751b064a93948e5da2336eb 100644 (file)
@@ -37,7 +37,7 @@ struct CharacterSpacingSpan::Impl
 };
 
 CharacterSpacingSpan::CharacterSpacingSpan()
-: BaseSpan()
+: BaseSpan(Dali::Toolkit::Text::SpanType::Value::CHARACTER_SPACING)
 {
   mImpl = std::make_unique<Impl>();
 }
index f22d88ab93e7b46cd82149bddb7b91c4572bf1a9..4a7811ff5bae38253ac57c236e733233f1dd4a38 100644 (file)
@@ -56,7 +56,7 @@ struct FontSpan::Impl
 };
 
 FontSpan::FontSpan()
-: BaseSpan()
+: BaseSpan(Dali::Toolkit::Text::SpanType::Value::FONT)
 {
   mImpl = std::make_unique<Impl>();
 }
index 515ba89180ca7a8f4ee092c93c03f4842941adc6..fa00d45de1b50200392540716bc313b376b98073 100644 (file)
@@ -37,7 +37,7 @@ struct ForegroundColorSpan::Impl
 };
 
 ForegroundColorSpan::ForegroundColorSpan()
-: BaseSpan()
+: BaseSpan(Dali::Toolkit::Text::SpanType::Value::FOREGROUND_COLOR)
 {
   mImpl = std::make_unique<Impl>();
 }
index 4f6ce4bedd279c0fa3c225bd684cad6a6e210abd..64d9eeefd95e9dda985dfff19f2fb0a758ece0fa 100644 (file)
@@ -29,7 +29,8 @@ namespace Text
 {
 namespace Internal
 {
-ItalicSpan::ItalicSpan():BaseSpan()
+ItalicSpan::ItalicSpan()
+: BaseSpan(Dali::Toolkit::Text::SpanType::Value::ITALIC)
 {
 }
 
index fae9a460a82520a9ec19c1ddead9243c9cff6230..c589cf2ce8960e775a047c2aa46230fb62b64504 100644 (file)
@@ -36,7 +36,7 @@ struct StrikethroughSpan::Impl
 };
 
 StrikethroughSpan::StrikethroughSpan()
-: BaseSpan()
+: BaseSpan(Dali::Toolkit::Text::SpanType::Value::STRIKETHROUGH)
 {
   mImpl = std::make_unique<Impl>();
 }
index 32d219fd1194bdb5f463bfb62af2a22dd6128c13..9124e02673426bf3d18fc73f89abc4bcb1e5d779 100644 (file)
@@ -36,7 +36,7 @@ struct UnderlineSpan::Impl
 };
 
 UnderlineSpan::UnderlineSpan()
-: BaseSpan()
+: BaseSpan(Dali::Toolkit::Text::SpanType::Value::UNDERLINE)
 {
   mImpl = std::make_unique<Impl>();
 }