Index: experimental/svg/model/SkSVGLinearGradient.cpp |
diff --git a/experimental/svg/model/SkSVGLinearGradient.cpp b/experimental/svg/model/SkSVGLinearGradient.cpp |
index 20c27f540c4474846163dc21fc670b3e31e04c43..289c5e327602c615e984e38716eb3c12c8a24439 100644 |
--- a/experimental/svg/model/SkSVGLinearGradient.cpp |
+++ b/experimental/svg/model/SkSVGLinearGradient.cpp |
@@ -17,6 +17,10 @@ void SkSVGLinearGradient::setHref(const SkSVGStringType& href) { |
fHref = std::move(href); |
} |
+void SkSVGLinearGradient::setSpreadMethod(const SkSVGSpreadMethod& spread) { |
+ fSpreadMethod = spread; |
+} |
+ |
void SkSVGLinearGradient::setX1(const SkSVGLength& x1) { |
fX1 = x1; |
} |
@@ -40,6 +44,11 @@ void SkSVGLinearGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& |
this->setHref(*href); |
} |
break; |
+ case SkSVGAttribute::kSpreadMethod: |
+ if (const auto* spread = v.as<SkSVGSpreadMethodValue>()) { |
+ this->setSpreadMethod(*spread); |
+ } |
+ break; |
case SkSVGAttribute::kX1: |
if (const auto* x1 = v.as<SkSVGLengthValue>()) { |
this->setX1(*x1); |
@@ -110,10 +119,17 @@ bool SkSVGLinearGradient::onAsPaint(const SkSVGRenderContext& ctx, SkPaint* pain |
// * stop (lazy?) sorting |
// * href loop detection |
// * href attribute inheritance (not just color stops) |
- // * spreadMethods support |
// * objectBoundingBox units support |
+ static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kPad) == |
+ SkShader::kClamp_TileMode, "SkSVGSpreadMethod::Type is out of sync"); |
+ static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kRepeat) == |
+ SkShader::kRepeat_TileMode, "SkSVGSpreadMethod::Type is out of sync"); |
+ static_assert(static_cast<SkShader::TileMode>(SkSVGSpreadMethod::Type::kReflect) == |
+ SkShader::kMirror_TileMode, "SkSVGSpreadMethod::Type is out of sync"); |
+ const auto tileMode = static_cast<SkShader::TileMode>(fSpreadMethod.type()); |
+ |
paint->setShader(SkGradientShader::MakeLinear(pts, colors.begin(), pos.begin(), colors.count(), |
- SkShader::kClamp_TileMode)); |
+ tileMode)); |
return true; |
} |