[SVGDom] Add 'stroke-dashoffset' support
https://www.w3.org/TR/SVG/painting.html#StrokeDashoffsetProperty Change-Id: Ia25d0048a56ac3835cabcb4e1794d91667367d7c Reviewed-on: https://skia-review.googlesource.com/59820 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
parent
7a0ebfc033
commit
e1dadd74f8
@ -17,6 +17,7 @@ SkSVGPresentationAttributes SkSVGPresentationAttributes::MakeInitial() {
|
||||
|
||||
result.fStroke.set(SkSVGPaint(SkSVGPaint::Type::kNone));
|
||||
result.fStrokeDashArray.set(SkSVGDashArray(SkSVGDashArray::Type::kNone));
|
||||
result.fStrokeDashOffset.set(SkSVGLength(0));
|
||||
result.fStrokeLineCap.set(SkSVGLineCap(SkSVGLineCap::Type::kButt));
|
||||
result.fStrokeLineJoin.set(SkSVGLineJoin(SkSVGLineJoin::Type::kMiter));
|
||||
result.fStrokeMiterLimit.set(SkSVGNumberType(4));
|
||||
|
@ -39,6 +39,7 @@ enum class SkSVGAttribute {
|
||||
kStopOpacity,
|
||||
kStroke,
|
||||
kStrokeDashArray,
|
||||
kStrokeDashOffset,
|
||||
kStrokeOpacity,
|
||||
kStrokeLineCap,
|
||||
kStrokeLineJoin,
|
||||
@ -70,6 +71,7 @@ struct SkSVGPresentationAttributes {
|
||||
|
||||
SkTLazy<SkSVGPaint> fStroke;
|
||||
SkTLazy<SkSVGDashArray> fStrokeDashArray;
|
||||
SkTLazy<SkSVGLength> fStrokeDashOffset;
|
||||
SkTLazy<SkSVGLineCap> fStrokeLineCap;
|
||||
SkTLazy<SkSVGLineJoin> fStrokeLineJoin;
|
||||
SkTLazy<SkSVGNumberType> fStrokeMiterLimit;
|
||||
|
@ -329,6 +329,7 @@ SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
|
||||
{ "stop-opacity" , { SkSVGAttribute::kStopOpacity , SetNumberAttribute }},
|
||||
{ "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }},
|
||||
{ "stroke-dasharray" , { SkSVGAttribute::kStrokeDashArray , SetDashArrayAttribute }},
|
||||
{ "stroke-dashoffset", { SkSVGAttribute::kStrokeDashOffset , SetLengthAttribute }},
|
||||
{ "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute }},
|
||||
{ "stroke-linejoin" , { SkSVGAttribute::kStrokeLineJoin , SetLineJoinAttribute }},
|
||||
{ "stroke-miterlimit", { SkSVGAttribute::kStrokeMiterLimit , SetNumberAttribute }},
|
||||
|
@ -94,6 +94,10 @@ void SkSVGNode::setStrokeDashArray(const SkSVGDashArray& dashArray) {
|
||||
fPresentationAttributes.fStrokeDashArray.set(dashArray);
|
||||
}
|
||||
|
||||
void SkSVGNode::setStrokeDashOffset(const SkSVGLength& dashOffset) {
|
||||
fPresentationAttributes.fStrokeDashOffset.set(dashOffset);
|
||||
}
|
||||
|
||||
void SkSVGNode::setStrokeOpacity(const SkSVGNumberType& opacity) {
|
||||
fPresentationAttributes.fStrokeOpacity.set(
|
||||
SkSVGNumberType(SkTPin<SkScalar>(opacity.value(), 0, 1)));
|
||||
@ -149,6 +153,11 @@ void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
||||
this->setStrokeDashArray(*dashArray);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kStrokeDashOffset:
|
||||
if (const SkSVGLengthValue* dashOffset= v.as<SkSVGLengthValue>()) {
|
||||
this->setStrokeDashOffset(*dashOffset);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kStrokeOpacity:
|
||||
if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) {
|
||||
this->setStrokeOpacity(*opacity);
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
void setOpacity(const SkSVGNumberType&);
|
||||
void setStroke(const SkSVGPaint&);
|
||||
void setStrokeDashArray(const SkSVGDashArray&);
|
||||
void setStrokeDashOffset(const SkSVGLength&);
|
||||
void setStrokeOpacity(const SkSVGNumberType&);
|
||||
void setStrokeWidth(const SkSVGLength&);
|
||||
void setVisibility(const SkSVGVisibility&);
|
||||
|
@ -179,13 +179,20 @@ void commitToPaint<SkSVGAttribute::kStrokeDashArray>(const SkSVGPresentationAttr
|
||||
|
||||
SkASSERT((intervals.count() & 1) == 0);
|
||||
|
||||
// TODO: phase support
|
||||
const SkScalar phase = 0;
|
||||
const SkScalar phase = ctx.lengthContext().resolve(*pctx->fInherited.fStrokeDashOffset.get(),
|
||||
SkSVGLengthContext::LengthType::kOther);
|
||||
pctx->fStrokePaint.setPathEffect(SkDashPathEffect::Make(intervals.begin(),
|
||||
intervals.count(),
|
||||
phase));
|
||||
}
|
||||
|
||||
template <>
|
||||
void commitToPaint<SkSVGAttribute::kStrokeDashOffset>(const SkSVGPresentationAttributes&,
|
||||
const SkSVGRenderContext&,
|
||||
SkSVGPresentationContext*) {
|
||||
// Applied via kStrokeDashArray.
|
||||
}
|
||||
|
||||
template <>
|
||||
void commitToPaint<SkSVGAttribute::kStrokeLineCap>(const SkSVGPresentationAttributes& attrs,
|
||||
const SkSVGRenderContext&,
|
||||
@ -330,6 +337,7 @@ void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttr
|
||||
ApplyLazyInheritedAttribute(FillRule);
|
||||
ApplyLazyInheritedAttribute(ClipRule);
|
||||
ApplyLazyInheritedAttribute(Stroke);
|
||||
ApplyLazyInheritedAttribute(StrokeDashOffset);
|
||||
ApplyLazyInheritedAttribute(StrokeDashArray);
|
||||
ApplyLazyInheritedAttribute(StrokeLineCap);
|
||||
ApplyLazyInheritedAttribute(StrokeLineJoin);
|
||||
|
Loading…
Reference in New Issue
Block a user