blob: a250ceaf6860f0c6d64f82a327abb9339b29997d [file] [log] [blame]
fmalita6ceef3d2016-07-26 18:46:34 -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"
9#include "include/core/SkPaint.h"
Tyler Dennistonc505e432021-02-08 13:58:44 -050010#include "include/utils/SkParsePath.h"
Florin Malitab3418102020-10-15 18:10:29 -040011#include "modules/svg/include/SkSVGPath.h"
12#include "modules/svg/include/SkSVGRenderContext.h"
13#include "modules/svg/include/SkSVGValue.h"
fmalita6ceef3d2016-07-26 18:46:34 -070014
fmalita58649cc2016-07-29 08:52:03 -070015SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
fmalita6ceef3d2016-07-26 18:46:34 -070016
Tyler Dennistonc505e432021-02-08 13:58:44 -050017bool SkSVGPath::parseAndSetAttribute(const char* n, const char* v) {
18 return INHERITED::parseAndSetAttribute(n, v) ||
19 this->setPath(SkSVGAttributeParser::parse<SkPath>("d", n, v));
20}
21
22template <>
23bool SkSVGAttributeParser::parse<SkPath>(SkPath* path) {
24 return SkParsePath::FromSVGString(fCurPos, path);
fmalita6ceef3d2016-07-26 18:46:34 -070025}
fmalitabffc2562016-08-03 10:21:11 -070026
Florin Malitae932d4b2016-12-01 13:35:11 -050027void SkSVGPath::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
Mike Reed7d34dc72019-11-26 12:17:17 -050028 SkPathFillType fillType) const {
Florin Malitae932d4b2016-12-01 13:35:11 -050029 // the passed fillType follows inheritance rules and needs to be applied at draw time.
Tyler Dennistonc505e432021-02-08 13:58:44 -050030 SkPath path = fPath; // Note: point and verb data are CoW
31 path.setFillType(fillType);
32 canvas->drawPath(path, paint);
fmalitabffc2562016-08-03 10:21:11 -070033}
Florin Malitace8840e2016-12-08 09:26:47 -050034
35SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const {
Florin Malitace8840e2016-12-08 09:26:47 -050036 SkPath path = fPath;
Florin Malita57a0edf2017-10-10 11:22:08 -040037 // clip-rule can be inherited and needs to be applied at clip time.
John Stilesa008b0f2020-08-16 08:48:02 -040038 path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType());
Florin Malitace8840e2016-12-08 09:26:47 -050039 this->mapToParent(&path);
40 return path;
41}
Tyler Denniston3a92f772021-01-12 09:28:22 -050042
43SkRect SkSVGPath::onObjectBoundingBox(const SkSVGRenderContext& ctx) const {
44 return fPath.computeTightBounds();
45}