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/background-color-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 BackgroundColorSpan::Impl
35 Vector4 mBackgroundColor; ///< The color of the characters.
36 bool mBackgroundColorDefined : 1; ///< Whether the background color is defined.
39 BackgroundColorSpan::BackgroundColorSpan()
42 mImpl = std::make_unique<Impl>();
45 BackgroundColorSpan ::~BackgroundColorSpan()
49 Dali::Toolkit::Text::BackgroundColorSpan BackgroundColorSpan::New(const Vector4 &color)
51 BackgroundColorSpanPtr object = new BackgroundColorSpan();
52 object->SetBackgroundColor(color);
53 Dali::Toolkit::Text::BackgroundColorSpan handle = Dali::Toolkit::Text::BackgroundColorSpan(object.Get());
59 const Vector4 BackgroundColorSpan::GetBackgroundColor() const
61 return mImpl->mBackgroundColor;
64 bool BackgroundColorSpan::IsBackgroundColorDefined() const
66 return mImpl->mBackgroundColorDefined;
69 void BackgroundColorSpan::SetBackgroundColor(const Vector4 &color)
71 mImpl->mBackgroundColor = color;
72 mImpl->mBackgroundColorDefined = true;
75 void BackgroundColorSpan::CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const
77 ColorRun backgroundColorRun;
78 backgroundColorRun.characterRun.characterIndex = range.GetStartIndex();
79 backgroundColorRun.characterRun.numberOfCharacters = range.GetNumberOfIndices();
80 backgroundColorRun.color = mImpl->mBackgroundColor;
81 logicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
84 } // namespace Internal
88 } // namespace Toolkit