blob: 3c09ab9885d9a51103c2e5625bc0ce831f7c88a8 [file] [log] [blame]
fmalita6ceef3d2016-07-26 18:46:34 -07001/*
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
fmalita58649cc2016-07-29 08:52:03 -070014SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
fmalita6ceef3d2016-07-26 18:46:34 -070015
fmalita6ceef3d2016-07-26 18:46:34 -070016void SkSVGPath::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
17 switch (attr) {
fmalita58649cc2016-07-29 08:52:03 -070018 case SkSVGAttribute::kD:
fmalita6ceef3d2016-07-26 18:46:34 -070019 if (const auto* path = v.as<SkSVGPathValue>()) {
20 this->setPath(*path);
21 }
22 break;
23 default:
24 this->INHERITED::onSetAttribute(attr, v);
25 }
26}
fmalitabffc2562016-08-03 10:21:11 -070027
Florin Malitae932d4b2016-12-01 13:35:11 -050028void 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);
fmalitabffc2562016-08-03 10:21:11 -070032 canvas->drawPath(fPath, paint);
33}
Florin Malitace8840e2016-12-08 09:26:47 -050034
35SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const {
Florin Malitace8840e2016-12-08 09:26:47 -050036 SkPath path = fPath;
Florin Malita57a0edf2017-10-10 11:22:08 -040037 // clip-rule can be inherited and needs to be applied at clip time.
38 path.setFillType(ctx.presentationContext().fInherited.fClipRule.get()->asFillType());
Florin Malitace8840e2016-12-08 09:26:47 -050039 this->mapToParent(&path);
40 return path;
41}