blob: b2ad0b1ab9becb22050ba629ba9f94ce3fe0e762 [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()) {
fmalita397a5172016-08-08 11:38:55 -070020 ctx->canvas()->save();
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 {
41 if (fTransform.value().isIdentity()) {
42 return;
43 }
44
45 SkMatrix inv;
46 if (!fTransform.value().invert(&inv)) {
47 return;
48 }
49
50 path->transform(inv);
51}