1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "modules/svg/include/SkSVGContainer.h" 9 10 #include "include/core/SkPath.h" 11 #include "include/pathops/SkPathOps.h" 12 #include "include/private/base/SkAssert.h" 13 14 #include <utility> 15 class SkSVGRenderContext; 16 SkSVGContainer(SkSVGTag t)17SkSVGContainer::SkSVGContainer(SkSVGTag t) : INHERITED(t) { } 18 appendChild(sk_sp<SkSVGNode> node)19void SkSVGContainer::appendChild(sk_sp<SkSVGNode> node) { 20 SkASSERT(node); 21 fChildren.push_back(std::move(node)); 22 } 23 getChild()24std::vector<sk_sp<SkSVGNode>> SkSVGContainer::getChild() { 25 std::vector<sk_sp<SkSVGNode>> res; 26 for (int i = 0; i < fChildren.size(); ++i) { 27 res.emplace_back(fChildren[i]); 28 } 29 return res; 30 } 31 hasChildren() const32bool SkSVGContainer::hasChildren() const { 33 return !fChildren.empty(); 34 } 35 onRender(const SkSVGRenderContext & ctx) const36void SkSVGContainer::onRender(const SkSVGRenderContext& ctx) const { 37 for (int i = 0; i < fChildren.size(); ++i) { 38 fChildren[i]->render(ctx); 39 } 40 } 41 onAsPath(const SkSVGRenderContext & ctx) const42SkPath SkSVGContainer::onAsPath(const SkSVGRenderContext& ctx) const { 43 SkPath path; 44 45 for (int i = 0; i < fChildren.size(); ++i) { 46 const SkPath childPath = fChildren[i]->asPath(ctx); 47 48 Op(path, childPath, kUnion_SkPathOp, &path); 49 } 50 51 this->mapToParent(&path); 52 return path; 53 } 54 onTransformableObjectBoundingBox(const SkSVGRenderContext & ctx) const55SkRect SkSVGContainer::onTransformableObjectBoundingBox(const SkSVGRenderContext& ctx) const { 56 SkRect bounds = SkRect::MakeEmpty(); 57 58 for (int i = 0; i < fChildren.size(); ++i) { 59 const SkRect childBounds = fChildren[i]->objectBoundingBox(ctx); 60 bounds.join(childBounds); 61 } 62 63 return bounds; 64 } 65