SkSVGNode.cpp revision bffc2566872f99d378a1113d0a49ec9ee0d60b7a
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 "SkCanvas.h" 9#include "SkMatrix.h" 10#include "SkSVGNode.h" 11#include "SkSVGRenderContext.h" 12#include "SkSVGValue.h" 13#include "SkTLazy.h" 14 15SkSVGNode::SkSVGNode(SkSVGTag t) : fTag(t) { } 16 17SkSVGNode::~SkSVGNode() { } 18 19void SkSVGNode::render(SkCanvas* canvas, const SkSVGRenderContext& ctx) const { 20 SkTCopyOnFirstWrite<SkSVGRenderContext> localContext(ctx); 21 fPresentationAttributes.applyTo(localContext); 22 23 SkAutoCanvasRestore acr(canvas, false); 24 const SkMatrix& m = this->onLocalMatrix(); 25 if (!m.isIdentity()) { 26 canvas->save(); 27 canvas->concat(m); 28 } 29 30 this->onRender(canvas, *localContext); 31} 32 33void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGValue& v) { 34 this->onSetAttribute(attr, v); 35} 36 37void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { 38 switch (attr) { 39 case SkSVGAttribute::kFill: 40 if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) { 41 fPresentationAttributes.setFill(*color); 42 } 43 break; 44 case SkSVGAttribute::kStroke: 45 if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) { 46 fPresentationAttributes.setStroke(*color); 47 } 48 break; 49 default: 50 SkDebugf("attribute ID <%d> ignored for node <%d>\n", attr, fTag); 51 break; 52 } 53} 54 55const SkMatrix& SkSVGNode::onLocalMatrix() const { 56 return SkMatrix::I(); 57} 58