2016-07-27 01:46:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "experimental/svg/model/SkSVGRenderContext.h"
|
|
|
|
#include "experimental/svg/model/SkSVGTransformableNode.h"
|
|
|
|
#include "experimental/svg/model/SkSVGValue.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2016-07-27 01:46:34 +00:00
|
|
|
|
|
|
|
SkSVGTransformableNode::SkSVGTransformableNode(SkSVGTag tag)
|
|
|
|
: INHERITED(tag)
|
2016-08-08 19:58:57 +00:00
|
|
|
, fTransform(SkMatrix::I()) { }
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
|
|
|
|
bool SkSVGTransformableNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
|
2016-08-08 19:58:57 +00:00
|
|
|
if (!fTransform.value().isIdentity()) {
|
2017-10-11 18:11:16 +00:00
|
|
|
ctx->saveOnce();
|
2016-08-08 19:58:57 +00:00
|
|
|
ctx->canvas()->concat(fTransform);
|
2016-08-08 18:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this->INHERITED::onPrepareToRender(ctx);
|
|
|
|
}
|
|
|
|
|
2016-07-27 01:46:34 +00:00
|
|
|
void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
|
|
|
switch (attr) {
|
2016-07-29 15:52:03 +00:00
|
|
|
case SkSVGAttribute::kTransform:
|
2016-07-27 01:46:34 +00:00
|
|
|
if (const auto* transform = v.as<SkSVGTransformValue>()) {
|
|
|
|
this->setTransform(*transform);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this->INHERITED::onSetAttribute(attr, v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-08 14:26:47 +00:00
|
|
|
|
|
|
|
void SkSVGTransformableNode::mapToParent(SkPath* path) const {
|
2017-10-11 14:13:47 +00:00
|
|
|
// transforms the path to parent node coordinates.
|
|
|
|
path->transform(fTransform.value());
|
2016-12-08 14:26:47 +00:00
|
|
|
}
|