skia2/experimental/svg/model/SkSVGUse.cpp
Florin Malita f4403e7a78 Revert "[SVG] Replace custom attribute value wrappers with std::variant"
This reverts commit 97e0861b67.

Reason for revert: not all builders support C++17 STL

Original change's description:
> [SVG] Replace custom attribute value wrappers with std::variant
> 
> Less boilerplate, more STL.
> 
> Change-Id: I601f75877d60085cbf3d39f401543fbe9c086f90
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282836
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Florin Malita <fmalita@chromium.org>

TBR=fmalita@chromium.org,reed@google.com,tdenniston@google.com

Change-Id: If5816f11e9cf85dcec2452229c5675037303b220
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282847
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2020-04-10 14:14:22 +00:00

87 lines
2.0 KiB
C++

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "experimental/svg/model/SkSVGUse.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
SkSVGUse::SkSVGUse() : INHERITED(SkSVGTag::kUse) {}
void SkSVGUse::appendChild(sk_sp<SkSVGNode>) {
SkDebugf("cannot append child nodes to this element.\n");
}
void SkSVGUse::setHref(const SkSVGStringType& href) {
fHref = href;
}
void SkSVGUse::setX(const SkSVGLength& x) {
fX = x;
}
void SkSVGUse::setY(const SkSVGLength& y) {
fY = y;
}
void SkSVGUse::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
switch (attr) {
case SkSVGAttribute::kHref:
if (const auto* href = v.as<SkSVGStringValue>()) {
this->setHref(*href);
}
break;
case SkSVGAttribute::kX:
if (const auto* x = v.as<SkSVGLengthValue>()) {
this->setX(*x);
}
break;
case SkSVGAttribute::kY:
if (const auto* y = v.as<SkSVGLengthValue>()) {
this->setY(*y);
}
break;
default:
this->INHERITED::onSetAttribute(attr, v);
}
}
bool SkSVGUse::onPrepareToRender(SkSVGRenderContext* ctx) const {
if (fHref.isEmpty() || !INHERITED::onPrepareToRender(ctx)) {
return false;
}
if (fX.value() || fY.value()) {
// Restored when the local SkSVGRenderContext leaves scope.
ctx->saveOnce();
ctx->canvas()->translate(fX.value(), fY.value());
}
// TODO: width/height override for <svg> targets.
return true;
}
void SkSVGUse::onRender(const SkSVGRenderContext& ctx) const {
const auto ref = ctx.findNodeById(fHref);
if (!ref) {
return;
}
ref->render(ctx);
}
SkPath SkSVGUse::onAsPath(const SkSVGRenderContext& ctx) const {
const auto ref = ctx.findNodeById(fHref);
if (!ref) {
return SkPath();
}
return ref->asPath(ctx);
}