[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
This commit is contained in:
parent
357f9d2032
commit
ceb93abddc
@ -19,6 +19,7 @@ enum class SkSVGAttribute {
|
||||
kD,
|
||||
kFill,
|
||||
kFillOpacity,
|
||||
kGradientTransform,
|
||||
kHeight,
|
||||
kHref,
|
||||
kOffset,
|
||||
|
@ -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[] = {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user