aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/svg/model/SkSVGRenderContext.cpp
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-10-13 14:07:44 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-13 19:14:39 +0000
commitf543a60ef06a6b0ccb5a0a85ca5415021c81c9ee (patch)
treef2a3d3dd48e360e045e01385d86fa7833de20d3b /experimental/svg/model/SkSVGRenderContext.cpp
parent770db22a553e87d6f3e40db72c5871b1d8a9ec91 (diff)
[SVGDom] Add 'stroke-dasharray' support
https://www.w3.org/TR/SVG/painting.html#StrokeDasharrayProperty Change-Id: I9a63ebbd958d661c865ed405570b86cca68f63bf Reviewed-on: https://skia-review.googlesource.com/59700 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'experimental/svg/model/SkSVGRenderContext.cpp')
-rw-r--r--experimental/svg/model/SkSVGRenderContext.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/experimental/svg/model/SkSVGRenderContext.cpp b/experimental/svg/model/SkSVGRenderContext.cpp
index 8ee5ffcbe6..61551c4858 100644
--- a/experimental/svg/model/SkSVGRenderContext.cpp
+++ b/experimental/svg/model/SkSVGRenderContext.cpp
@@ -6,6 +6,7 @@
*/
#include "SkCanvas.h"
+#include "SkDashPathEffect.h"
#include "SkPath.h"
#include "SkSVGAttribute.h"
#include "SkSVGNode.h"
@@ -154,6 +155,38 @@ void commitToPaint<SkSVGAttribute::kFillOpacity>(const SkSVGPresentationAttribut
}
template <>
+void commitToPaint<SkSVGAttribute::kStrokeDashArray>(const SkSVGPresentationAttributes& attrs,
+ const SkSVGRenderContext& ctx,
+ SkSVGPresentationContext* pctx) {
+ const auto& dashArray = attrs.fStrokeDashArray.get();
+ if (dashArray->type() != SkSVGDashArray::Type::kDashArray) {
+ return;
+ }
+
+ const auto count = dashArray->dashArray().count();
+ SkSTArray<128, SkScalar, true> intervals(count);
+ for (const auto& dash : dashArray->dashArray()) {
+ intervals.push_back(ctx.lengthContext().resolve(dash,
+ SkSVGLengthContext::LengthType::kOther));
+ }
+
+ if (count & 1) {
+ // If an odd number of values is provided, then the list of values
+ // is repeated to yield an even number of values.
+ intervals.push_back_n(count);
+ memcpy(intervals.begin() + count, intervals.begin(), count);
+ }
+
+ SkASSERT((intervals.count() & 1) == 0);
+
+ // TODO: phase support
+ const SkScalar phase = 0;
+ pctx->fStrokePaint.setPathEffect(SkDashPathEffect::Make(intervals.begin(),
+ intervals.count(),
+ phase));
+}
+
+template <>
void commitToPaint<SkSVGAttribute::kStrokeLineCap>(const SkSVGPresentationAttributes& attrs,
const SkSVGRenderContext&,
SkSVGPresentationContext* pctx) {
@@ -297,6 +330,7 @@ void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttr
ApplyLazyInheritedAttribute(FillRule);
ApplyLazyInheritedAttribute(ClipRule);
ApplyLazyInheritedAttribute(Stroke);
+ ApplyLazyInheritedAttribute(StrokeDashArray);
ApplyLazyInheritedAttribute(StrokeLineCap);
ApplyLazyInheritedAttribute(StrokeLineJoin);
ApplyLazyInheritedAttribute(StrokeMiterLimit);