blob: 6eb7d88592bb2b3d5f4befbeb0f7761da774610f [file] [log] [blame]
fmalita6ceef3d2016-07-26 18:46:34 -07001/*
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
Florin Malitab3418102020-10-15 18:10:29 -04008#include "modules/svg/include/SkSVGContainer.h"
fmalita6ceef3d2016-07-26 18:46:34 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkPath.h"
11#include "include/pathops/SkPathOps.h"
Florin Malitace8840e2016-12-08 09:26:47 -050012
fmalita6ceef3d2016-07-26 18:46:34 -070013SkSVGContainer::SkSVGContainer(SkSVGTag t) : INHERITED(t) { }
14
15void SkSVGContainer::appendChild(sk_sp<SkSVGNode> node) {
16 SkASSERT(node);
17 fChildren.push_back(std::move(node));
18}
19
fmalitabef51c22016-09-20 15:45:57 -070020bool SkSVGContainer::hasChildren() const {
21 return !fChildren.empty();
22}
23
fmalita397a5172016-08-08 11:38:55 -070024void SkSVGContainer::onRender(const SkSVGRenderContext& ctx) const {
fmalita6ceef3d2016-07-26 18:46:34 -070025 for (int i = 0; i < fChildren.count(); ++i) {
fmalita397a5172016-08-08 11:38:55 -070026 fChildren[i]->render(ctx);
fmalita6ceef3d2016-07-26 18:46:34 -070027 }
28}
Florin Malitace8840e2016-12-08 09:26:47 -050029
30SkPath SkSVGContainer::onAsPath(const SkSVGRenderContext& ctx) const {
31 SkPath path;
32
33 for (int i = 0; i < fChildren.count(); ++i) {
34 const SkPath childPath = fChildren[i]->asPath(ctx);
35
36 Op(path, childPath, kUnion_SkPathOp, &path);
37 }
38
39 this->mapToParent(&path);
40 return path;
41}
Tyler Dennistonf548a022020-10-27 15:02:02 -040042
43SkRect SkSVGContainer::onObjectBoundingBox(const SkSVGRenderContext& ctx) const {
44 SkRect bounds = SkRect::MakeEmpty();
45
46 for (int i = 0; i < fChildren.count(); ++i) {
47 const SkRect childBounds = fChildren[i]->objectBoundingBox(ctx);
48 bounds.join(childBounds);
49 }
50
Tyler Dennistonf548a022020-10-27 15:02:02 -040051 return bounds;
52}