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 SkSVGContainer(SkSVGTag t)13SkSVGContainer::SkSVGContainer(SkSVGTag t) : INHERITED(t) { } 14 appendChild(sk_sp<SkSVGNode> node)15void SkSVGContainer::appendChild(sk_sp<SkSVGNode> node) { 16 SkASSERT(node); 17 fChildren.push_back(std::move(node)); 18 } 19 getChild()20std::vector<sk_sp<SkSVGNode>> SkSVGContainer::getChild() { 21 std::vector<sk_sp<SkSVGNode>> res; 22 for (int i = 0; i < fChildren.count(); ++i) { 23 res.emplace_back(fChildren[i]); 24 } 25 return res; 26 } 27 hasChildren() const28bool SkSVGContainer::hasChildren() const { 29 return !fChildren.empty(); 30 } 31 onRender(const SkSVGRenderContext & ctx) const32void SkSVGContainer::onRender(const SkSVGRenderContext& ctx) const { 33 for (int i = 0; i < fChildren.count(); ++i) { 34 fChildren[i]->render(ctx); 35 } 36 } 37 onAsPath(const SkSVGRenderContext & ctx) const38SkPath SkSVGContainer::onAsPath(const SkSVGRenderContext& ctx) const { 39 SkPath path; 40 41 for (int i = 0; i < fChildren.count(); ++i) { 42 const SkPath childPath = fChildren[i]->asPath(ctx); 43 44 Op(path, childPath, kUnion_SkPathOp, &path); 45 } 46 47 this->mapToParent(&path); 48 return path; 49 } 50 onObjectBoundingBox(const SkSVGRenderContext & ctx) const51SkRect SkSVGContainer::onObjectBoundingBox(const SkSVGRenderContext& ctx) const { 52 SkRect bounds = SkRect::MakeEmpty(); 53 54 for (int i = 0; i < fChildren.count(); ++i) { 55 const SkRect childBounds = fChildren[i]->objectBoundingBox(ctx); 56 bounds.join(childBounds); 57 } 58 59 return bounds; 60 } 61