blob: df21b20a1b4830e931cb4efc0d6676b371a7c17a [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "experimental/svg/model/SkSVGRenderContext.h"
9#include "experimental/svg/model/SkSVGTransformableNode.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
fmalita6ceef3d2016-07-26 18:46:34 -070011
12SkSVGTransformableNode::SkSVGTransformableNode(SkSVGTag tag)
13 : INHERITED(tag)
fmalitac97796b2016-08-08 12:58:57 -070014 , fTransform(SkMatrix::I()) { }
fmalita6ceef3d2016-07-26 18:46:34 -070015
fmalita397a5172016-08-08 11:38:55 -070016
17bool SkSVGTransformableNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
Florin Malitaa3626692020-04-09 14:36:45 -040018 if (!fTransform.isIdentity()) {
Florin Malitab36be142017-10-11 14:11:16 -040019 ctx->saveOnce();
fmalitac97796b2016-08-08 12:58:57 -070020 ctx->canvas()->concat(fTransform);
fmalita397a5172016-08-08 11:38:55 -070021 }
22
23 return this->INHERITED::onPrepareToRender(ctx);
24}
25
Florin Malita97e08612020-04-10 00:29:13 -040026void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
fmalita6ceef3d2016-07-26 18:46:34 -070027 switch (attr) {
fmalita58649cc2016-07-29 08:52:03 -070028 case SkSVGAttribute::kTransform:
Florin Malita97e08612020-04-10 00:29:13 -040029 if (const auto* transform = std::get_if<SkSVGTransformType>(&v)) {
fmalita6ceef3d2016-07-26 18:46:34 -070030 this->setTransform(*transform);
31 }
32 break;
33 default:
34 this->INHERITED::onSetAttribute(attr, v);
35 break;
36 }
37}
Florin Malitace8840e2016-12-08 09:26:47 -050038
39void SkSVGTransformableNode::mapToParent(SkPath* path) const {
Florin Malita98395d02017-10-11 10:13:47 -040040 // transforms the path to parent node coordinates.
Florin Malitaa3626692020-04-09 14:36:45 -040041 path->transform(fTransform);
Florin Malitace8840e2016-12-08 09:26:47 -050042}