Debian Codegraph @

modules/svg/src/SkSVGContainer.cpp

raw
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
17 SkSVGContainer::SkSVGContainer(SkSVGTag t) : INHERITED(t) { }
18
19 void SkSVGContainer::appendChild(sk_sp<SkSVGNode> node) {
20 SkASSERT(node);
21 fChildren.push_back(std::move(node));
22 }
23
24 bool SkSVGContainer::hasChildren() const {
25 return !fChildren.empty();
26 }
27
28 void SkSVGContainer::onRender(const SkSVGRenderContext& ctx) const {
29 for (int i = 0; i < fChildren.size(); ++i) {
30 fChildren[i]->render(ctx);
31 }
32 }
33
34 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 if (auto result = Op(path, childPath, kUnion_SkPathOp)) {
41 path = *result;
42 }
43 }
44
45 return this->mapToParent(path);
46 }
47
48 SkRect SkSVGContainer::onTransformableObjectBoundingBox(const SkSVGRenderContext& ctx) const {
49 SkRect bounds = SkRect::MakeEmpty();
50
51 for (int i = 0; i < fChildren.size(); ++i) {
52 const SkRect childBounds = fChildren[i]->objectBoundingBox(ctx);
53 bounds.join(childBounds);
54 }
55
56 return bounds;
57 }