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_TEXT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_RENDER_SVG_TEXT_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 #include "frameworks/core/pipeline/base/render_node.h" 25 26 namespace OHOS::Ace { 27 28 struct DrawOffset { 29 Offset svg; 30 Offset current; 31 bool isTspan = false; 32 }; 33 34 struct PathOffset { 35 Offset svg; 36 double start = 0.0; 37 double current = 0.0; 38 std::string path; 39 }; 40 41 class RenderSvgText : public RenderSvgBase { 42 DECLARE_ACE_TYPE(RenderSvgText, RenderSvgBase) 43 44 public: 45 static RefPtr<RenderNode> Create(); 46 47 void Update(const RefPtr<Component>& component) override; 48 void PerformLayout() override; 49 bool PrepareSelfAnimation(const RefPtr<SvgAnimate>& svgAnimate) override; 50 GetTextData()51 const std::string& GetTextData() const 52 { 53 return textData_; 54 } 55 SetTextData(const std::string & textData)56 void SetTextData(const std::string& textData) 57 { 58 textData_ = textData; 59 } 60 GetX()61 const Dimension& GetX() const 62 { 63 return x_; 64 } 65 GetY()66 const Dimension& GetY() const 67 { 68 return y_; 69 } 70 GetDx()71 const Dimension& GetDx() const 72 { 73 return dx_; 74 } 75 GetDy()76 const Dimension& GetDy() const 77 { 78 return dy_; 79 } 80 GetRotate()81 double GetRotate() const 82 { 83 return rotate_; 84 } 85 86 protected: 87 Dimension x_ = Dimension(0.0); 88 Dimension y_ = Dimension(0.0); 89 Dimension dx_ = Dimension(0.0); 90 Dimension dy_ = Dimension(0.0); 91 std::string textData_; 92 double rotate_ = 0.0; 93 bool hasX_ = false; 94 bool hasY_ = false; 95 96 private: 97 void PrepareAnimations(const RefPtr<Component>& component); 98 bool SetProperty(const std::string& attributeName, const Dimension& value); 99 bool GetProperty(const std::string& attrName, Dimension& dimension) const; 100 }; 101 102 } // namespace OHOS::Ace 103 104 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_RENDER_SVG_TEXT_H 105