1 /*
2 * Copyright (c) 2021 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 "draw/pen.h"
17
18 #include "impl_interface/path_effect_impl.h"
19
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
Pen()23 Pen::Pen() noexcept
24 : width_(0),
25 miterLimit_(-1),
26 join_(Pen::JoinStyle::MITER_JOIN),
27 cap_(Pen::CapStyle::FLAT_CAP),
28 pathEffect_(nullptr),
29 brush_()
30 {}
31
Pen(const Color & c)32 Pen::Pen(const Color& c) noexcept : Pen()
33 {
34 brush_.SetColor(c);
35 }
36
Pen(int rgba)37 Pen::Pen(int rgba) noexcept : Pen()
38 {
39 brush_.SetColor(rgba);
40 }
41
GetColor() const42 Color Pen::GetColor() const
43 {
44 return brush_.GetColor();
45 }
46
SetColor(const Color & c)47 void Pen::SetColor(const Color& c)
48 {
49 brush_.SetColor(c);
50 }
51
SetColor(int c)52 void Pen::SetColor(int c)
53 {
54 brush_.SetColor(c);
55 }
56
SetARGB(int r,int g,int b,int a)57 void Pen::SetARGB(int r, int g, int b, int a)
58 {
59 return brush_.SetARGB(r, g, b, a);
60 }
61
GetColor4f()62 Color4f Pen::GetColor4f()
63 {
64 return brush_.GetColor4f();
65 }
66
GetColorSpace() const67 std::shared_ptr<ColorSpace> Pen::GetColorSpace() const
68 {
69 return brush_.GetColorSpace();
70 }
71
SetColor(const Color4f & cf,std::shared_ptr<ColorSpace> s)72 void Pen::SetColor(const Color4f& cf, std::shared_ptr<ColorSpace> s)
73 {
74 brush_.SetColor(cf, s);
75 }
76
GetAlpha() const77 uint32_t Pen::GetAlpha() const
78 {
79 return brush_.GetAlpha();
80 }
81
SetAlpha(uint32_t a)82 void Pen::SetAlpha(uint32_t a)
83 {
84 return brush_.SetAlpha(a);
85 }
86
SetAlphaF(scalar a)87 void Pen::SetAlphaF(scalar a)
88 {
89 return brush_.SetAlphaF(a);
90 }
91
GetWidth() const92 scalar Pen::GetWidth() const
93 {
94 return width_;
95 }
96
SetWidth(scalar width)97 void Pen::SetWidth(scalar width)
98 {
99 width_ = width;
100 }
101
GetMiterLimit() const102 scalar Pen::GetMiterLimit() const
103 {
104 return miterLimit_;
105 }
106
SetMiterLimit(scalar limit)107 void Pen::SetMiterLimit(scalar limit)
108 {
109 miterLimit_ = limit;
110 }
111
GetCapStyle() const112 Pen::CapStyle Pen::GetCapStyle() const
113 {
114 return cap_;
115 }
116
SetCapStyle(CapStyle cs)117 void Pen::SetCapStyle(CapStyle cs)
118 {
119 cap_ = cs;
120 }
121
GetJoinStyle() const122 Pen::JoinStyle Pen::GetJoinStyle() const
123 {
124 return join_;
125 }
126
SetJoinStyle(JoinStyle js)127 void Pen::SetJoinStyle(JoinStyle js)
128 {
129 join_ = js;
130 }
131
GetBlendMode() const132 BlendMode Pen::GetBlendMode() const
133 {
134 return brush_.GetBlendMode();
135 }
136
SetBlendMode(BlendMode mode)137 void Pen::SetBlendMode(BlendMode mode)
138 {
139 return brush_.SetBlendMode(mode);
140 }
141
IsAntiAlias() const142 bool Pen::IsAntiAlias() const
143 {
144 return brush_.IsAntiAlias();
145 }
146
SetAntiAlias(bool aa)147 void Pen::SetAntiAlias(bool aa)
148 {
149 brush_.SetAntiAlias(aa);
150 }
151
SetPathEffect(std::shared_ptr<PathEffect> e)152 void Pen::SetPathEffect(std::shared_ptr<PathEffect> e)
153 {
154 pathEffect_ = e;
155 }
156
GetPathEffect() const157 std::shared_ptr<PathEffect> Pen::GetPathEffect() const
158 {
159 return pathEffect_;
160 }
161
SetFilter(const Filter & filter)162 void Pen::SetFilter(const Filter& filter)
163 {
164 brush_.SetFilter(filter);
165 }
166
GetFilter() const167 Filter Pen::GetFilter() const
168 {
169 return brush_.GetFilter();
170 }
171
SetShaderEffect(std::shared_ptr<ShaderEffect> e)172 void Pen::SetShaderEffect(std::shared_ptr<ShaderEffect> e)
173 {
174 brush_.SetShaderEffect(e);
175 }
176
GetShaderEffect() const177 std::shared_ptr<ShaderEffect> Pen::GetShaderEffect() const
178 {
179 return brush_.GetShaderEffect();
180 }
181
Reset()182 void Pen::Reset()
183 {
184 *this = Pen();
185 }
186
operator ==(const Pen & p1,const Pen & p2)187 bool operator==(const Pen& p1, const Pen& p2)
188 {
189 return p1.width_ == p2.width_ && p1.miterLimit_ == p2.miterLimit_ && p1.join_ == p2.join_ && p1.cap_ == p2.cap_ &&
190 p1.pathEffect_ == p2.pathEffect_ && p1.brush_ == p2.brush_;
191 }
192
operator !=(const Pen & p1,const Pen & p2)193 bool operator!=(const Pen& p1, const Pen& p2)
194 {
195 return p1.width_ != p2.width_ || p1.miterLimit_ != p2.miterLimit_ || p1.join_ != p2.join_ || p1.cap_ != p2.cap_ ||
196 p1.pathEffect_ != p2.pathEffect_ || p1.brush_ != p2.brush_;
197 }
198 } // namespace Drawing
199 } // namespace Rosen
200 } // namespace OHOS
201