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 "effect/path_effect.h"
17 
18 #include "impl_factory.h"
19 
20 #include "impl_interface/path_effect_impl.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
PathEffect(PathEffectType t,const scalar intervals[],int count,scalar phase)25 PathEffect::PathEffect(PathEffectType t, const scalar intervals[], int count, scalar phase) noexcept : PathEffect()
26 {
27     type_ = t;
28     impl_->InitWithDash(intervals, count, phase);
29 }
30 
PathEffect(PathEffectType t,const Path & path,scalar advance,scalar phase,PathDashStyle style)31 PathEffect::PathEffect(PathEffectType t, const Path& path, scalar advance, scalar phase, PathDashStyle style) noexcept
32     : PathEffect()
33 {
34     type_ = t;
35     impl_->InitWithPathDash(path, advance, phase, style);
36 }
37 
PathEffect(PathEffectType t,scalar radius)38 PathEffect::PathEffect(PathEffectType t, scalar radius) noexcept : PathEffect()
39 {
40     type_ = t;
41     impl_->InitWithCorner(radius);
42 }
43 
PathEffect(PathEffectType t,scalar segLength,scalar dev,uint32_t seedAssist)44 PathEffect::PathEffect(PathEffectType t, scalar segLength, scalar dev, uint32_t seedAssist) noexcept : PathEffect()
45 {
46     type_ = t;
47     impl_->InitWithDiscrete(segLength, dev, seedAssist);
48 }
49 
PathEffect(PathEffectType t,PathEffect & e1,PathEffect & e2)50 PathEffect::PathEffect(PathEffectType t, PathEffect& e1, PathEffect& e2) noexcept : PathEffect()
51 {
52     type_ = t;
53     if (type_ == PathEffect::PathEffectType::SUM) {
54         impl_->InitWithSum(e1, e2);
55     } else if (type_ == PathEffect::PathEffectType::COMPOSE) {
56         impl_->InitWithCompose(e1, e2);
57     }
58 }
59 
PathEffect()60 PathEffect::PathEffect() noexcept
61     : type_(PathEffect::PathEffectType::NO_TYPE), impl_(ImplFactory::CreatePathEffectImpl())
62 {}
63 
PathEffect(PathEffectType t)64 PathEffect::PathEffect(PathEffectType t) noexcept
65     : type_(t), impl_(ImplFactory::CreatePathEffectImpl())
66 {}
67 
GetType() const68 PathEffect::PathEffectType PathEffect::GetType() const
69 {
70     return type_;
71 }
72 
CreateDashPathEffect(const scalar intervals[],int count,scalar phase)73 std::shared_ptr<PathEffect> PathEffect::CreateDashPathEffect(const scalar intervals[], int count, scalar phase)
74 {
75     return std::make_shared<PathEffect>(PathEffect::PathEffectType::DASH, intervals, count, phase);
76 }
77 
CreatePathDashEffect(const Path & path,scalar advance,scalar phase,PathDashStyle style)78 std::shared_ptr<PathEffect> PathEffect::CreatePathDashEffect(
79     const Path& path, scalar advance, scalar phase, PathDashStyle style)
80 {
81     return std::make_shared<PathEffect>(PathEffect::PathEffectType::PATH_DASH, path, advance, phase, style);
82 }
83 
CreateCornerPathEffect(scalar radius)84 std::shared_ptr<PathEffect> PathEffect::CreateCornerPathEffect(scalar radius)
85 {
86     return std::make_shared<PathEffect>(PathEffect::PathEffectType::CORNER, radius);
87 }
88 
CreateDiscretePathEffect(scalar segLength,scalar dev,uint32_t seedAssist)89 std::shared_ptr<PathEffect> PathEffect::CreateDiscretePathEffect(scalar segLength, scalar dev, uint32_t seedAssist)
90 {
91     return std::make_shared<PathEffect>(PathEffect::PathEffectType::DISCRETE, segLength, dev, seedAssist);
92 }
93 
CreateSumPathEffect(PathEffect & e1,PathEffect & e2)94 std::shared_ptr<PathEffect> PathEffect::CreateSumPathEffect(PathEffect& e1, PathEffect& e2)
95 {
96     return std::make_shared<PathEffect>(PathEffect::PathEffectType::SUM, e1, e2);
97 }
98 
CreateComposePathEffect(PathEffect & e1,PathEffect & e2)99 std::shared_ptr<PathEffect> PathEffect::CreateComposePathEffect(PathEffect& e1, PathEffect& e2)
100 {
101     return std::make_shared<PathEffect>(PathEffect::PathEffectType::COMPOSE, e1, e2);
102 }
103 
Serialize() const104 std::shared_ptr<Data> PathEffect::Serialize() const
105 {
106     return impl_->Serialize();
107 }
108 
Deserialize(std::shared_ptr<Data> data)109 bool PathEffect::Deserialize(std::shared_ptr<Data> data)
110 {
111     return impl_->Deserialize(data);
112 }
113 
114 } // namespace Drawing
115 } // namespace Rosen
116 } // namespace OHOS