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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_RENDER_SVG_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_RENDER_SVG_PATTERN_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 namespace OHOS::Ace { 26 27 class RenderSvgPattern : public RenderSvgBase { 28 DECLARE_ACE_TYPE(RenderSvgPattern, RenderSvgBase) 29 30 public: 31 static RefPtr<RenderNode> Create(); 32 void Update(const RefPtr<Component>& component) override; 33 void PerformLayout() override; 34 bool PrepareSelfAnimation(const RefPtr<SvgAnimate>& svgAnimate) override; 35 IsDefaultPatternUnits()36 bool IsDefaultPatternUnits() const 37 { 38 return patternUnits_ == "objectBoundingBox"; 39 } 40 IsDefaultPatternContentUnits()41 bool IsDefaultPatternContentUnits() const 42 { 43 // return true if content relative to svg 44 return patternContentUnits_ == "userSpaceOnUse"; 45 } 46 47 double ParseUnitsAttr(const Dimension& attr, double value) const; 48 49 protected: 50 Dimension x_; 51 Dimension y_; 52 Dimension height_; 53 Dimension width_; 54 std::string patternUnits_ = "objectBoundingBox"; 55 std::string patternContentUnits_ = "userSpaceOnUse"; 56 Rect viewBox_; 57 58 private: 59 void PrepareAnimations(const RefPtr<Component>& component); 60 bool SetProperty(const std::string& attributeName, double value); 61 bool GetProperty(const std::string& attrName, double& value) const; 62 }; 63 64 } // namespace OHOS::Ace 65 66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_RENDER_SVG_PATTERN_H 67