blob: 6bacb1aaabab0a827e2fd3fdf3d2e2d234e4cfe7 [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 "experimental/svg/model/SkSVGPoly.h"
9#include "experimental/svg/model/SkSVGRenderContext.h"
10#include "experimental/svg/model/SkSVGValue.h"
11#include "include/core/SkCanvas.h"
12#include "src/core/SkTLazy.h"
fmalita5b31f322016-08-12 12:15:33 -070013
14SkSVGPoly::SkSVGPoly(SkSVGTag t) : INHERITED(t) {}
15
16void 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
23void 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 Malitae932d4b2016-12-01 13:35:11 -050035void SkSVGPoly::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
Mike Reed3e7af412019-11-26 03:34:16 +000036 SkPath::FillType fillType) const {
Florin Malitae932d4b2016-12-01 13:35:11 -050037 // the passed fillType follows inheritance rules and needs to be applied at draw time.
38 fPath.setFillType(fillType);
fmalita5b31f322016-08-12 12:15:33 -070039 canvas->drawPath(fPath, paint);
40}
Florin Malitace8840e2016-12-08 09:26:47 -050041
42SkPath SkSVGPoly::onAsPath(const SkSVGRenderContext& ctx) const {
Florin Malitace8840e2016-12-08 09:26:47 -050043 SkPath path = fPath;
Florin Malita57a0edf2017-10-10 11:22:08 -040044
45 // clip-rule can be inherited and needs to be applied at clip time.
46 path.setFillType(ctx.presentationContext().fInherited.fClipRule.get()->asFillType());
47
Florin Malitace8840e2016-12-08 09:26:47 -050048 this->mapToParent(&path);
49 return path;
50}