1 /*
2  * Copyright (c) 2022-2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_MASK_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_MASK_H
18 
19 #ifndef USE_ROSEN_DRAWING
20 #include "include/core/SkRect.h"
21 #else
22 #include "core/components_ng/render/drawing.h"
23 #endif
24 
25 #include "frameworks/core/components_ng/svg/parse/svg_attributes_parser.h"
26 #include "frameworks/core/components_ng/svg/parse/svg_quote.h"
27 
28 namespace OHOS::Ace::NG {
29 
30 class SvgMask : public SvgQuote {
31     DECLARE_ACE_TYPE(SvgMask, SvgQuote);
32 
33 public:
34     SvgMask();
35     ~SvgMask() override = default;
36     static RefPtr<SvgNode> Create();
37 
38 protected:
39     void OnInitStyle() override;
40     void OnDrawTraversedBefore(RSCanvas& canvas, const Size& viewPort, const std::optional<Color>& color) override;
41     void OnDrawTraversedAfter(RSCanvas& canvas, const Size& viewPort, const std::optional<Color>& color) override;
42 
43     double ParseUnitsAttr(const Dimension& attr, double value);
44     bool ParseAndSetSpecializedAttr(const std::string& name, const std::string& value) override;
45 
46 private:
47     Dimension x_ = Dimension(-0.1, DimensionUnit::PERCENT); // x-axis default value
48     Dimension y_ = Dimension(-0.1, DimensionUnit::PERCENT); // y-axis default value
49     Dimension height_ = Dimension(1.2, DimensionUnit::PERCENT); // masking area width default value
50     Dimension width_ = Dimension(1.2, DimensionUnit::PERCENT); // masking area height default  value
51     bool isDefaultMaskUnits_ = true;
52     bool isDefaultMaskContentUnits_ = true;
53 
54     SvgMaskAttribute maskAttr_;
55 
56 #ifndef USE_ROSEN_DRAWING
57     SkRect maskBounds_;
58 #else
59     RSRect maskBounds_;
60 #endif
61     int canvasLayerCount_ = -1;
62 };
63 
64 } // namespace OHOS::Ace::NG
65 
66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_MASK_H