Debian Codegraph @

modules/svg/src/SkSVGPath.cpp

raw
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 "modules/svg/include/SkSVGPath.h"
9
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkPathTypes.h"
12 #include "include/utils/SkParsePath.h"
13 #include "modules/svg/include/SkSVGAttribute.h"
14 #include "modules/svg/include/SkSVGAttributeParser.h"
15 #include "modules/svg/include/SkSVGRenderContext.h"
16 #include "modules/svg/include/SkSVGTypes.h"
17
18 class SkPaint;
19
20 SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
21
22 bool SkSVGPath::parseAndSetAttribute(const char* n, const char* v) {
23 return INHERITED::parseAndSetAttribute(n, v) ||
24 this->setPath(SkSVGAttributeParser::parse<SkPath>("d", n, v));
25 }
26
27 template <>
28 bool SkSVGAttributeParser::parse<SkPath>(SkPath* path) {
29 if (auto result = SkParsePath::FromSVGString(fCurPos)) {
30 *path = *result;
31 return true;
32 }
33 return false;
34 }
35
36 void SkSVGPath::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
37 SkPathFillType fillType) const {
38 // the passed fillType follows inheritance rules and needs to be applied at draw time.
39 SkPath path = fPath; // Note: point and verb data are CoW
40 path.setFillType(fillType);
41 canvas->drawPath(path, paint);
42 }
43
44 SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const {
45 SkPath path = fPath;
46 // clip-rule can be inherited and needs to be applied at clip time.
47 path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType());
48 return this->mapToParent(path);
49 }
50
51 SkRect SkSVGPath::onTransformableObjectBoundingBox(const SkSVGRenderContext& ctx) const {
52 return fPath.computeTightBounds();
53 }