blob: e8713c03c40bab5df1480c161a5e83001ed41497 [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
fmalita397a5172016-08-08 11:38:55 -07008#include "SkCanvas.h"
9#include "SkSVGRenderContext.h"
fmalita6ceef3d2016-07-26 18:46:34 -070010#include "SkSVGTransformableNode.h"
11#include "SkSVGValue.h"
12
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 {
fmalitac97796b2016-08-08 12:58:57 -070019 if (!fTransform.value().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
fmalita6ceef3d2016-07-26 18:46:34 -070027void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
28 switch (attr) {
fmalita58649cc2016-07-29 08:52:03 -070029 case SkSVGAttribute::kTransform:
fmalita6ceef3d2016-07-26 18:46:34 -070030 if (const auto* transform = v.as<SkSVGTransformValue>()) {
31 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.
42 path->transform(fTransform.value());
Florin Malitace8840e2016-12-08 09:26:47 -050043}