[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>
This commit is contained in:
Florin Malita 2020-04-10 00:29:13 -04:00 committed by Skia Commit-Bot
parent f7255d72f8
commit 97e0861b67
37 changed files with 144 additions and 243 deletions

View File

@ -1626,7 +1626,6 @@ if (skia_enable_tools) {
"experimental/svg/model/SkSVGText.cpp",
"experimental/svg/model/SkSVGTransformableNode.cpp",
"experimental/svg/model/SkSVGUse.cpp",
"experimental/svg/model/SkSVGValue.cpp",
]
deps = [
":skia",

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGCircle.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
SkSVGCircle::SkSVGCircle() : INHERITED(SkSVGTag::kCircle) {}
@ -24,20 +23,20 @@ void SkSVGCircle::setR(const SkSVGLength& r) {
fR = r;
}
void SkSVGCircle::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGCircle::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kCx:
if (const auto* cx = v.as<SkSVGLengthValue>()) {
if (const auto* cx = std::get_if<SkSVGLength>(&v)) {
this->setCx(*cx);
}
break;
case SkSVGAttribute::kCy:
if (const auto* cy = v.as<SkSVGLengthValue>()) {
if (const auto* cy = std::get_if<SkSVGLength>(&v)) {
this->setCy(*cy);
}
break;
case SkSVGAttribute::kR:
if (const auto* r = v.as<SkSVGLengthValue>()) {
if (const auto* r = std::get_if<SkSVGLength>(&v)) {
this->setR(*r);
}
break;

View File

@ -23,7 +23,7 @@ public:
void setR(const SkSVGLength&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;

View File

@ -26,7 +26,6 @@
#include "experimental/svg/model/SkSVGText.h"
#include "experimental/svg/model/SkSVGTypes.h"
#include "experimental/svg/model/SkSVGUse.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkString.h"
#include "include/private/SkTo.h"
@ -44,7 +43,7 @@ bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGPaintValue(paint));
node->setAttribute(attr, paint);
return true;
}
@ -56,7 +55,7 @@ bool SetColorAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGColorValue(color));
node->setAttribute(attr, color);
return true;
}
@ -68,7 +67,7 @@ bool SetIRIAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGStringValue(iri));
node->setAttribute(attr, iri);
return true;
}
@ -80,7 +79,7 @@ bool SetClipPathAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGClipValue(clip));
node->setAttribute(attr, clip);
return true;
}
@ -92,7 +91,7 @@ bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGPathValue(path));
node->setAttribute(attr, path);
return true;
}
@ -100,7 +99,7 @@ bool SetStringAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
const char* stringValue) {
SkString str(stringValue, strlen(stringValue));
SkSVGStringType strType = SkSVGStringType(str);
node->setAttribute(attr, SkSVGStringValue(strType));
node->setAttribute(attr, strType);
return true;
}
@ -112,7 +111,7 @@ bool SetTransformAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGTransformValue(transform));
node->setAttribute(attr, transform);
return true;
}
@ -124,7 +123,7 @@ bool SetLengthAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGLengthValue(length));
node->setAttribute(attr, length);
return true;
}
@ -136,7 +135,7 @@ bool SetNumberAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGNumberValue(number));
node->setAttribute(attr, number);
return true;
}
@ -148,7 +147,7 @@ bool SetViewBoxAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGViewBoxValue(viewBox));
node->setAttribute(attr, viewBox);
return true;
}
@ -160,7 +159,7 @@ bool SetLineCapAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGLineCapValue(lineCap));
node->setAttribute(attr, lineCap);
return true;
}
@ -172,7 +171,7 @@ bool SetLineJoinAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGLineJoinValue(lineJoin));
node->setAttribute(attr, lineJoin);
return true;
}
@ -184,7 +183,7 @@ bool SetSpreadMethodAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGSpreadMethodValue(spread));
node->setAttribute(attr, spread);
return true;
}
@ -196,7 +195,7 @@ bool SetPointsAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGPointsValue(points));
node->setAttribute(attr, points);
return true;
}
@ -208,7 +207,7 @@ bool SetFillRuleAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGFillRuleValue(fillRule));
node->setAttribute(attr, fillRule);
return true;
}
@ -220,7 +219,7 @@ bool SetVisibilityAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGVisibilityValue(visibility));
node->setAttribute(attr, visibility);
return true;
}
@ -232,7 +231,7 @@ bool SetDashArrayAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
return false;
}
node->setAttribute(attr, SkSVGDashArrayValue(dashArray));
node->setAttribute(attr, dashArray);
return true;
}

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGEllipse.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
SkSVGEllipse::SkSVGEllipse() : INHERITED(SkSVGTag::kEllipse) {}
@ -28,25 +27,25 @@ void SkSVGEllipse::setRy(const SkSVGLength& ry) {
fRy = ry;
}
void SkSVGEllipse::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGEllipse::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kCx:
if (const auto* cx = v.as<SkSVGLengthValue>()) {
if (const auto* cx = std::get_if<SkSVGLength>(&v)) {
this->setCx(*cx);
}
break;
case SkSVGAttribute::kCy:
if (const auto* cy = v.as<SkSVGLengthValue>()) {
if (const auto* cy = std::get_if<SkSVGLength>(&v)) {
this->setCy(*cy);
}
break;
case SkSVGAttribute::kRx:
if (const auto* rx = v.as<SkSVGLengthValue>()) {
if (const auto* rx = std::get_if<SkSVGLength>(&v)) {
this->setRx(*rx);
}
break;
case SkSVGAttribute::kRy:
if (const auto* ry = v.as<SkSVGLengthValue>()) {
if (const auto* ry = std::get_if<SkSVGLength>(&v)) {
this->setRy(*ry);
}
break;

View File

@ -24,7 +24,7 @@ public:
void setRy(const SkSVGLength&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;

View File

@ -8,7 +8,6 @@
#include "experimental/svg/model/SkSVGGradient.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGStop.h"
#include "experimental/svg/model/SkSVGValue.h"
void SkSVGGradient::setHref(const SkSVGStringType& href) {
fHref = std::move(href);
@ -22,20 +21,20 @@ void SkSVGGradient::setSpreadMethod(const SkSVGSpreadMethod& spread) {
fSpreadMethod = spread;
}
void SkSVGGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kGradientTransform:
if (const auto* t = v.as<SkSVGTransformValue>()) {
if (const auto* t = std::get_if<SkSVGTransformType>(&v)) {
this->setGradientTransform(*t);
}
break;
case SkSVGAttribute::kHref:
if (const auto* href = v.as<SkSVGStringValue>()) {
if (const auto* href = std::get_if<SkSVGStringType>(&v)) {
this->setHref(*href);
}
break;
case SkSVGAttribute::kSpreadMethod:
if (const auto* spread = v.as<SkSVGSpreadMethodValue>()) {
if (const auto* spread = std::get_if<SkSVGSpreadMethod>(&v)) {
this->setSpreadMethod(*spread);
}
break;

View File

@ -26,7 +26,7 @@ public:
protected:
explicit SkSVGGradient(SkSVGTag t) : INHERITED(t) {}
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const final;

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGLine.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
SkSVGLine::SkSVGLine() : INHERITED(SkSVGTag::kLine) {}
@ -28,25 +27,25 @@ void SkSVGLine::setY2(const SkSVGLength& y2) {
fY2 = y2;
}
void SkSVGLine::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGLine::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kX1:
if (const auto* x1 = v.as<SkSVGLengthValue>()) {
if (const auto* x1 = std::get_if<SkSVGLength>(&v)) {
this->setX1(*x1);
}
break;
case SkSVGAttribute::kY1:
if (const auto* y1 = v.as<SkSVGLengthValue>()) {
if (const auto* y1 = std::get_if<SkSVGLength>(&v)) {
this->setY1(*y1);
}
break;
case SkSVGAttribute::kX2:
if (const auto* x2 = v.as<SkSVGLengthValue>()) {
if (const auto* x2 = std::get_if<SkSVGLength>(&v)) {
this->setX2(*x2);
}
break;
case SkSVGAttribute::kY2:
if (const auto* y2 = v.as<SkSVGLengthValue>()) {
if (const auto* y2 = std::get_if<SkSVGLength>(&v)) {
this->setY2(*y2);
}
break;

View File

@ -24,7 +24,7 @@ public:
void setY2(const SkSVGLength&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGLinearGradient.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/effects/SkGradientShader.h"
SkSVGLinearGradient::SkSVGLinearGradient() : INHERITED(SkSVGTag::kLinearGradient) {}
@ -28,25 +27,25 @@ void SkSVGLinearGradient::setY2(const SkSVGLength& y2) {
fY2 = y2;
}
void SkSVGLinearGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGLinearGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kX1:
if (const auto* x1 = v.as<SkSVGLengthValue>()) {
if (const auto* x1 = std::get_if<SkSVGLength>(&v)) {
this->setX1(*x1);
}
break;
case SkSVGAttribute::kY1:
if (const auto* y1 = v.as<SkSVGLengthValue>()) {
if (const auto* y1 = std::get_if<SkSVGLength>(&v)) {
this->setY1(*y1);
}
break;
case SkSVGAttribute::kX2:
if (const auto* x2 = v.as<SkSVGLengthValue>()) {
if (const auto* x2 = std::get_if<SkSVGLength>(&v)) {
this->setX2(*x2);
}
break;
case SkSVGAttribute::kY2:
if (const auto* y2 = v.as<SkSVGLengthValue>()) {
if (const auto* y2 = std::get_if<SkSVGLength>(&v)) {
this->setY2(*y2);
}
break;

View File

@ -24,7 +24,7 @@ public:
void setY2(const SkSVGLength&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
sk_sp<SkShader> onMakeShader(const SkSVGRenderContext&,
const SkColor*, const SkScalar*, int count,

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGNode.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkMatrix.h"
#include "include/pathops/SkPathOps.h"
@ -56,7 +55,7 @@ bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
return visibility != SkSVGVisibility::Type::kHidden;
}
void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
this->onSetAttribute(attr, v);
}
@ -136,85 +135,85 @@ void SkSVGNode::setVisibility(const SkSVGVisibility& visibility) {
SetInheritedByDefault(fPresentationAttributes.fVisibility, visibility);
}
void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kClipPath:
if (const SkSVGClipValue* clip = v.as<SkSVGClipValue>()) {
if (const auto* clip = std::get_if<SkSVGClip>(&v)) {
this->setClipPath(*clip);
}
break;
case SkSVGAttribute::kClipRule:
if (const SkSVGFillRuleValue* clipRule = v.as<SkSVGFillRuleValue>()) {
if (const auto* clipRule = std::get_if<SkSVGFillRule>(&v)) {
this->setClipRule(*clipRule);
}
break;
case SkSVGAttribute::kColor:
if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) {
if (const auto* color = std::get_if<SkSVGColorType>(&v)) {
this->setColor(*color);
}
break;
case SkSVGAttribute::kFill:
if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) {
if (const auto* paint = std::get_if<SkSVGPaint>(&v)) {
this->setFill(*paint);
}
break;
case SkSVGAttribute::kFillOpacity:
if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) {
if (const auto* opacity = std::get_if<SkSVGNumberType>(&v)) {
this->setFillOpacity(*opacity);
}
break;
case SkSVGAttribute::kFillRule:
if (const SkSVGFillRuleValue* fillRule = v.as<SkSVGFillRuleValue>()) {
if (const auto* fillRule = std::get_if<SkSVGFillRule>(&v)) {
this->setFillRule(*fillRule);
}
break;
case SkSVGAttribute::kOpacity:
if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) {
if (const auto* opacity = std::get_if<SkSVGNumberType>(&v)) {
this->setOpacity(*opacity);
}
break;
case SkSVGAttribute::kStroke:
if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) {
if (const auto* paint = std::get_if<SkSVGPaint>(&v)) {
this->setStroke(*paint);
}
break;
case SkSVGAttribute::kStrokeDashArray:
if (const SkSVGDashArrayValue* dashArray = v.as<SkSVGDashArrayValue>()) {
if (const auto* dashArray = std::get_if<SkSVGDashArray>(&v)) {
this->setStrokeDashArray(*dashArray);
}
break;
case SkSVGAttribute::kStrokeDashOffset:
if (const SkSVGLengthValue* dashOffset= v.as<SkSVGLengthValue>()) {
if (const auto* dashOffset= std::get_if<SkSVGLength>(&v)) {
this->setStrokeDashOffset(*dashOffset);
}
break;
case SkSVGAttribute::kStrokeOpacity:
if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) {
if (const auto* opacity = std::get_if<SkSVGNumberType>(&v)) {
this->setStrokeOpacity(*opacity);
}
break;
case SkSVGAttribute::kStrokeLineCap:
if (const SkSVGLineCapValue* lineCap = v.as<SkSVGLineCapValue>()) {
if (const auto* lineCap = std::get_if<SkSVGLineCap>(&v)) {
this->setStrokeLineCap(*lineCap);
}
break;
case SkSVGAttribute::kStrokeLineJoin:
if (const SkSVGLineJoinValue* lineJoin = v.as<SkSVGLineJoinValue>()) {
if (const auto* lineJoin = std::get_if<SkSVGLineJoin>(&v)) {
this->setStrokeLineJoin(*lineJoin);
}
break;
case SkSVGAttribute::kStrokeMiterLimit:
if (const SkSVGNumberValue* miterLimit = v.as<SkSVGNumberValue>()) {
if (const auto* miterLimit = std::get_if<SkSVGNumberType>(&v)) {
this->setStrokeMiterLimit(*miterLimit);
}
break;
case SkSVGAttribute::kStrokeWidth:
if (const SkSVGLengthValue* strokeWidth = v.as<SkSVGLengthValue>()) {
if (const auto* strokeWidth = std::get_if<SkSVGLength>(&v)) {
this->setStrokeWidth(*strokeWidth);
}
break;
case SkSVGAttribute::kVisibility:
if (const SkSVGVisibilityValue* visibility = v.as<SkSVGVisibilityValue>()) {
if (const auto* visibility = std::get_if<SkSVGVisibility>(&v)) {
this->setVisibility(*visibility);
}
break;

View File

@ -16,7 +16,6 @@ class SkMatrix;
class SkPaint;
class SkPath;
class SkSVGRenderContext;
class SkSVGValue;
enum class SkSVGTag {
kCircle,
@ -50,7 +49,7 @@ public:
bool asPaint(const SkSVGRenderContext&, SkPaint*) const;
SkPath asPath(const SkSVGRenderContext&) const;
void setAttribute(SkSVGAttribute, const SkSVGValue&);
void setAttribute(SkSVGAttribute, const SkSVGAttributeValue&);
void setClipPath(const SkSVGClip&);
void setClipRule(const SkSVGFillRule&);
@ -86,7 +85,7 @@ protected:
virtual SkPath onAsPath(const SkSVGRenderContext&) const = 0;
virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
virtual void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&);
virtual bool hasChildren() const { return false; }

View File

@ -7,16 +7,15 @@
#include "experimental/svg/model/SkSVGPath.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
void SkSVGPath::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGPath::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kD:
if (const auto* path = v.as<SkSVGPathValue>()) {
if (const auto* path = std::get_if<SkPath>(&v)) {
this->setPath(*path);
}
break;

View File

@ -19,7 +19,7 @@ public:
void setPath(const SkPath& path) { fPath = path; }
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;

View File

@ -8,7 +8,6 @@
#include "experimental/svg/model/SkSVGPattern.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkShader.h"
@ -38,35 +37,35 @@ void SkSVGPattern::setPatternTransform(const SkSVGTransformType& patternTransfor
fAttributes.fPatternTransform.set(patternTransform);
}
void SkSVGPattern::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGPattern::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kX:
if (const auto* x = v.as<SkSVGLengthValue>()) {
if (const auto* x = std::get_if<SkSVGLength>(&v)) {
this->setX(*x);
}
break;
case SkSVGAttribute::kY:
if (const auto* y = v.as<SkSVGLengthValue>()) {
if (const auto* y = std::get_if<SkSVGLength>(&v)) {
this->setY(*y);
}
break;
case SkSVGAttribute::kWidth:
if (const auto* w = v.as<SkSVGLengthValue>()) {
if (const auto* w = std::get_if<SkSVGLength>(&v)) {
this->setWidth(*w);
}
break;
case SkSVGAttribute::kHeight:
if (const auto* h = v.as<SkSVGLengthValue>()) {
if (const auto* h = std::get_if<SkSVGLength>(&v)) {
this->setHeight(*h);
}
break;
case SkSVGAttribute::kHref:
if (const auto* href = v.as<SkSVGStringValue>()) {
if (const auto* href = std::get_if<SkSVGStringType>(&v)) {
this->setHref(*href);
}
break;
case SkSVGAttribute::kPatternTransform:
if (const auto* t = v.as<SkSVGTransformValue>()) {
if (const auto* t = std::get_if<SkSVGTransformType>(&v)) {
this->setPatternTransform(*t);
}
break;

View File

@ -31,7 +31,7 @@ public:
protected:
SkSVGPattern();
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const override;

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGPoly.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
#include "src/core/SkTLazy.h"
@ -20,10 +19,10 @@ void SkSVGPoly::setPoints(const SkSVGPointsType& pts) {
this->tag() == SkSVGTag::kPolygon); // only polygons are auto-closed
}
void SkSVGPoly::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGPoly::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kPoints:
if (const auto* pts = v.as<SkSVGPointsValue>()) {
if (const auto* pts = std::get_if<SkSVGPointsType>(&v)) {
this->setPoints(*pts);
}
break;

View File

@ -27,7 +27,7 @@ public:
void setPoints(const SkSVGPointsType&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGRadialGradient.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/effects/SkGradientShader.h"
SkSVGRadialGradient::SkSVGRadialGradient() : INHERITED(SkSVGTag::kRadialGradient) {}
@ -32,30 +31,30 @@ void SkSVGRadialGradient::setFy(const SkSVGLength& fy) {
fFy.set(fy);
}
void SkSVGRadialGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGRadialGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kCx:
if (const auto* cx = v.as<SkSVGLengthValue>()) {
if (const auto* cx = std::get_if<SkSVGLength>(&v)) {
this->setCx(*cx);
}
break;
case SkSVGAttribute::kCy:
if (const auto* cy = v.as<SkSVGLengthValue>()) {
if (const auto* cy = std::get_if<SkSVGLength>(&v)) {
this->setCy(*cy);
}
break;
case SkSVGAttribute::kR:
if (const auto* r = v.as<SkSVGLengthValue>()) {
if (const auto* r = std::get_if<SkSVGLength>(&v)) {
this->setR(*r);
}
break;
case SkSVGAttribute::kFx:
if (const auto* fx = v.as<SkSVGLengthValue>()) {
if (const auto* fx = std::get_if<SkSVGLength>(&v)) {
this->setFx(*fx);
}
break;
case SkSVGAttribute::kFy:
if (const auto* fy = v.as<SkSVGLengthValue>()) {
if (const auto* fy = std::get_if<SkSVGLength>(&v)) {
this->setFy(*fy);
}
break;

View File

@ -25,7 +25,7 @@ public:
void setFy(const SkSVGLength&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
sk_sp<SkShader> onMakeShader(const SkSVGRenderContext&,
const SkColor*, const SkScalar*, int count,

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGRect.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkRect.h"
@ -37,35 +36,35 @@ void SkSVGRect::setRy(const SkSVGLength& ry) {
fRy = ry;
}
void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kX:
if (const auto* x = v.as<SkSVGLengthValue>()) {
if (const auto* x = std::get_if<SkSVGLength>(&v)) {
this->setX(*x);
}
break;
case SkSVGAttribute::kY:
if (const auto* y = v.as<SkSVGLengthValue>()) {
if (const auto* y = std::get_if<SkSVGLength>(&v)) {
this->setY(*y);
}
break;
case SkSVGAttribute::kWidth:
if (const auto* w = v.as<SkSVGLengthValue>()) {
if (const auto* w = std::get_if<SkSVGLength>(&v)) {
this->setWidth(*w);
}
break;
case SkSVGAttribute::kHeight:
if (const auto* h = v.as<SkSVGLengthValue>()) {
if (const auto* h = std::get_if<SkSVGLength>(&v)) {
this->setHeight(*h);
}
break;
case SkSVGAttribute::kRx:
if (const auto* rx = v.as<SkSVGLengthValue>()) {
if (const auto* rx = std::get_if<SkSVGLength>(&v)) {
this->setRx(*rx);
}
break;
case SkSVGAttribute::kRy:
if (const auto* ry = v.as<SkSVGLengthValue>()) {
if (const auto* ry = std::get_if<SkSVGLength>(&v)) {
this->setRy(*ry);
}
break;

View File

@ -26,7 +26,7 @@ public:
void setRy(const SkSVGLength&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGSVG.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
SkSVGSVG::SkSVGSVG() : INHERITED(SkSVGTag::kSvg) { }
@ -64,30 +63,30 @@ void SkSVGSVG::setViewBox(const SkSVGViewBoxType& vb) {
fViewBox.set(vb);
}
void SkSVGSVG::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGSVG::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kX:
if (const auto* x = v.as<SkSVGLengthValue>()) {
if (const auto* x = std::get_if<SkSVGLength>(&v)) {
this->setX(*x);
}
break;
case SkSVGAttribute::kY:
if (const auto* y = v.as<SkSVGLengthValue>()) {
if (const auto* y = std::get_if<SkSVGLength>(&v)) {
this->setY(*y);
}
break;
case SkSVGAttribute::kWidth:
if (const auto* w = v.as<SkSVGLengthValue>()) {
if (const auto* w = std::get_if<SkSVGLength>(&v)) {
this->setWidth(*w);
}
break;
case SkSVGAttribute::kHeight:
if (const auto* h = v.as<SkSVGLengthValue>()) {
if (const auto* h = std::get_if<SkSVGLength>(&v)) {
this->setHeight(*h);
}
break;
case SkSVGAttribute::kViewBox:
if (const auto* vb = v.as<SkSVGViewBoxValue>()) {
if (const auto* vb = std::get_if<SkSVGViewBoxType>(&v)) {
this->setViewBox(*vb);
}
break;

View File

@ -31,7 +31,7 @@ public:
protected:
bool onPrepareToRender(SkSVGRenderContext*) const override;
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
private:
SkSVGSVG();

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGStop.h"
#include "experimental/svg/model/SkSVGValue.h"
SkSVGStop::SkSVGStop() : INHERITED(SkSVGTag::kStop) {}
@ -23,20 +22,20 @@ void SkSVGStop::setStopOpacity(const SkSVGNumberType& opacity) {
fStopOpacity = SkTPin<SkScalar>(opacity, 0, 1);
}
void SkSVGStop::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGStop::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kOffset:
if (const auto* offset = v.as<SkSVGLengthValue>()) {
if (const auto* offset = std::get_if<SkSVGLength>(&v)) {
this->setOffset(*offset);
}
break;
case SkSVGAttribute::kStopColor:
if (const auto* color = v.as<SkSVGColorValue>()) {
if (const auto* color = std::get_if<SkSVGColorType>(&v)) {
this->setStopColor(*color);
}
break;
case SkSVGAttribute::kStopOpacity:
if (const auto* opacity = v.as<SkSVGNumberValue>()) {
if (const auto* opacity = std::get_if<SkSVGNumberType>(&v)) {
this->setStopOpacity(*opacity);
}
break;

View File

@ -29,7 +29,7 @@ public:
void setStopOpacity(const SkSVGNumberType&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
private:
SkSVGStop();

View File

@ -8,7 +8,6 @@
#include "experimental/svg/model/SkSVGText.h"
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
SkSVGText::SkSVGText() : INHERITED(SkSVGTag::kText) {}
@ -48,35 +47,35 @@ SkPath SkSVGText::onAsPath(const SkSVGRenderContext& ctx) const {
return path;
}
void SkSVGText::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGText::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kX:
if (const auto* x = v.as<SkSVGLengthValue>()) {
if (const auto* x = std::get_if<SkSVGLength>(&v)) {
this->setX(*x);
}
break;
case SkSVGAttribute::kY:
if (const auto* y = v.as<SkSVGLengthValue>()) {
if (const auto* y = std::get_if<SkSVGLength>(&v)) {
this->setY(*y);
}
break;
case SkSVGAttribute::kText:
if (const auto* text = v.as<SkSVGStringValue>()) {
if (const auto* text = std::get_if<SkSVGStringType>(&v)) {
this->setText(*text);
}
break;
case SkSVGAttribute::kTextAnchor:
if (const auto* text_anchor = v.as<SkSVGStringValue>()) {
if (const auto* text_anchor = std::get_if<SkSVGStringType>(&v)) {
this->setTextAnchor(*text_anchor);
}
break;
case SkSVGAttribute::kFontFamily:
if (const auto* font_family = v.as<SkSVGStringValue>()) {
if (const auto* font_family = std::get_if<SkSVGStringType>(&v)) {
this->setFontFamily(*font_family);
}
break;
case SkSVGAttribute::kFontSize:
if (const auto* font_size = v.as<SkSVGLengthValue>()) {
if (const auto* font_size = std::get_if<SkSVGLength>(&v)) {
this->setFontSize(*font_size);
}
break;

View File

@ -29,7 +29,7 @@ class SkSVGText final : public SkSVGShape {
void setTextAnchor(const SkSVGStringType&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGTransformableNode.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h"
SkSVGTransformableNode::SkSVGTransformableNode(SkSVGTag tag)
@ -24,10 +23,10 @@ bool SkSVGTransformableNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
return this->INHERITED::onPrepareToRender(ctx);
}
void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGTransformableNode::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kTransform:
if (const auto* transform = v.as<SkSVGTransformValue>()) {
if (const auto* transform = std::get_if<SkSVGTransformType>(&v)) {
this->setTransform(*transform);
}
break;

View File

@ -22,7 +22,7 @@ protected:
bool onPrepareToRender(SkSVGRenderContext*) const override;
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
void mapToParent(SkPath*) const;

View File

@ -18,6 +18,8 @@
#include "include/core/SkTypes.h"
#include "include/private/SkTDArray.h"
#include <variant>
using SkSVGColorType = SkColor;
using SkSVGNumberType = SkScalar;
using SkSVGStringType = SkString;
@ -279,4 +281,24 @@ private:
SkTDArray<SkSVGLength> fDashArray;
};
using SkSVGAttributeValue =
std::variant<
SkPath, // TODO: hmm, why is this not aliased?
SkSVGClip,
SkSVGColorType,
SkSVGDashArray,
SkSVGFillRule,
SkSVGLength,
SkSVGLineCap,
SkSVGLineJoin,
SkSVGNumberType,
SkSVGPaint,
SkSVGPointsType,
SkSVGStringType,
SkSVGSpreadMethod,
SkSVGTransformType,
SkSVGViewBoxType,
SkSVGVisibility
>;
#endif // SkSVGTypes_DEFINED

View File

@ -8,7 +8,6 @@
#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) {}
@ -29,20 +28,20 @@ void SkSVGUse::setY(const SkSVGLength& y) {
fY = y;
}
void SkSVGUse::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
void SkSVGUse::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) {
case SkSVGAttribute::kHref:
if (const auto* href = v.as<SkSVGStringValue>()) {
if (const auto* href = std::get_if<SkSVGStringType>(&v)) {
this->setHref(*href);
}
break;
case SkSVGAttribute::kX:
if (const auto* x = v.as<SkSVGLengthValue>()) {
if (const auto* x = std::get_if<SkSVGLength>(&v)) {
this->setX(*x);
}
break;
case SkSVGAttribute::kY:
if (const auto* y = v.as<SkSVGLengthValue>()) {
if (const auto* y = std::get_if<SkSVGLength>(&v)) {
this->setY(*y);
}
break;

View File

@ -28,7 +28,7 @@ public:
void setY(const SkSVGLength&);
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
void onSetAttribute(SkSVGAttribute, const SkSVGAttributeValue&) override;
bool onPrepareToRender(SkSVGRenderContext*) const override;
void onRender(const SkSVGRenderContext&) const override;

View File

@ -1,7 +0,0 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

View File

@ -1,95 +0,0 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkSVGValue_DEFINED
#define SkSVGValue_DEFINED
#include "experimental/svg/model/SkSVGTypes.h"
#include "include/core/SkColor.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPath.h"
#include "include/core/SkTypes.h"
#include "include/private/SkNoncopyable.h"
class SkSVGValue : public SkNoncopyable {
public:
enum class Type {
kClip,
kColor,
kDashArray,
kFillRule,
kLength,
kLineCap,
kLineJoin,
kNumber,
kPaint,
kPath,
kPoints,
kSpreadMethod,
kString,
kTransform,
kViewBox,
kVisibility,
};
Type type() const { return fType; }
template <typename T>
const T* as() const {
return fType == T::TYPE ? static_cast<const T*>(this) : nullptr;
}
protected:
SkSVGValue(Type t) : fType(t) { }
private:
Type fType;
typedef SkNoncopyable INHERITED;
};
template <typename T, SkSVGValue::Type ValueType>
class SkSVGWrapperValue final : public SkSVGValue {
public:
static constexpr Type TYPE = ValueType;
explicit SkSVGWrapperValue(const T& v)
: INHERITED(ValueType)
, fWrappedValue(v) { }
operator const T&() const { return fWrappedValue; }
const T* operator->() const { return &fWrappedValue; }
private:
// Stack-only
void* operator new(size_t) = delete;
void* operator new(size_t, void*) = delete;
const T& fWrappedValue;
typedef SkSVGValue INHERITED;
};
using SkSVGClipValue = SkSVGWrapperValue<SkSVGClip , SkSVGValue::Type::kClip >;
using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >;
using SkSVGFillRuleValue = SkSVGWrapperValue<SkSVGFillRule , SkSVGValue::Type::kFillRule >;
using SkSVGLengthValue = SkSVGWrapperValue<SkSVGLength , SkSVGValue::Type::kLength >;
using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue::Type::kPath >;
using SkSVGTransformValue = SkSVGWrapperValue<SkSVGTransformType, SkSVGValue::Type::kTransform >;
using SkSVGViewBoxValue = SkSVGWrapperValue<SkSVGViewBoxType , SkSVGValue::Type::kViewBox >;
using SkSVGPaintValue = SkSVGWrapperValue<SkSVGPaint , SkSVGValue::Type::kPaint >;
using SkSVGLineCapValue = SkSVGWrapperValue<SkSVGLineCap , SkSVGValue::Type::kLineCap >;
using SkSVGLineJoinValue = SkSVGWrapperValue<SkSVGLineJoin , SkSVGValue::Type::kLineJoin >;
using SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >;
using SkSVGPointsValue = SkSVGWrapperValue<SkSVGPointsType , SkSVGValue::Type::kPoints >;
using SkSVGStringValue = SkSVGWrapperValue<SkSVGStringType , SkSVGValue::Type::kString >;
using SkSVGSpreadMethodValue = SkSVGWrapperValue<SkSVGSpreadMethod ,
SkSVGValue::Type::kSpreadMethod>;
using SkSVGVisibilityValue = SkSVGWrapperValue<SkSVGVisibility , SkSVGValue::Type::kVisibility>;
using SkSVGDashArrayValue = SkSVGWrapperValue<SkSVGDashArray , SkSVGValue::Type::kDashArray >;
#endif // SkSVGValue_DEFINED