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 a,int r,int g,int b)57 void Pen::SetARGB(int a, int r, int g, int b)
58 {
59 return brush_.SetARGB(a, r, g, b);
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
GetAlphaF() const82 scalar Pen::GetAlphaF() const
83 {
84 return brush_.GetAlphaF();
85 }
86
SetAlpha(uint32_t a)87 void Pen::SetAlpha(uint32_t a)
88 {
89 return brush_.SetAlpha(a);
90 }
91
SetAlphaF(scalar a)92 void Pen::SetAlphaF(scalar a)
93 {
94 return brush_.SetAlphaF(a);
95 }
96
GetWidth() const97 scalar Pen::GetWidth() const
98 {
99 return width_;
100 }
101
SetWidth(scalar width)102 void Pen::SetWidth(scalar width)
103 {
104 width_ = width;
105 }
106
GetMiterLimit() const107 scalar Pen::GetMiterLimit() const
108 {
109 return miterLimit_;
110 }
111
SetMiterLimit(scalar limit)112 void Pen::SetMiterLimit(scalar limit)
113 {
114 miterLimit_ = limit;
115 }
116
GetCapStyle() const117 Pen::CapStyle Pen::GetCapStyle() const
118 {
119 return cap_;
120 }
121
SetCapStyle(CapStyle cs)122 void Pen::SetCapStyle(CapStyle cs)
123 {
124 cap_ = cs;
125 }
126
GetJoinStyle() const127 Pen::JoinStyle Pen::GetJoinStyle() const
128 {
129 return join_;
130 }
131
SetJoinStyle(JoinStyle js)132 void Pen::SetJoinStyle(JoinStyle js)
133 {
134 join_ = js;
135 }
136
GetBlendMode() const137 BlendMode Pen::GetBlendMode() const
138 {
139 return brush_.GetBlendMode();
140 }
141
SetBlendMode(BlendMode mode)142 void Pen::SetBlendMode(BlendMode mode)
143 {
144 return brush_.SetBlendMode(mode);
145 }
146
IsAntiAlias() const147 bool Pen::IsAntiAlias() const
148 {
149 return brush_.IsAntiAlias();
150 }
151
SetAntiAlias(bool aa)152 void Pen::SetAntiAlias(bool aa)
153 {
154 brush_.SetAntiAlias(aa);
155 }
156
SetPathEffect(std::shared_ptr<PathEffect> e)157 void Pen::SetPathEffect(std::shared_ptr<PathEffect> e)
158 {
159 pathEffect_ = e;
160 }
161
GetPathEffect() const162 std::shared_ptr<PathEffect> Pen::GetPathEffect() const
163 {
164 return pathEffect_;
165 }
166
SetFilter(const Filter & filter)167 void Pen::SetFilter(const Filter& filter)
168 {
169 brush_.SetFilter(filter);
170 }
171
GetFilter() const172 Filter Pen::GetFilter() const
173 {
174 return brush_.GetFilter();
175 }
176
HasFilter() const177 bool Pen::HasFilter() const
178 {
179 return brush_.HasFilter();
180 }
181
SetShaderEffect(std::shared_ptr<ShaderEffect> e)182 void Pen::SetShaderEffect(std::shared_ptr<ShaderEffect> e)
183 {
184 brush_.SetShaderEffect(e);
185 }
186
GetShaderEffect() const187 std::shared_ptr<ShaderEffect> Pen::GetShaderEffect() const
188 {
189 return brush_.GetShaderEffect();
190 }
191
Reset()192 void Pen::Reset()
193 {
194 *this = Pen();
195 }
196
operator ==(const Pen & p1,const Pen & p2)197 bool operator==(const Pen& p1, const Pen& p2)
198 {
199 return p1.width_ == p2.width_ && p1.miterLimit_ == p2.miterLimit_ && p1.join_ == p2.join_ && p1.cap_ == p2.cap_ &&
200 p1.pathEffect_ == p2.pathEffect_ && p1.brush_ == p2.brush_;
201 }
202
operator !=(const Pen & p1,const Pen & p2)203 bool operator!=(const Pen& p1, const Pen& p2)
204 {
205 return !(p1 == p2);
206 }
207 } // namespace Drawing
208 } // namespace Rosen
209 } // namespace OHOS
210