SkSVGNode.cpp revision 397a517d1a5774653fcdd08172f9a6b5eea67621
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(const SkSVGRenderContext& ctx) const {
20    SkSVGRenderContext localContext(ctx);
21
22    if (this->onPrepareToRender(&localContext)) {
23        this->onRender(localContext);
24    }
25}
26
27bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
28    fPresentationAttributes.applyTo(ctx);
29    return true;
30}
31
32void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
33    this->onSetAttribute(attr, v);
34}
35
36void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
37    switch (attr) {
38    case SkSVGAttribute::kFill:
39        if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) {
40            fPresentationAttributes.setFill(*color);
41        }
42        break;
43    case SkSVGAttribute::kStroke:
44        if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) {
45            fPresentationAttributes.setStroke(*color);
46        }
47        break;
48    default:
49        SkDebugf("attribute ID <%d> ignored for node <%d>\n", attr, fTag);
50        break;
51    }
52}
53