1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "texgine_paint.h"
17
18 namespace OHOS {
19 namespace Rosen {
20 namespace TextEngine {
TexginePaint()21 TexginePaint::TexginePaint(): paint_(std::make_shared<SkPaint>())
22 {
23 }
24
GetPaint() const25 SkPaint TexginePaint::GetPaint() const
26 {
27 return *paint_.get();
28 }
29
SetPaint(const SkPaint & paint)30 void TexginePaint::SetPaint(const SkPaint &paint)
31 {
32 *paint_ = paint;
33 }
34
SetColor(const uint32_t color)35 void TexginePaint::SetColor(const uint32_t color)
36 {
37 paint_->setColor(color);
38 }
39
SetAlphaf(const float alpha)40 void TexginePaint::SetAlphaf(const float alpha)
41 {
42 paint_->setAlphaf(alpha);
43 }
44
SetStrokeWidth(const double width)45 void TexginePaint::SetStrokeWidth(const double width)
46 {
47 paint_->setStrokeWidth(width);
48 }
49
SetAntiAlias(const bool aa)50 void TexginePaint::SetAntiAlias(const bool aa)
51 {
52 paint_->setAntiAlias(aa);
53 }
54
SetARGB(const unsigned int a,const unsigned int r,const unsigned int g,const unsigned int b)55 void TexginePaint::SetARGB(const unsigned int a, const unsigned int r,
56 const unsigned int g, const unsigned int b)
57 {
58 paint_->setARGB(a, r, g, b);
59 }
60
SetStyle(Style style)61 void TexginePaint::SetStyle(Style style)
62 {
63 paint_->setStyle(static_cast<SkPaint::Style>(style));
64 }
65
SetPathEffect(const std::shared_ptr<TexginePathEffect> pathEffect)66 void TexginePaint::SetPathEffect(const std::shared_ptr<TexginePathEffect> pathEffect)
67 {
68 if (pathEffect == nullptr) {
69 return;
70 }
71
72 paint_->setPathEffect(pathEffect->GetPathEffect());
73 }
74
SetMaskFilter(const std::shared_ptr<TexgineMaskFilter> maskFilter)75 void TexginePaint::SetMaskFilter(const std::shared_ptr<TexgineMaskFilter> maskFilter)
76 {
77 if (maskFilter == nullptr) {
78 return;
79 }
80
81 paint_->setMaskFilter(maskFilter->GetMaskFilter());
82 }
83
SetAlpha(const unsigned int alpha)84 void TexginePaint::SetAlpha(const unsigned int alpha)
85 {
86 paint_->setAlpha(alpha);
87 }
88
SetBlendMode(TexgineBlendMode mode)89 void TexginePaint::SetBlendMode(TexgineBlendMode mode)
90 {
91 paint_->setBlendMode(static_cast<SkBlendMode>(mode));
92 }
93
operator ==(const TexginePaint & rhs) const94 bool TexginePaint::operator ==(const TexginePaint &rhs) const
95 {
96 return *paint_ == rhs.GetPaint();
97 }
98 } // namespace TextEngine
99 } // namespace Rosen
100 } // namespace OHOS
101