fmalita | 6ceef3d | 2016-07-26 18:46:34 -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" |
| 9 | #include "include/core/SkPaint.h" |
Tyler Denniston | c505e43 | 2021-02-08 13:58:44 -0500 | [diff] [blame] | 10 | #include "include/utils/SkParsePath.h" |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 11 | #include "modules/svg/include/SkSVGPath.h" |
| 12 | #include "modules/svg/include/SkSVGRenderContext.h" |
| 13 | #include "modules/svg/include/SkSVGValue.h" |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 14 | |
fmalita | 58649cc | 2016-07-29 08:52:03 -0700 | [diff] [blame] | 15 | SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { } |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 16 | |
Tyler Denniston | c505e43 | 2021-02-08 13:58:44 -0500 | [diff] [blame] | 17 | bool 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 | |
| 22 | template <> |
| 23 | bool SkSVGAttributeParser::parse<SkPath>(SkPath* path) { |
| 24 | return SkParsePath::FromSVGString(fCurPos, path); |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 25 | } |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 26 | |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 27 | void SkSVGPath::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint, |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 28 | SkPathFillType fillType) const { |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 29 | // the passed fillType follows inheritance rules and needs to be applied at draw time. |
Tyler Denniston | c505e43 | 2021-02-08 13:58:44 -0500 | [diff] [blame] | 30 | SkPath path = fPath; // Note: point and verb data are CoW |
| 31 | path.setFillType(fillType); |
| 32 | canvas->drawPath(path, paint); |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 33 | } |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 34 | |
| 35 | SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const { |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 36 | SkPath path = fPath; |
Florin Malita | 57a0edf | 2017-10-10 11:22:08 -0400 | [diff] [blame] | 37 | // 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] | 38 | path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType()); |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 39 | this->mapToParent(&path); |
| 40 | return path; |
| 41 | } |
Tyler Denniston | 3a92f77 | 2021-01-12 09:28:22 -0500 | [diff] [blame] | 42 | |
| 43 | SkRect SkSVGPath::onObjectBoundingBox(const SkSVGRenderContext& ctx) const { |
| 44 | return fPath.computeTightBounds(); |
| 45 | } |