blob: f76f2c45d4a68b9e7582722c7e2cc8ab04864625 [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 "include/core/SkCanvas.h"
Florin Malita6fc41062020-10-15 09:22:35 -04009#include "modules/svg/include/SkSVGRenderContext.h"
10#include "modules/svg/include/SkSVGTransformableNode.h"
11#include "modules/svg/include/SkSVGValue.h"
fmalita6ceef3d2016-07-26 18:46:34 -070012
13SkSVGTransformableNode::SkSVGTransformableNode(SkSVGTag tag)
14 : INHERITED(tag)
fmalitac97796b2016-08-08 12:58:57 -070015 , fTransform(SkMatrix::I()) { }
fmalita6ceef3d2016-07-26 18:46:34 -070016
fmalita397a5172016-08-08 11:38:55 -070017
18bool SkSVGTransformableNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
Florin Malitaa3626692020-04-09 14:36:45 -040019 if (!fTransform.isIdentity()) {
Florin Malitab36be142017-10-11 14:11:16 -040020 ctx->saveOnce();
fmalitac97796b2016-08-08 12:58:57 -070021 ctx->canvas()->concat(fTransform);
fmalita397a5172016-08-08 11:38:55 -070022 }
23
24 return this->INHERITED::onPrepareToRender(ctx);
25}
26
Florin Malitaf4403e72020-04-10 14:14:04 +000027void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
fmalita6ceef3d2016-07-26 18:46:34 -070028 switch (attr) {
fmalita58649cc2016-07-29 08:52:03 -070029 case SkSVGAttribute::kTransform:
Florin Malitaf4403e72020-04-10 14:14:04 +000030 if (const auto* transform = v.as<SkSVGTransformValue>()) {
fmalita6ceef3d2016-07-26 18:46:34 -070031 this->setTransform(*transform);
32 }
33 break;
34 default:
35 this->INHERITED::onSetAttribute(attr, v);
36 break;
37 }
38}
Florin Malitace8840e2016-12-08 09:26:47 -050039
40void SkSVGTransformableNode::mapToParent(SkPath* path) const {
Florin Malita98395d02017-10-11 10:13:47 -040041 // transforms the path to parent node coordinates.
Florin Malitaa3626692020-04-09 14:36:45 -040042 path->transform(fTransform);
Florin Malitace8840e2016-12-08 09:26:47 -050043}