blob: a731014b1905c1098ed8b2fa28f48333471d7ac8 [file] [log] [blame]
fmalita5b31f322016-08-12 12:15:33 -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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkCanvas.h"
Florin Malitab3418102020-10-15 18:10:29 -04009#include "modules/svg/include/SkSVGPoly.h"
10#include "modules/svg/include/SkSVGRenderContext.h"
11#include "modules/svg/include/SkSVGValue.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/core/SkTLazy.h"
fmalita5b31f322016-08-12 12:15:33 -070013
14SkSVGPoly::SkSVGPoly(SkSVGTag t) : INHERITED(t) {}
15
Tyler Dennistonc6834822021-02-08 15:07:03 -050016bool SkSVGPoly::parseAndSetAttribute(const char* n, const char* v) {
17 if (INHERITED::parseAndSetAttribute(n, v)) {
18 return true;
fmalita5b31f322016-08-12 12:15:33 -070019 }
Tyler Dennistonc6834822021-02-08 15:07:03 -050020
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;
fmalita5b31f322016-08-12 12:15:33 -070030}
31
Florin Malitae932d4b2016-12-01 13:35:11 -050032void SkSVGPoly::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
Mike Reed7d34dc72019-11-26 12:17:17 -050033 SkPathFillType fillType) const {
Florin Malitae932d4b2016-12-01 13:35:11 -050034 // the passed fillType follows inheritance rules and needs to be applied at draw time.
35 fPath.setFillType(fillType);
fmalita5b31f322016-08-12 12:15:33 -070036 canvas->drawPath(fPath, paint);
37}
Florin Malitace8840e2016-12-08 09:26:47 -050038
39SkPath SkSVGPoly::onAsPath(const SkSVGRenderContext& ctx) const {
Florin Malitace8840e2016-12-08 09:26:47 -050040 SkPath path = fPath;
Florin Malita57a0edf2017-10-10 11:22:08 -040041
42 // clip-rule can be inherited and needs to be applied at clip time.
John Stilesa008b0f2020-08-16 08:48:02 -040043 path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType());
Florin Malita57a0edf2017-10-10 11:22:08 -040044
Florin Malitace8840e2016-12-08 09:26:47 -050045 this->mapToParent(&path);
46 return path;
47}
Tyler Dennistondcf288b2020-12-11 16:28:34 -050048
49SkRect SkSVGPoly::onObjectBoundingBox(const SkSVGRenderContext& ctx) const {
50 return fPath.getBounds();
51}