fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 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 | |
fmalita | 58649cc | 2016-07-29 08:52:03 -0700 | [diff] [blame] | 14 | SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { } |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 15 | |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 16 | void SkSVGPath::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { |
| 17 | switch (attr) { |
fmalita | 58649cc | 2016-07-29 08:52:03 -0700 | [diff] [blame] | 18 | case SkSVGAttribute::kD: |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 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 | } |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 27 | |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 28 | 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); |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 32 | canvas->drawPath(fPath, paint); |
| 33 | } |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 34 | |
| 35 | SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const { |
| 36 | // the computed fillType follows inheritance rules and needs to be applied at draw time. |
| 37 | fPath.setFillType(FillRuleToFillType(*ctx.presentationContext().fInherited.fFillRule.get())); |
| 38 | |
| 39 | SkPath path = fPath; |
| 40 | this->mapToParent(&path); |
| 41 | return path; |
| 42 | } |