From e1dadd74f8a554ead3975431d6c09eb25749c904 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Fri, 13 Oct 2017 18:18:32 -0400 Subject: [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 Commit-Queue: Florin Malita --- experimental/svg/model/SkSVGAttribute.cpp | 1 + experimental/svg/model/SkSVGAttribute.h | 2 ++ experimental/svg/model/SkSVGDOM.cpp | 1 + experimental/svg/model/SkSVGNode.cpp | 9 +++++++++ experimental/svg/model/SkSVGNode.h | 1 + experimental/svg/model/SkSVGRenderContext.cpp | 12 ++++++++++-- 6 files changed, 24 insertions(+), 2 deletions(-) (limited to 'experimental/svg') diff --git a/experimental/svg/model/SkSVGAttribute.cpp b/experimental/svg/model/SkSVGAttribute.cpp index 41527f7497..31c6c28bb2 100644 --- a/experimental/svg/model/SkSVGAttribute.cpp +++ b/experimental/svg/model/SkSVGAttribute.cpp @@ -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)); diff --git a/experimental/svg/model/SkSVGAttribute.h b/experimental/svg/model/SkSVGAttribute.h index 1650c3b913..333e3c98e8 100644 --- a/experimental/svg/model/SkSVGAttribute.h +++ b/experimental/svg/model/SkSVGAttribute.h @@ -39,6 +39,7 @@ enum class SkSVGAttribute { kStopOpacity, kStroke, kStrokeDashArray, + kStrokeDashOffset, kStrokeOpacity, kStrokeLineCap, kStrokeLineJoin, @@ -70,6 +71,7 @@ struct SkSVGPresentationAttributes { SkTLazy fStroke; SkTLazy fStrokeDashArray; + SkTLazy fStrokeDashOffset; SkTLazy fStrokeLineCap; SkTLazy fStrokeLineJoin; SkTLazy fStrokeMiterLimit; diff --git a/experimental/svg/model/SkSVGDOM.cpp b/experimental/svg/model/SkSVGDOM.cpp index b25a4d01e3..5b4dc6626f 100644 --- a/experimental/svg/model/SkSVGDOM.cpp +++ b/experimental/svg/model/SkSVGDOM.cpp @@ -329,6 +329,7 @@ SortedDictionaryEntry 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 }}, diff --git a/experimental/svg/model/SkSVGNode.cpp b/experimental/svg/model/SkSVGNode.cpp index 07dc59c645..c5262a0da8 100644 --- a/experimental/svg/model/SkSVGNode.cpp +++ b/experimental/svg/model/SkSVGNode.cpp @@ -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(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()) { + this->setStrokeDashOffset(*dashOffset); + } + break; case SkSVGAttribute::kStrokeOpacity: if (const SkSVGNumberValue* opacity = v.as()) { this->setStrokeOpacity(*opacity); diff --git a/experimental/svg/model/SkSVGNode.h b/experimental/svg/model/SkSVGNode.h index c8de2d75f2..ffc4411bde 100644 --- a/experimental/svg/model/SkSVGNode.h +++ b/experimental/svg/model/SkSVGNode.h @@ -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&); diff --git a/experimental/svg/model/SkSVGRenderContext.cpp b/experimental/svg/model/SkSVGRenderContext.cpp index 61551c4858..2b7ba2cf2c 100644 --- a/experimental/svg/model/SkSVGRenderContext.cpp +++ b/experimental/svg/model/SkSVGRenderContext.cpp @@ -179,13 +179,20 @@ void commitToPaint(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(const SkSVGPresentationAttributes&, + const SkSVGRenderContext&, + SkSVGPresentationContext*) { + // Applied via kStrokeDashArray. +} + template <> void commitToPaint(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); -- cgit v1.2.3