Debian Codegraph @

modules/svg/src/SkSVGTransformableNode.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/SkSVGTransformableNode.h"
9
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkRect.h"
12 #include "modules/svg/include/SkSVGAttribute.h"
13 #include "modules/svg/include/SkSVGRenderContext.h"
14 #include "modules/svg/include/SkSVGValue.h"
15
16 SkSVGTransformableNode::SkSVGTransformableNode(SkSVGTag tag)
17 : INHERITED(tag)
18 , fTransform(SkMatrix::I()) { }
19
20
21 bool SkSVGTransformableNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
22 if (!fTransform.isIdentity()) {
23 ctx->saveOnce();
24 ctx->canvas()->concat(fTransform);
25 }
26
27 return this->INHERITED::onPrepareToRender(ctx);
28 }
29
30 void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
31 switch (attr) {
32 case SkSVGAttribute::kTransform:
33 if (const auto* transform = v.as<SkSVGTransformValue>()) {
34 this->setTransform(*transform);
35 }
36 break;
37 default:
38 this->INHERITED::onSetAttribute(attr, v);
39 break;
40 }
41 }
42
43 SkPath SkSVGTransformableNode::mapToParent(const SkPath& path) const {
44 // transforms the path to parent node coordinates.
45 return path.makeTransform(fTransform);
46 }
47
48 SkRect SkSVGTransformableNode::mapToParent(const SkRect& rect) const {
49 return fTransform.mapRect(rect);
50 }
51
52 SkRect SkSVGTransformableNode::onTransformableObjectBoundingBox(const SkSVGRenderContext&) const {
53 return SkRect::MakeEmpty();
54 }
55
56 SkRect SkSVGTransformableNode::onObjectBoundingBox(const SkSVGRenderContext& ctx) const {
57 SkRect obb = this->onTransformableObjectBoundingBox(ctx);
58
59 if (ctx.currentOBBScope().fNode != this && !fTransform.isIdentity()) {
60 obb = this->mapToParent(obb);
61 }
62 return obb;
63 }
64