/src/skia/modules/svg/src/SkSVGPath.cpp
Line | Count | Source |
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 | | |
8 | | #include "include/core/SkCanvas.h" |
9 | | #include "include/core/SkPaint.h" |
10 | | #include "include/utils/SkParsePath.h" |
11 | | #include "modules/svg/include/SkSVGPath.h" |
12 | | #include "modules/svg/include/SkSVGRenderContext.h" |
13 | | #include "modules/svg/include/SkSVGValue.h" |
14 | | |
15 | 96.0k | SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { } |
16 | | |
17 | 129k | bool SkSVGPath::parseAndSetAttribute(const char* n, const char* v) { |
18 | 129k | return INHERITED::parseAndSetAttribute(n, v) || |
19 | 113k | this->setPath(SkSVGAttributeParser::parse<SkPath>("d", n, v)); |
20 | 129k | } |
21 | | |
22 | | template <> |
23 | 83.4k | bool SkSVGAttributeParser::parse<SkPath>(SkPath* path) { |
24 | 83.4k | return SkParsePath::FromSVGString(fCurPos, path); |
25 | 83.4k | } |
26 | | |
27 | | void SkSVGPath::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint, |
28 | 60.7k | SkPathFillType fillType) const { |
29 | | // the passed fillType follows inheritance rules and needs to be applied at draw time. |
30 | 60.7k | SkPath path = fPath; // Note: point and verb data are CoW |
31 | 60.7k | path.setFillType(fillType); |
32 | 60.7k | canvas->drawPath(path, paint); |
33 | 60.7k | } |
34 | | |
35 | 213k | SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const { |
36 | 213k | SkPath path = fPath; |
37 | | // clip-rule can be inherited and needs to be applied at clip time. |
38 | 213k | path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType()); |
39 | 213k | this->mapToParent(&path); |
40 | 213k | return path; |
41 | 213k | } |
42 | | |
43 | 4.35k | SkRect SkSVGPath::onObjectBoundingBox(const SkSVGRenderContext& ctx) const { |
44 | 4.35k | return fPath.computeTightBounds(); |
45 | 4.35k | } |