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.
|
|
|
|
*/
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkSVGRenderContext.h"
|
2016-07-27 01:46:34 +00:00
|
|
|
#include "SkSVGTransformableNode.h"
|
|
|
|
#include "SkSVGValue.h"
|
|
|
|
|
|
|
|
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()) {
|
2016-08-08 18:38:55 +00:00
|
|
|
ctx->canvas()->save();
|
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;
|
|
|
|
}
|
|
|
|
}
|