xref: /aosp_15_r20/external/skia/modules/svg/src/SkSVGContainer.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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)17 SkSVGContainer::SkSVGContainer(SkSVGTag t) : INHERITED(t) { }
18 
appendChild(sk_sp<SkSVGNode> node)19 void SkSVGContainer::appendChild(sk_sp<SkSVGNode> node) {
20     SkASSERT(node);
21     fChildren.push_back(std::move(node));
22 }
23 
hasChildren() const24 bool SkSVGContainer::hasChildren() const {
25     return !fChildren.empty();
26 }
27 
onRender(const SkSVGRenderContext & ctx) const28 void SkSVGContainer::onRender(const SkSVGRenderContext& ctx) const {
29     for (int i = 0; i < fChildren.size(); ++i) {
30         fChildren[i]->render(ctx);
31     }
32 }
33 
onAsPath(const SkSVGRenderContext & ctx) const34 SkPath SkSVGContainer::onAsPath(const SkSVGRenderContext& ctx) const {
35     SkPath path;
36 
37     for (int i = 0; i < fChildren.size(); ++i) {
38         const SkPath childPath = fChildren[i]->asPath(ctx);
39 
40         Op(path, childPath, kUnion_SkPathOp, &path);
41     }
42 
43     this->mapToParent(&path);
44     return path;
45 }
46 
onObjectBoundingBox(const SkSVGRenderContext & ctx) const47 SkRect SkSVGContainer::onObjectBoundingBox(const SkSVGRenderContext& ctx) const {
48     SkRect bounds = SkRect::MakeEmpty();
49 
50     for (int i = 0; i < fChildren.size(); ++i) {
51         const SkRect childBounds = fChildren[i]->objectBoundingBox(ctx);
52         bounds.join(childBounds);
53     }
54 
55     return bounds;
56 }
57