397a517d1a
The main feature is <svg> viewBox and proper viewport support, but the CL touches a few other things: * refactor SkSVGRenderContext to auto-restore canvas state, and split the presentation bits into a separate CoW SkSVGPresentationContext * introduce SkSVGNode::onPrepareToRender(), as a way for nodes to push their custom state before the actual onRender() call (instead of relying on non-virtual SkSVGNode to know about all possible state bits) * add a "Type" suffix to SVG types, to disambiguate (e.g. SkSVGRectType vs. SkSVGRect) R=robertphillips@google.com,stephana@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2222793002 Review-Url: https://codereview.chromium.org/2222793002
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
/*
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "SkCanvas.h"
|
|
#include "SkMatrix.h"
|
|
#include "SkSVGNode.h"
|
|
#include "SkSVGRenderContext.h"
|
|
#include "SkSVGValue.h"
|
|
#include "SkTLazy.h"
|
|
|
|
SkSVGNode::SkSVGNode(SkSVGTag t) : fTag(t) { }
|
|
|
|
SkSVGNode::~SkSVGNode() { }
|
|
|
|
void SkSVGNode::render(const SkSVGRenderContext& ctx) const {
|
|
SkSVGRenderContext localContext(ctx);
|
|
|
|
if (this->onPrepareToRender(&localContext)) {
|
|
this->onRender(localContext);
|
|
}
|
|
}
|
|
|
|
bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
|
|
fPresentationAttributes.applyTo(ctx);
|
|
return true;
|
|
}
|
|
|
|
void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
|
this->onSetAttribute(attr, v);
|
|
}
|
|
|
|
void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
|
switch (attr) {
|
|
case SkSVGAttribute::kFill:
|
|
if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) {
|
|
fPresentationAttributes.setFill(*color);
|
|
}
|
|
break;
|
|
case SkSVGAttribute::kStroke:
|
|
if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) {
|
|
fPresentationAttributes.setStroke(*color);
|
|
}
|
|
break;
|
|
default:
|
|
SkDebugf("attribute ID <%d> ignored for node <%d>\n", attr, fTag);
|
|
break;
|
|
}
|
|
}
|