aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/svg
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-10-13 18:18:32 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-13 22:53:32 +0000
commite1dadd74f8a554ead3975431d6c09eb25749c904 (patch)
tree4ef0718d6809b4217d41423dc93d3832cbc5c0f0 /experimental/svg
parent7a0ebfc033463907e2088401972d14ea8589cdb5 (diff)
[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>
Diffstat (limited to 'experimental/svg')
-rw-r--r--experimental/svg/model/SkSVGAttribute.cpp1
-rw-r--r--experimental/svg/model/SkSVGAttribute.h2
-rw-r--r--experimental/svg/model/SkSVGDOM.cpp1
-rw-r--r--experimental/svg/model/SkSVGNode.cpp9
-rw-r--r--experimental/svg/model/SkSVGNode.h1
-rw-r--r--experimental/svg/model/SkSVGRenderContext.cpp12
6 files changed, 24 insertions, 2 deletions
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<SkSVGPaint> fStroke;
SkTLazy<SkSVGDashArray> fStrokeDashArray;
+ SkTLazy<SkSVGLength> fStrokeDashOffset;
SkTLazy<SkSVGLineCap> fStrokeLineCap;
SkTLazy<SkSVGLineJoin> fStrokeLineJoin;
SkTLazy<SkSVGNumberType> 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<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 }},
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<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);
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,14 +179,21 @@ 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&,
SkSVGPresentationContext* pctx) {
@@ -330,6 +337,7 @@ void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttr
ApplyLazyInheritedAttribute(FillRule);
ApplyLazyInheritedAttribute(ClipRule);
ApplyLazyInheritedAttribute(Stroke);
+ ApplyLazyInheritedAttribute(StrokeDashOffset);
ApplyLazyInheritedAttribute(StrokeDashArray);
ApplyLazyInheritedAttribute(StrokeLineCap);
ApplyLazyInheritedAttribute(StrokeLineJoin);