aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2016-09-13 13:59:05 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-13 13:59:05 -0700
commitceb93abddc81ccc0b4f93d958135632ed4cebfd4 (patch)
tree5c5328d6a8d06ebeaa69910de4cb3f577dde6db5 /experimental
parent357f9d2032d65a3be28cd93af9d99c0de19a2d0f (diff)
[SVGDom] Linear gradient 'gradientTransform' support
R=stephana@google.com,robertphillips@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2339533002 Review-Url: https://codereview.chromium.org/2339533002
Diffstat (limited to 'experimental')
-rw-r--r--experimental/svg/model/SkSVGAttribute.h1
-rw-r--r--experimental/svg/model/SkSVGDOM.cpp63
-rw-r--r--experimental/svg/model/SkSVGLinearGradient.cpp11
-rw-r--r--experimental/svg/model/SkSVGLinearGradient.h6
4 files changed, 47 insertions, 34 deletions
diff --git a/experimental/svg/model/SkSVGAttribute.h b/experimental/svg/model/SkSVGAttribute.h
index 13a6041b4b..478a26b261 100644
--- a/experimental/svg/model/SkSVGAttribute.h
+++ b/experimental/svg/model/SkSVGAttribute.h
@@ -19,6 +19,7 @@ enum class SkSVGAttribute {
kD,
kFill,
kFillOpacity,
+ kGradientTransform,
kHeight,
kHref,
kOffset,
diff --git a/experimental/svg/model/SkSVGDOM.cpp b/experimental/svg/model/SkSVGDOM.cpp
index 26944737f1..f467c5e6d0 100644
--- a/experimental/svg/model/SkSVGDOM.cpp
+++ b/experimental/svg/model/SkSVGDOM.cpp
@@ -251,37 +251,38 @@ struct AttrParseInfo {
};
SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
- { "cx" , { SkSVGAttribute::kCx , SetLengthAttribute }},
- { "cy" , { SkSVGAttribute::kCy , SetLengthAttribute }},
- { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
- { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }},
- { "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute }},
- { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }},
- { "offset" , { SkSVGAttribute::kOffset , SetLengthAttribute }},
- { "opacity" , { SkSVGAttribute::kOpacity , SetNumberAttribute }},
- { "points" , { SkSVGAttribute::kPoints , SetPointsAttribute }},
- { "r" , { SkSVGAttribute::kR , SetLengthAttribute }},
- { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute }},
- { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute }},
- { "spreadMethod" , { SkSVGAttribute::kSpreadMethod , SetSpreadMethodAttribute }},
- { "stop-color" , { SkSVGAttribute::kStopColor , SetColorAttribute }},
- { "stop-opacity" , { SkSVGAttribute::kStopOpacity , SetNumberAttribute }},
- { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }},
- { "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute }},
- { "stroke-linejoin", { SkSVGAttribute::kStrokeLineJoin, SetLineJoinAttribute }},
- { "stroke-opacity" , { SkSVGAttribute::kStrokeOpacity , SetNumberAttribute }},
- { "stroke-width" , { SkSVGAttribute::kStrokeWidth , SetLengthAttribute }},
- { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }},
- { "transform" , { SkSVGAttribute::kTransform , SetTransformAttribute }},
- { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }},
- { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }},
- { "x" , { SkSVGAttribute::kX , SetLengthAttribute }},
- { "x1" , { SkSVGAttribute::kX1 , SetLengthAttribute }},
- { "x2" , { SkSVGAttribute::kX2 , SetLengthAttribute }},
- { "xlink:href" , { SkSVGAttribute::kHref , SetIRIAttribute }},
- { "y" , { SkSVGAttribute::kY , SetLengthAttribute }},
- { "y1" , { SkSVGAttribute::kY1 , SetLengthAttribute }},
- { "y2" , { SkSVGAttribute::kY2 , SetLengthAttribute }},
+ { "cx" , { SkSVGAttribute::kCx , SetLengthAttribute }},
+ { "cy" , { SkSVGAttribute::kCy , SetLengthAttribute }},
+ { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
+ { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }},
+ { "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute }},
+ { "gradientTransform", { SkSVGAttribute::kGradientTransform, SetTransformAttribute }},
+ { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }},
+ { "offset" , { SkSVGAttribute::kOffset , SetLengthAttribute }},
+ { "opacity" , { SkSVGAttribute::kOpacity , SetNumberAttribute }},
+ { "points" , { SkSVGAttribute::kPoints , SetPointsAttribute }},
+ { "r" , { SkSVGAttribute::kR , SetLengthAttribute }},
+ { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute }},
+ { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute }},
+ { "spreadMethod" , { SkSVGAttribute::kSpreadMethod , SetSpreadMethodAttribute }},
+ { "stop-color" , { SkSVGAttribute::kStopColor , SetColorAttribute }},
+ { "stop-opacity" , { SkSVGAttribute::kStopOpacity , SetNumberAttribute }},
+ { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }},
+ { "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute }},
+ { "stroke-linejoin" , { SkSVGAttribute::kStrokeLineJoin , SetLineJoinAttribute }},
+ { "stroke-opacity" , { SkSVGAttribute::kStrokeOpacity , SetNumberAttribute }},
+ { "stroke-width" , { SkSVGAttribute::kStrokeWidth , SetLengthAttribute }},
+ { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }},
+ { "transform" , { SkSVGAttribute::kTransform , SetTransformAttribute }},
+ { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }},
+ { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }},
+ { "x" , { SkSVGAttribute::kX , SetLengthAttribute }},
+ { "x1" , { SkSVGAttribute::kX1 , SetLengthAttribute }},
+ { "x2" , { SkSVGAttribute::kX2 , SetLengthAttribute }},
+ { "xlink:href" , { SkSVGAttribute::kHref , SetIRIAttribute }},
+ { "y" , { SkSVGAttribute::kY , SetLengthAttribute }},
+ { "y1" , { SkSVGAttribute::kY1 , SetLengthAttribute }},
+ { "y2" , { SkSVGAttribute::kY2 , SetLengthAttribute }},
};
SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = {
diff --git a/experimental/svg/model/SkSVGLinearGradient.cpp b/experimental/svg/model/SkSVGLinearGradient.cpp
index 289c5e3276..4bbed1c354 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::setGradientTransform(const SkSVGTransformType& t) {
+ fGradientTransform = t;
+}
+
void SkSVGLinearGradient::setSpreadMethod(const SkSVGSpreadMethod& spread) {
fSpreadMethod = spread;
}
@@ -39,6 +43,11 @@ void SkSVGLinearGradient::setY2(const SkSVGLength& y2) {
void SkSVGLinearGradient::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
switch (attr) {
+ case SkSVGAttribute::kGradientTransform:
+ if (const auto* t = v.as<SkSVGTransformValue>()) {
+ this->setGradientTransform(*t);
+ }
+ break;
case SkSVGAttribute::kHref:
if (const auto* href = v.as<SkSVGStringValue>()) {
this->setHref(*href);
@@ -130,6 +139,6 @@ bool SkSVGLinearGradient::onAsPaint(const SkSVGRenderContext& ctx, SkPaint* pain
const auto tileMode = static_cast<SkShader::TileMode>(fSpreadMethod.type());
paint->setShader(SkGradientShader::MakeLinear(pts, colors.begin(), pos.begin(), colors.count(),
- tileMode));
+ tileMode, 0, &fGradientTransform.value()));
return true;
}
diff --git a/experimental/svg/model/SkSVGLinearGradient.h b/experimental/svg/model/SkSVGLinearGradient.h
index e12b5245e8..2e4e3f5dee 100644
--- a/experimental/svg/model/SkSVGLinearGradient.h
+++ b/experimental/svg/model/SkSVGLinearGradient.h
@@ -19,6 +19,7 @@ public:
}
void setHref(const SkSVGStringType&);
+ void setGradientTransform(const SkSVGTransformType&);
void setSpreadMethod(const SkSVGSpreadMethod&);
void setX1(const SkSVGLength&);
void setY1(const SkSVGLength&);
@@ -42,8 +43,9 @@ private:
SkSVGLength fX2 = SkSVGLength(100, SkSVGLength::Unit::kPercentage);
SkSVGLength fY2 = SkSVGLength(0 , SkSVGLength::Unit::kPercentage);
- SkSVGStringType fHref;
- SkSVGSpreadMethod fSpreadMethod = SkSVGSpreadMethod(SkSVGSpreadMethod::Type::kPad);
+ SkSVGStringType fHref;
+ SkSVGTransformType fGradientTransform = SkSVGTransformType(SkMatrix::I());
+ SkSVGSpreadMethod fSpreadMethod = SkSVGSpreadMethod(SkSVGSpreadMethod::Type::kPad);
typedef SkSVGHiddenContainer INHERITED;
};