Spannable: Add BackgroundSpan
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / spannable / spans / font-span-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FONT_SPAN_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FONT_SPAN_IMPL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/devel-api/text/spans/font-span.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/logical-model-impl.h>
26 #include <dali-toolkit/internal/text/spannable/spans/base-span-impl.h>
27 #include <dali-toolkit/internal/text/text-definitions.h>
28 #include <dali/public-api/math/vector4.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Text
35 {
36 namespace Internal
37 {
38 class FontSpan;
39 using FontSpanPtr = IntrusivePtr<FontSpan>;
40
41 /**
42  * @copydoc Dali::Toolkit::Text::FontSpan
43  */
44 class FontSpan : public BaseSpan
45 {
46 public:
47   /**
48    * @brief Creates a new FontSpan object.
49    */
50   static Dali::Toolkit::Text::FontSpan New(const std::string&                             familyName,
51                                            const float&                                   sizeInPoints,
52                                            const Dali::TextAbstraction::FontWeight::Type& weight,
53                                            const Dali::TextAbstraction::FontWidth::Type&  width,
54                                            const Dali::TextAbstraction::FontSlant::Type&  slant);
55
56   /**
57    * Default Constructor
58    */
59   FontSpan();
60
61   FontSpan(const FontSpan&) = delete;            ///< Deleted copy constructor
62   FontSpan(FontSpan&&)      = delete;            ///< Deleted move constructor
63   FontSpan& operator=(const FontSpan&) = delete; ///< Deleted copy assignment operator
64   FontSpan& operator=(FontSpan&&) = delete;      ///< Deleted move assignment operator
65
66   /**
67    * @brief Destructor
68    *
69    * A reference counted object may only be deleted by calling Unreference()
70    */
71   ~FontSpan() override;
72
73 public: //Methods
74 public: //Methods
75   /**
76    * @copydoc Dali::Toolkit::Text::FontSpan::GetFamilyName()
77    */
78   const std::string GetFamilyName() const;
79
80   /**
81    * @copydoc Dali::Toolkit::Text::FontSpan::IsFamilyNameDefined()
82    */
83   bool IsFamilyNameDefined() const;
84
85   /**
86    * @copydoc Dali::Toolkit::Text::FontSpan::GetWeight()
87    */
88   const Dali::TextAbstraction::FontWeight::Type GetWeight() const;
89
90   /**
91    * @copydoc Dali::Toolkit::Text::FontSpan::IsWeightDefined()
92    */
93   bool IsWeightDefined() const;
94
95   /**
96    * @copydoc Dali::Toolkit::Text::FontSpan::GetWidth()
97    */
98   const Dali::TextAbstraction::FontWidth::Type GetWidth() const;
99
100   /**
101    * @copydoc Dali::Toolkit::Text::FontSpan::IsWidthDefined()
102    */
103   bool IsWidthDefined() const;
104
105   /**
106    * @copydoc Dali::Toolkit::Text::FontSpan::GetSlant()
107    */
108   const Dali::TextAbstraction::FontSlant::Type GetSlant() const;
109
110   /**
111    * @copydoc Dali::Toolkit::Text::FontSpan::IsSlantDefined()
112    */
113   bool IsSlantDefined() const;
114
115   /**
116    * @copydoc Dali::Toolkit::Text::FontSpan::GetSize()
117    */
118   const float GetSize() const;
119
120   /**
121    * @copydoc Dali::Toolkit::Text::FontSpan::IsSizeDefined()
122    */
123   bool IsSizeDefined() const;
124
125 public: //Methods. Not intended for application developers
126   /**
127    * @brief Set the font family name.
128    *
129    * @param[in] familyName The font family name.
130    */
131   void SetFamilyName(const std::string& familyName);
132
133   /**
134    * @brief Set the font weight.
135    *
136    * @param[in] weight The font weight.
137    */
138   void SetWeight(const Dali::TextAbstraction::FontWeight::Type& weight);
139
140   /**
141    * @brief Set the font width.
142    *
143    * @param[in] width The font width.
144    */
145   void SetWidth(const Dali::TextAbstraction::FontWidth::Type& width);
146
147   /**
148    * @brief Set the font slant.
149    *
150    * @param[in] slant The font slant.
151    */
152   void SetSlant(const Dali::TextAbstraction::FontSlant::Type& slant);
153
154   /**
155    * @brief Set the font size.
156    *
157    * @param[in] size The font size.
158    */
159   void SetSize(const float& size);
160
161 private: //Methods
162   void InitializeFontRun(FontDescriptionRun& fontRun) const;
163   void ProcessFontFamily(FontDescriptionRun& fontRun) const;
164   void ProcessFontSize(FontDescriptionRun& fontRun) const;
165   void ProcessFontWeight(FontDescriptionRun& fontRun) const;
166   void ProcessFontWidth(FontDescriptionRun& fontRun) const;
167   void ProcessFontSlant(FontDescriptionRun& fontRun) const;
168
169 public: //Methods for internal only
170         /**
171    * @copydoc Dali::Toolkit::Text::BaseSpan::CreateStyleCharacterRun
172    */
173   void CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const override;
174
175 private:
176   struct Impl;
177   std::unique_ptr<Impl> mImpl{nullptr};
178
179 }; // class FontSpan
180
181 } // namespace Internal
182
183 // Helpers for public-api forwarding methods
184
185 inline Internal::FontSpan& GetImplementation(Dali::Toolkit::Text::FontSpan& fontSpan)
186 {
187   DALI_ASSERT_ALWAYS(fontSpan && "fontSpan handle is empty");
188
189   BaseObject& object = fontSpan.GetBaseObject();
190
191   return static_cast<Internal::FontSpan&>(object);
192 }
193
194 inline const Internal::FontSpan& GetImplementation(const Dali::Toolkit::Text::FontSpan& fontSpan)
195 {
196   DALI_ASSERT_ALWAYS(fontSpan && "fontSpan handle is empty");
197
198   const BaseObject& object = fontSpan.GetBaseObject();
199
200   return static_cast<const Internal::FontSpan&>(object);
201 }
202
203 } // namespace Text
204
205 } // namespace Toolkit
206
207 } // namespace Dali
208
209 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FONT_SPAN_IMPL_H