1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkCanvas.h"
9 #include "SkPaint.h"
10 #include "SkSVGPath.h"
11 #include "SkSVGRenderContext.h"
12 #include "SkSVGValue.h"
13
SkSVGPath()14 SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
15
onSetAttribute(SkSVGAttribute attr,const SkSVGValue & v)16 void SkSVGPath::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
17 switch (attr) {
18 case SkSVGAttribute::kD:
19 if (const auto* path = v.as<SkSVGPathValue>()) {
20 this->setPath(*path);
21 }
22 break;
23 default:
24 this->INHERITED::onSetAttribute(attr, v);
25 }
26 }
27
onDraw(SkCanvas * canvas,const SkSVGLengthContext &,const SkPaint & paint,SkPath::FillType fillType) const28 void SkSVGPath::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
29 SkPath::FillType fillType) const {
30 // the passed fillType follows inheritance rules and needs to be applied at draw time.
31 fPath.setFillType(fillType);
32 canvas->drawPath(fPath, paint);
33 }
34
onAsPath(const SkSVGRenderContext & ctx) const35 SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const {
36 SkPath path = fPath;
37 // clip-rule can be inherited and needs to be applied at clip time.
38 path.setFillType(ctx.presentationContext().fInherited.fClipRule.get()->asFillType());
39 this->mapToParent(&path);
40 return path;
41 }
42