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"
|
2020-04-10 14:14:04 +00:00
|
|
|
#include "experimental/svg/model/SkSVGValue.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#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 {
|
2020-04-09 18:36:45 +00:00
|
|
|
if (!fTransform.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);
|
|
|
|
}
|
|
|
|
|
2020-04-10 14:14:04 +00:00
|
|
|
void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
2016-07-27 01:46:34 +00:00
|
|
|
switch (attr) {
|
2016-07-29 15:52:03 +00:00
|
|
|
case SkSVGAttribute::kTransform:
|
2020-04-10 14:14:04 +00:00
|
|
|
if (const auto* transform = v.as<SkSVGTransformValue>()) {
|
2016-07-27 01:46:34 +00:00
|
|
|
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.
|
2020-04-09 18:36:45 +00:00
|
|
|
path->transform(fTransform);
|
2016-12-08 14:26:47 +00:00
|
|
|
}
|