1 /* 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 8 #include "modules/svg/include/SkSVGTransformableNode.h" 9 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkRect.h" 12 #include "modules/svg/include/SkSVGAttribute.h" 13 #include "modules/svg/include/SkSVGRenderContext.h" 14 #include "modules/svg/include/SkSVGValue.h" 15 SkSVGTransformableNode(SkSVGTag tag)16SkSVGTransformableNode::SkSVGTransformableNode(SkSVGTag tag) 17 : INHERITED(tag) 18 , fTransform(SkMatrix::I()) { } 19 20 onPrepareToRender(SkSVGRenderContext * ctx) const21bool SkSVGTransformableNode::onPrepareToRender(SkSVGRenderContext* ctx) const { 22 if (!fTransform.isIdentity()) { 23 ctx->saveOnce(); 24 ctx->canvas()->concat(fTransform); 25 } 26 27 return this->INHERITED::onPrepareToRender(ctx); 28 } 29 onSetAttribute(SkSVGAttribute attr,const SkSVGValue & v)30void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { 31 switch (attr) { 32 case SkSVGAttribute::kTransform: 33 if (const auto* transform = v.as<SkSVGTransformValue>()) { 34 this->setTransform(*transform); 35 } 36 break; 37 default: 38 this->INHERITED::onSetAttribute(attr, v); 39 break; 40 } 41 } 42 mapToParent(SkPath * path) const43void SkSVGTransformableNode::mapToParent(SkPath* path) const { 44 // transforms the path to parent node coordinates. 45 path->transform(fTransform); 46 } 47 mapToParent(SkRect * rect) const48void SkSVGTransformableNode::mapToParent(SkRect* rect) const { 49 *rect = fTransform.mapRect(*rect); 50 } 51