From ceb93abddc81ccc0b4f93d958135632ed4cebfd4 Mon Sep 17 00:00:00 2001 From: fmalita Date: Tue, 13 Sep 2016 13:59:05 -0700 Subject: [PATCH] [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 --- experimental/svg/model/SkSVGAttribute.h | 1 + experimental/svg/model/SkSVGDOM.cpp | 63 +++++++++++++------------- experimental/svg/model/SkSVGLinearGradient.cpp | 11 ++++- experimental/svg/model/SkSVGLinearGradient.h | 6 ++- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/experimental/svg/model/SkSVGAttribute.h b/experimental/svg/model/SkSVGAttribute.h index 13a6041..478a26b 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 2694473..f467c5e 100644 --- a/experimental/svg/model/SkSVGDOM.cpp +++ b/experimental/svg/model/SkSVGDOM.cpp @@ -251,37 +251,38 @@ struct AttrParseInfo { }; SortedDictionaryEntry 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(*)()> gTagFactories[] = { diff --git a/experimental/svg/model/SkSVGLinearGradient.cpp b/experimental/svg/model/SkSVGLinearGradient.cpp index 289c5e3..4bbed1c 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()) { + this->setGradientTransform(*t); + } + break; case SkSVGAttribute::kHref: if (const auto* href = v.as()) { this->setHref(*href); @@ -130,6 +139,6 @@ bool SkSVGLinearGradient::onAsPaint(const SkSVGRenderContext& ctx, SkPaint* pain const auto tileMode = static_cast(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 e12b524..2e4e3f5 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; }; -- 2.7.4