Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: experimental/svg/model/SkSVGLinearGradient.cpp

Issue 2337203002: [SVGDom] Linear gradient 'spreadMethod' support (Closed)
Patch Set: review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/svg/model/SkSVGLinearGradient.h ('k') | experimental/svg/model/SkSVGTypes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « experimental/svg/model/SkSVGLinearGradient.h ('k') | experimental/svg/model/SkSVGTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698