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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkCanvas.h" |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 9 | #include "modules/svg/include/SkSVGPoly.h" |
| 10 | #include "modules/svg/include/SkSVGRenderContext.h" |
| 11 | #include "modules/svg/include/SkSVGValue.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/core/SkTLazy.h" |
fmalita | 5b31f32 | 2016-08-12 12:15:33 -0700 | [diff] [blame] | 13 | |
| 14 | SkSVGPoly::SkSVGPoly(SkSVGTag t) : INHERITED(t) {} |
| 15 | |
Tyler Denniston | c683482 | 2021-02-08 15:07:03 -0500 | [diff] [blame^] | 16 | bool SkSVGPoly::parseAndSetAttribute(const char* n, const char* v) { |
| 17 | if (INHERITED::parseAndSetAttribute(n, v)) { |
| 18 | return true; |
fmalita | 5b31f32 | 2016-08-12 12:15:33 -0700 | [diff] [blame] | 19 | } |
Tyler Denniston | c683482 | 2021-02-08 15:07:03 -0500 | [diff] [blame^] | 20 | |
| 21 | if (this->setPoints(SkSVGAttributeParser::parse<SkSVGPointsType>("points", n, v))) { |
| 22 | // TODO: we can likely just keep the points array and create the SkPath when needed. |
| 23 | fPath = SkPath::Polygon( |
| 24 | fPoints.begin(), fPoints.count(), |
| 25 | this->tag() == SkSVGTag::kPolygon); // only polygons are auto-closed |
| 26 | } |
| 27 | |
| 28 | // No other attributes on this node |
| 29 | return false; |
fmalita | 5b31f32 | 2016-08-12 12:15:33 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 32 | void SkSVGPoly::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint, |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 33 | SkPathFillType fillType) const { |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 34 | // the passed fillType follows inheritance rules and needs to be applied at draw time. |
| 35 | fPath.setFillType(fillType); |
fmalita | 5b31f32 | 2016-08-12 12:15:33 -0700 | [diff] [blame] | 36 | canvas->drawPath(fPath, paint); |
| 37 | } |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 38 | |
| 39 | SkPath SkSVGPoly::onAsPath(const SkSVGRenderContext& ctx) const { |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 40 | SkPath path = fPath; |
Florin Malita | 57a0edf | 2017-10-10 11:22:08 -0400 | [diff] [blame] | 41 | |
| 42 | // clip-rule can be inherited and needs to be applied at clip time. |
John Stiles | a008b0f | 2020-08-16 08:48:02 -0400 | [diff] [blame] | 43 | path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType()); |
Florin Malita | 57a0edf | 2017-10-10 11:22:08 -0400 | [diff] [blame] | 44 | |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 45 | this->mapToParent(&path); |
| 46 | return path; |
| 47 | } |
Tyler Denniston | dcf288b | 2020-12-11 16:28:34 -0500 | [diff] [blame] | 48 | |
| 49 | SkRect SkSVGPoly::onObjectBoundingBox(const SkSVGRenderContext& ctx) const { |
| 50 | return fPath.getBounds(); |
| 51 | } |