fmalita | 5b31f32 | 2016-08-12 12:15:33 -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" |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 9 | #include "SkTLazy.h" |
fmalita | 5b31f32 | 2016-08-12 12:15:33 -0700 | [diff] [blame] | 10 | #include "SkSVGRenderContext.h" |
| 11 | #include "SkSVGPoly.h" |
| 12 | #include "SkSVGValue.h" |
| 13 | |
| 14 | SkSVGPoly::SkSVGPoly(SkSVGTag t) : INHERITED(t) {} |
| 15 | |
| 16 | void SkSVGPoly::setPoints(const SkSVGPointsType& pts) { |
| 17 | fPath.reset(); |
| 18 | fPath.addPoly(pts.value().begin(), |
| 19 | pts.value().count(), |
| 20 | this->tag() == SkSVGTag::kPolygon); // only polygons are auto-closed |
| 21 | } |
| 22 | |
| 23 | void SkSVGPoly::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { |
| 24 | switch (attr) { |
| 25 | case SkSVGAttribute::kPoints: |
| 26 | if (const auto* pts = v.as<SkSVGPointsValue>()) { |
| 27 | this->setPoints(*pts); |
| 28 | } |
| 29 | break; |
| 30 | default: |
| 31 | this->INHERITED::onSetAttribute(attr, v); |
| 32 | } |
| 33 | } |
| 34 | |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 35 | void SkSVGPoly::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint, |
| 36 | SkPath::FillType fillType) const { |
| 37 | // the passed fillType follows inheritance rules and needs to be applied at draw time. |
| 38 | fPath.setFillType(fillType); |
fmalita | 5b31f32 | 2016-08-12 12:15:33 -0700 | [diff] [blame] | 39 | canvas->drawPath(fPath, paint); |
| 40 | } |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 41 | |
| 42 | SkPath SkSVGPoly::onAsPath(const SkSVGRenderContext& ctx) const { |
| 43 | // the computed fillType follows inheritance rules and needs to be applied at draw time. |
| 44 | fPath.setFillType(FillRuleToFillType(*ctx.presentationContext().fInherited.fFillRule.get())); |
| 45 | |
| 46 | SkPath path = fPath; |
| 47 | this->mapToParent(&path); |
| 48 | return path; |
| 49 | } |