Merge "Fix issue using broken image" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / spannable / spans / underline-span-impl.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/spannable/spans/underline-span-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/text/color-run.h>
23 #include <dali-toolkit/internal/text/markup-tags-and-attributes.h>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Text
30 {
31 namespace Internal
32 {
33 struct UnderlineSpan::Impl
34 {
35   UnderlineStyleProperties mUnderlineProperties; ///< The properties of underline style.
36 };
37
38 UnderlineSpan::UnderlineSpan()
39 : BaseSpan()
40 {
41   mImpl = std::make_unique<Impl>();
42 }
43
44 UnderlineSpan ::~UnderlineSpan()
45 {
46 }
47
48 Dali::Toolkit::Text::UnderlineSpan UnderlineSpan::New()
49 {
50   UnderlineSpanPtr object = new UnderlineSpan();
51
52   Dali::Toolkit::Text::UnderlineSpan handle = Dali::Toolkit::Text::UnderlineSpan(object.Get());
53
54   return handle;
55 }
56
57 Dali::Toolkit::Text::UnderlineSpan UnderlineSpan::NewSolid(Vector4 color, float height)
58 {
59   UnderlineSpanPtr object = new UnderlineSpan();
60   object->SetType(Text::Underline::SOLID);
61   object->SetColor(color);
62   object->SetHeight(height);
63
64   Dali::Toolkit::Text::UnderlineSpan handle = Dali::Toolkit::Text::UnderlineSpan(object.Get());
65
66   return handle;
67 }
68
69 Dali::Toolkit::Text::UnderlineSpan UnderlineSpan::NewDashed(Vector4 color, float height, float dashGap, float dashWidth)
70 {
71   UnderlineSpanPtr object = new UnderlineSpan();
72   object->SetType(Text::Underline::DASHED);
73   object->SetColor(color);
74   object->SetHeight(height);
75   object->SetDashGap(dashGap);
76   object->SetDashWidth(dashWidth);
77
78   Dali::Toolkit::Text::UnderlineSpan handle = Dali::Toolkit::Text::UnderlineSpan(object.Get());
79
80   return handle;
81 }
82
83 Dali::Toolkit::Text::UnderlineSpan UnderlineSpan::NewDouble(Vector4 color, float height)
84 {
85   UnderlineSpanPtr object = new UnderlineSpan();
86   object->SetType(Text::Underline::DOUBLE);
87   object->SetColor(color);
88   object->SetHeight(height);
89
90   Dali::Toolkit::Text::UnderlineSpan handle = Dali::Toolkit::Text::UnderlineSpan(object.Get());
91
92   return handle;
93 }
94
95 //Methods
96
97 const Text::Underline::Type UnderlineSpan::GetType() const
98 {
99   return mImpl->mUnderlineProperties.type;
100 }
101
102 bool UnderlineSpan::IsTypeDefined() const
103 {
104   return mImpl->mUnderlineProperties.typeDefined;
105 }
106
107 void UnderlineSpan::SetType(const Text::Underline::Type& type)
108 {
109   mImpl->mUnderlineProperties.type        = type;
110   mImpl->mUnderlineProperties.typeDefined = true;
111 }
112
113 const Vector4 UnderlineSpan::GetColor() const
114 {
115   return mImpl->mUnderlineProperties.color;
116 }
117
118 bool UnderlineSpan::IsColorDefined() const
119 {
120   return mImpl->mUnderlineProperties.colorDefined;
121 }
122
123 void UnderlineSpan::SetColor(const Vector4& color)
124 {
125   mImpl->mUnderlineProperties.color        = color;
126   mImpl->mUnderlineProperties.colorDefined = true;
127 }
128
129 const float UnderlineSpan::GetHeight() const
130 {
131   return mImpl->mUnderlineProperties.height;
132 }
133
134 bool UnderlineSpan::IsHeightDefined() const
135 {
136   return mImpl->mUnderlineProperties.heightDefined;
137 }
138
139 void UnderlineSpan::SetHeight(const float& height)
140 {
141   mImpl->mUnderlineProperties.height        = height;
142   mImpl->mUnderlineProperties.heightDefined = true;
143 }
144
145 const float UnderlineSpan::GetDashGap() const
146 {
147   return mImpl->mUnderlineProperties.dashGap;
148 }
149
150 bool UnderlineSpan::IsDashGapDefined() const
151 {
152   return mImpl->mUnderlineProperties.dashGapDefined;
153 }
154
155 void UnderlineSpan::SetDashGap(const float& dashGap)
156 {
157   mImpl->mUnderlineProperties.dashGap        = dashGap;
158   mImpl->mUnderlineProperties.dashGapDefined = true;
159 }
160
161 const float UnderlineSpan::GetDashWidth() const
162 {
163   return mImpl->mUnderlineProperties.dashWidth;
164 }
165
166 bool UnderlineSpan::IsDashWidthDefined() const
167 {
168   return mImpl->mUnderlineProperties.dashWidthDefined;
169 }
170
171 void UnderlineSpan::SetDashWidth(const float& dashWidth)
172 {
173   mImpl->mUnderlineProperties.dashWidth        = dashWidth;
174   mImpl->mUnderlineProperties.dashWidthDefined = true;
175 }
176
177 void UnderlineSpan::CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const
178 {
179   UnderlinedCharacterRun underlinedCharacterRun;
180   underlinedCharacterRun.characterRun.characterIndex     = range.GetStartIndex();
181   underlinedCharacterRun.characterRun.numberOfCharacters = range.GetNumberOfIndices();
182
183   underlinedCharacterRun.properties = mImpl->mUnderlineProperties;
184   logicalModel->mUnderlinedCharacterRuns.PushBack(underlinedCharacterRun);
185
186   logicalModel->mUnderlineRunsUpdated = true;
187 }
188
189 } // namespace Internal
190
191 } // namespace Text
192
193 } // namespace Toolkit
194
195 } // namespace Dali