2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/spannable/spans/underline-span-impl.h>
22 #include <dali-toolkit/internal/text/color-run.h>
23 #include <dali-toolkit/internal/text/markup-tags-and-attributes.h>
33 struct UnderlineSpan::Impl
35 UnderlineStyleProperties mUnderlineProperties; ///< The properties of underline style.
38 UnderlineSpan::UnderlineSpan()
41 mImpl = std::make_unique<Impl>();
44 UnderlineSpan ::~UnderlineSpan()
48 Dali::Toolkit::Text::UnderlineSpan UnderlineSpan::New()
50 UnderlineSpanPtr object = new UnderlineSpan();
52 Dali::Toolkit::Text::UnderlineSpan handle = Dali::Toolkit::Text::UnderlineSpan(object.Get());
57 Dali::Toolkit::Text::UnderlineSpan UnderlineSpan::NewSolid(Vector4 color, float height)
59 UnderlineSpanPtr object = new UnderlineSpan();
60 object->SetType(Text::Underline::SOLID);
61 object->SetColor(color);
62 object->SetHeight(height);
64 Dali::Toolkit::Text::UnderlineSpan handle = Dali::Toolkit::Text::UnderlineSpan(object.Get());
69 Dali::Toolkit::Text::UnderlineSpan UnderlineSpan::NewDashed(Vector4 color, float height, float dashGap, float dashWidth)
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);
78 Dali::Toolkit::Text::UnderlineSpan handle = Dali::Toolkit::Text::UnderlineSpan(object.Get());
83 Dali::Toolkit::Text::UnderlineSpan UnderlineSpan::NewDouble(Vector4 color, float height)
85 UnderlineSpanPtr object = new UnderlineSpan();
86 object->SetType(Text::Underline::DOUBLE);
87 object->SetColor(color);
88 object->SetHeight(height);
90 Dali::Toolkit::Text::UnderlineSpan handle = Dali::Toolkit::Text::UnderlineSpan(object.Get());
97 const Text::Underline::Type UnderlineSpan::GetType() const
99 return mImpl->mUnderlineProperties.type;
102 bool UnderlineSpan::IsTypeDefined() const
104 return mImpl->mUnderlineProperties.typeDefined;
107 void UnderlineSpan::SetType(const Text::Underline::Type& type)
109 mImpl->mUnderlineProperties.type = type;
110 mImpl->mUnderlineProperties.typeDefined = true;
113 const Vector4 UnderlineSpan::GetColor() const
115 return mImpl->mUnderlineProperties.color;
118 bool UnderlineSpan::IsColorDefined() const
120 return mImpl->mUnderlineProperties.colorDefined;
123 void UnderlineSpan::SetColor(const Vector4& color)
125 mImpl->mUnderlineProperties.color = color;
126 mImpl->mUnderlineProperties.colorDefined = true;
129 const float UnderlineSpan::GetHeight() const
131 return mImpl->mUnderlineProperties.height;
134 bool UnderlineSpan::IsHeightDefined() const
136 return mImpl->mUnderlineProperties.heightDefined;
139 void UnderlineSpan::SetHeight(const float& height)
141 mImpl->mUnderlineProperties.height = height;
142 mImpl->mUnderlineProperties.heightDefined = true;
145 const float UnderlineSpan::GetDashGap() const
147 return mImpl->mUnderlineProperties.dashGap;
150 bool UnderlineSpan::IsDashGapDefined() const
152 return mImpl->mUnderlineProperties.dashGapDefined;
155 void UnderlineSpan::SetDashGap(const float& dashGap)
157 mImpl->mUnderlineProperties.dashGap = dashGap;
158 mImpl->mUnderlineProperties.dashGapDefined = true;
161 const float UnderlineSpan::GetDashWidth() const
163 return mImpl->mUnderlineProperties.dashWidth;
166 bool UnderlineSpan::IsDashWidthDefined() const
168 return mImpl->mUnderlineProperties.dashWidthDefined;
171 void UnderlineSpan::SetDashWidth(const float& dashWidth)
173 mImpl->mUnderlineProperties.dashWidth = dashWidth;
174 mImpl->mUnderlineProperties.dashWidthDefined = true;
177 void UnderlineSpan::CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const
179 UnderlinedCharacterRun underlinedCharacterRun;
180 underlinedCharacterRun.characterRun.characterIndex = range.GetStartIndex();
181 underlinedCharacterRun.characterRun.numberOfCharacters = range.GetNumberOfIndices();
183 underlinedCharacterRun.properties = mImpl->mUnderlineProperties;
184 logicalModel->mUnderlinedCharacterRuns.PushBack(underlinedCharacterRun);
186 logicalModel->mUnderlineRunsUpdated = true;
189 } // namespace Internal
193 } // namespace Toolkit