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()
22     : style_(Style::FILL), brush_(std::make_shared<RSBrush>()), pen_(std::make_shared<RSPen>()) {}
23 
GetBrush() const24 RSBrush TexginePaint::GetBrush() const
25 {
26     return *brush_.get();
27 }
28 
GetPen() const29 RSPen TexginePaint::GetPen() const
30 {
31     return *pen_.get();
32 }
33 
GetStyle() const34 TexginePaint::Style TexginePaint::GetStyle() const
35 {
36     return style_;
37 }
38 
SetBrush(const RSBrush & brush)39 void TexginePaint::SetBrush(const RSBrush &brush)
40 {
41     *brush_ = brush;
42 }
43 
SetPen(const RSPen & pen)44 void TexginePaint::SetPen(const RSPen &pen)
45 {
46     *pen_ = pen;
47 }
48 
SetColor(const uint32_t color)49 void TexginePaint::SetColor(const uint32_t color)
50 {
51     brush_->SetColor(color);
52     pen_->SetColor(color);
53 }
54 
SetAlphaf(const float alpha)55 void TexginePaint::SetAlphaf(const float alpha)
56 {
57     brush_->SetAlphaF(alpha);
58     pen_->SetAlphaF(alpha);
59 }
60 
SetStrokeWidth(const double width)61 void TexginePaint::SetStrokeWidth(const double width)
62 {
63     pen_->SetWidth(width);
64 }
65 
SetAntiAlias(const bool aa)66 void TexginePaint::SetAntiAlias(const bool aa)
67 {
68     brush_->SetAntiAlias(aa);
69     pen_->SetAntiAlias(aa);
70 }
71 
SetARGB(const unsigned int a,const unsigned int r,const unsigned int g,const unsigned int b)72 void TexginePaint::SetARGB(const unsigned int a, const unsigned int r,
73     const unsigned int g, const unsigned int b)
74 {
75     brush_->SetARGB(a, r, g, b);
76     pen_->SetARGB(a, r, g, b);
77 }
78 
SetStyle(Style style)79 void TexginePaint::SetStyle(Style style)
80 {
81     style_ = style;
82 }
83 
SetPathEffect(const std::shared_ptr<TexginePathEffect> pathEffect)84 void TexginePaint::SetPathEffect(const std::shared_ptr<TexginePathEffect> pathEffect)
85 {
86     if (pathEffect == nullptr) {
87         return;
88     }
89     pen_->SetPathEffect(pathEffect->GetPathEffect());
90 }
91 
SetMaskFilter(const std::shared_ptr<TexgineMaskFilter> maskFilter)92 void TexginePaint::SetMaskFilter(const std::shared_ptr<TexgineMaskFilter> maskFilter)
93 {
94     if (maskFilter == nullptr) {
95         return;
96     }
97     RSFilter filter;
98     filter.SetMaskFilter(maskFilter->GetMaskFilter());
99     brush_->SetFilter(filter);
100     pen_->SetFilter(filter);
101 }
102 
SetAlpha(const unsigned int alpha)103 void TexginePaint::SetAlpha(const unsigned int alpha)
104 {
105     brush_->SetAlpha(alpha);
106     pen_->SetAlpha(alpha);
107 }
108 
SetBlendMode(TexgineBlendMode mode)109 void TexginePaint::SetBlendMode(TexgineBlendMode mode)
110 {
111     brush_->SetBlendMode(static_cast<Drawing::BlendMode>(mode));
112     pen_->SetBlendMode(static_cast<Drawing::BlendMode>(mode));
113 }
114 
operator ==(const TexginePaint & rhs) const115 bool TexginePaint::operator ==(const TexginePaint &rhs) const
116 {
117     return style_ == rhs.GetStyle() && *brush_ == rhs.GetBrush() && *pen_ == rhs.GetPen();
118 }
119 } // namespace TextEngine
120 } // namespace Rosen
121 } // namespace OHOS
122