1 /* 2 * Copyright (c) 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_NG_SVG_PARSE_SVG_QUOTE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_QUOTE_H 18 19 #include "frameworks/core/components_ng/svg/parse/svg_node.h" 20 #include "include/pathops/SkPathOps.h" 21 22 namespace OHOS::Ace::NG { 23 24 class SvgQuote : public SvgNode { 25 DECLARE_ACE_TYPE(SvgQuote, SvgNode); 26 27 public: SvgQuote()28 SvgQuote() : SvgNode() 29 { 30 InitHrefFlag(); 31 } 32 ~SvgQuote() override = default; 33 34 #ifndef USE_ROSEN_DRAWING AsPath(const Size & viewPort)35 SkPath AsPath(const Size& viewPort) const override 36 { 37 SkPath path; 38 for (const auto& child : children_) { 39 const SkPath childPath = child->AsPath(viewPort); 40 Op(path, childPath, kUnion_SkPathOp, &path); 41 } 42 return path; 43 } 44 #else AsPath(const Size & viewPort)45 RSRecordingPath AsPath(const Size& viewPort) const override 46 { 47 RSRecordingPath path; 48 for (const auto& child : children_) { 49 auto childPath = child->AsPath(viewPort); 50 path.Op(path, childPath, RSPathOp::UNION); 51 } 52 return path; 53 } 54 #endif 55 Draw(RSCanvas & canvas,const Size & viewPort,const std::optional<Color> & color)56 void Draw(RSCanvas& canvas, const Size& viewPort, const std::optional<Color>& color) override 57 { 58 // render composition on other svg tags 59 if (!OnCanvas(canvas)) { 60 return; 61 } 62 OnDrawTraversedBefore(canvas, viewPort, color); 63 OnDrawTraversed(canvas, viewPort, color); 64 OnDrawTraversedAfter(canvas, viewPort, color); 65 } 66 67 protected: OnDrawTraversedBefore(RSCanvas & canvas,const Size & viewPort,const std::optional<Color> & color)68 virtual void OnDrawTraversedBefore(RSCanvas& canvas, const Size& viewPort, const std::optional<Color>& color) {} OnDrawTraversedAfter(RSCanvas & canvas,const Size & viewPort,const std::optional<Color> & color)69 virtual void OnDrawTraversedAfter(RSCanvas& canvas, const Size& viewPort, const std::optional<Color>& color) {} 70 71 // mask/pattern/filter/clipPath InitHrefFlag()72 void InitHrefFlag() 73 { 74 hrefFill_ = true; 75 hrefRender_ = false; 76 passStyle_ = true; 77 inheritStyle_ = false; 78 drawTraversed_ = false; 79 } 80 }; 81 82 } // namespace OHOS::Ace::NG 83 84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_QUOTE_H