• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SkSVGPath()15 SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
16 
parseAndSetAttribute(const char * n,const char * v)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 <>
parse(SkPath * path)23 bool SkSVGAttributeParser::parse<SkPath>(SkPath* path) {
24     return SkParsePath::FromSVGString(fCurPos, path);
25 }
26 
onDraw(SkCanvas * canvas,const SkSVGLengthContext &,const SkPaint & paint,SkPathFillType fillType) const27 void SkSVGPath::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
28                        SkPathFillType fillType) const {
29     // the passed fillType follows inheritance rules and needs to be applied at draw time.
30     SkPath path = fPath;  // Note: point and verb data are CoW
31     path.setFillType(fillType);
32     canvas->drawPath(path, paint);
33 }
34 
onAsPath(const SkSVGRenderContext & ctx) const35 SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const {
36     SkPath path = fPath;
37     // clip-rule can be inherited and needs to be applied at clip time.
38     path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType());
39     this->mapToParent(&path);
40     return path;
41 }
42 
onObjectBoundingBox(const SkSVGRenderContext & ctx) const43 SkRect SkSVGPath::onObjectBoundingBox(const SkSVGRenderContext& ctx) const {
44     return fPath.computeTightBounds();
45 }
46