blob: 9351a2f096792b1112eac072cb6eb8f67eeeeb61 [file] [log] [blame]
fmalitabffc2562016-08-03 10:21:11 -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
8#include "SkSVGRenderContext.h"
9#include "SkSVGShape.h"
10
11SkSVGShape::SkSVGShape(SkSVGTag t) : INHERITED(t) {}
12
fmalita397a5172016-08-08 11:38:55 -070013void SkSVGShape::onRender(const SkSVGRenderContext& ctx) const {
Florin Malitae932d4b2016-12-01 13:35:11 -050014 const SkPath::FillType fillType =
15 FillRuleToFillType(*ctx.presentationContext().fInherited.fFillRule.get());
16
fmalita286a8652016-08-10 17:11:29 -070017 // TODO: this approach forces duplicate geometry resolution in onDraw(); refactor to avoid.
fmalita2d961e02016-08-11 09:16:29 -070018 if (const SkPaint* fillPaint = ctx.fillPaint()) {
Florin Malitae932d4b2016-12-01 13:35:11 -050019 this->onDraw(ctx.canvas(), ctx.lengthContext(), *fillPaint, fillType);
fmalitabffc2562016-08-03 10:21:11 -070020 }
21
fmalita2d961e02016-08-11 09:16:29 -070022 if (const SkPaint* strokePaint = ctx.strokePaint()) {
Florin Malitae932d4b2016-12-01 13:35:11 -050023 this->onDraw(ctx.canvas(), ctx.lengthContext(), *strokePaint, fillType);
fmalitabffc2562016-08-03 10:21:11 -070024 }
25}
26
27void SkSVGShape::appendChild(sk_sp<SkSVGNode>) {
28 SkDebugf("cannot append child nodes to an SVG shape.\n");
29}
Florin Malitae932d4b2016-12-01 13:35:11 -050030
31SkPath::FillType SkSVGShape::FillRuleToFillType(const SkSVGFillRule& fillRule) {
32 switch (fillRule.type()) {
33 case SkSVGFillRule::Type::kNonZero:
34 return SkPath::kWinding_FillType;
35 case SkSVGFillRule::Type::kEvenOdd:
36 return SkPath::kEvenOdd_FillType;
37 default:
38 SkASSERT(false);
39 return SkPath::kWinding_FillType;
40 }
41}