fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 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 "SkSVGContainer.h" |
| 9 | |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 10 | #include "SkPath.h" |
| 11 | #include "SkPathOps.h" |
| 12 | |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 13 | SkSVGContainer::SkSVGContainer(SkSVGTag t) : INHERITED(t) { } |
| 14 | |
| 15 | void SkSVGContainer::appendChild(sk_sp<SkSVGNode> node) { |
| 16 | SkASSERT(node); |
| 17 | fChildren.push_back(std::move(node)); |
| 18 | } |
| 19 | |
fmalita | bef51c2 | 2016-09-20 15:45:57 -0700 | [diff] [blame] | 20 | bool SkSVGContainer::hasChildren() const { |
| 21 | return !fChildren.empty(); |
| 22 | } |
| 23 | |
fmalita | 397a517 | 2016-08-08 11:38:55 -0700 | [diff] [blame] | 24 | void SkSVGContainer::onRender(const SkSVGRenderContext& ctx) const { |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 25 | for (int i = 0; i < fChildren.count(); ++i) { |
fmalita | 397a517 | 2016-08-08 11:38:55 -0700 | [diff] [blame] | 26 | fChildren[i]->render(ctx); |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 27 | } |
| 28 | } |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 29 | |
| 30 | SkPath 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 | } |