[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/SkSVGText.cpp",
"experimental/svg/model/SkSVGTransformableNode.cpp", "experimental/svg/model/SkSVGTransformableNode.cpp",
"experimental/svg/model/SkSVGUse.cpp", "experimental/svg/model/SkSVGUse.cpp",
"experimental/svg/model/SkSVGValue.cpp",
] ]
deps = [ deps = [
":skia", ":skia",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,7 +26,7 @@ public:
protected: protected:
explicit SkSVGGradient(SkSVGTag t) : INHERITED(t) {} 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; bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const final;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,6 @@
#include "experimental/svg/model/SkSVGPoly.h" #include "experimental/svg/model/SkSVGPoly.h"
#include "experimental/svg/model/SkSVGRenderContext.h" #include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
#include "src/core/SkTLazy.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 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) { switch (attr) {
case SkSVGAttribute::kPoints: case SkSVGAttribute::kPoints:
if (const auto* pts = v.as<SkSVGPointsValue>()) { if (const auto* pts = std::get_if<SkSVGPointsType>(&v)) {
this->setPoints(*pts); this->setPoints(*pts);
} }
break; break;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,6 +18,8 @@
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#include "include/private/SkTDArray.h" #include "include/private/SkTDArray.h"
#include <variant>
using SkSVGColorType = SkColor; using SkSVGColorType = SkColor;
using SkSVGNumberType = SkScalar; using SkSVGNumberType = SkScalar;
using SkSVGStringType = SkString; using SkSVGStringType = SkString;
@ -279,4 +281,24 @@ private:
SkTDArray<SkSVGLength> fDashArray; 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 #endif // SkSVGTypes_DEFINED

View File

@ -8,7 +8,6 @@
#include "experimental/svg/model/SkSVGUse.h" #include "experimental/svg/model/SkSVGUse.h"
#include "experimental/svg/model/SkSVGRenderContext.h" #include "experimental/svg/model/SkSVGRenderContext.h"
#include "experimental/svg/model/SkSVGValue.h"
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
SkSVGUse::SkSVGUse() : INHERITED(SkSVGTag::kUse) {} SkSVGUse::SkSVGUse() : INHERITED(SkSVGTag::kUse) {}
@ -29,20 +28,20 @@ void SkSVGUse::setY(const SkSVGLength& y) {
fY = y; fY = y;
} }
void SkSVGUse::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { void SkSVGUse::onSetAttribute(SkSVGAttribute attr, const SkSVGAttributeValue& v) {
switch (attr) { switch (attr) {
case SkSVGAttribute::kHref: case SkSVGAttribute::kHref:
if (const auto* href = v.as<SkSVGStringValue>()) { if (const auto* href = std::get_if<SkSVGStringType>(&v)) {
this->setHref(*href); this->setHref(*href);
} }
break; break;
case SkSVGAttribute::kX: case SkSVGAttribute::kX:
if (const auto* x = v.as<SkSVGLengthValue>()) { if (const auto* x = std::get_if<SkSVGLength>(&v)) {
this->setX(*x); this->setX(*x);
} }
break; break;
case SkSVGAttribute::kY: case SkSVGAttribute::kY:
if (const auto* y = v.as<SkSVGLengthValue>()) { if (const auto* y = std::get_if<SkSVGLength>(&v)) {
this->setY(*y); this->setY(*y);
} }
break; break;

View File

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