1 /* 2 * Copyright (c) 2021-2022 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_SVG_RENDER_SVG_MASK_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_RENDER_SVG_MASK_H 18 19 #include "base/memory/ace_type.h" 20 21 #include "frameworks/core/animation/animator.h" 22 #include "frameworks/core/components/common/properties/svg_paint_state.h" 23 #include "frameworks/core/components/svg/render_svg_base.h" 24 25 #ifndef USE_ROSEN_DRAWING 26 class SkCanvas; 27 #endif 28 namespace OHOS::Ace { 29 30 class RenderSvgMask : public RenderSvgBase { 31 DECLARE_ACE_TYPE(RenderSvgMask, RenderSvgBase) 32 33 public: 34 static RefPtr<RenderNode> Create(); 35 void Update(const RefPtr<Component>& component) override; 36 void PerformLayout() override; 37 bool PrepareSelfAnimation(const RefPtr<SvgAnimate>& svgAnimate) override; 38 #ifndef USE_ROSEN_DRAWING PaintMaskLayer(SkCanvas * canvas,const Offset & offset,const Rect & paintRect)39 virtual void PaintMaskLayer(SkCanvas* canvas, const Offset& offset, const Rect& paintRect) {} 40 #else PaintMaskLayer(RSCanvas * canvas,const Offset & offset,const Rect & paintRect)41 virtual void PaintMaskLayer(RSCanvas* canvas, const Offset& offset, const Rect& paintRect) {} 42 #endif PaintMaskLayer(RenderContext & context,const Offset & offset,const Rect & paintRect)43 virtual void PaintMaskLayer(RenderContext& context, const Offset& offset, const Rect& paintRect) {} 44 IsDefaultMaskUnits()45 bool IsDefaultMaskUnits() const 46 { 47 return maskUnits_ == "objectBoundingBox"; 48 } 49 IsDefaultMaskContentUnits()50 bool IsDefaultMaskContentUnits() const 51 { 52 // return true if content relative to svg 53 return maskContentUnits_ == "userSpaceOnUse"; 54 } 55 SetElementBounds(const Rect & bounds)56 void SetElementBounds(const Rect& bounds) 57 { 58 elementBounds_ = bounds; 59 } 60 61 protected: 62 double ParseUnitsAttr(const Dimension& attr, double value); 63 64 Dimension x_ = Dimension(-0.1, DimensionUnit::PERCENT); // x-axis default value 65 Dimension y_ = Dimension(-0.1, DimensionUnit::PERCENT); // y-axis default value 66 Dimension height_ = Dimension(1.2, DimensionUnit::PERCENT); // masking area width default value 67 Dimension width_ = Dimension(1.2, DimensionUnit::PERCENT); // masking area height default value 68 std::string maskUnits_ = "objectBoundingBox"; 69 std::string maskContentUnits_ = "userSpaceOnUse"; 70 Rect elementBounds_; 71 72 private: 73 void PrepareAnimations(const RefPtr<Component>& component); 74 bool SetProperty(const std::string& attributeName, double value); 75 bool GetProperty(const std::string& attrName, double& value) const; 76 }; 77 78 } // namespace OHOS::Ace 79 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_RENDER_SVG_MASK_H 81