fmalita | bffc256 | 2016-08-03 10:21:11 -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 | |
| 8 | #include "SkSVGRenderContext.h" |
| 9 | #include "SkSVGShape.h" |
| 10 | |
| 11 | SkSVGShape::SkSVGShape(SkSVGTag t) : INHERITED(t) {} |
| 12 | |
fmalita | 397a517 | 2016-08-08 11:38:55 -0700 | [diff] [blame] | 13 | void SkSVGShape::onRender(const SkSVGRenderContext& ctx) const { |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 14 | const SkPath::FillType fillType = |
| 15 | FillRuleToFillType(*ctx.presentationContext().fInherited.fFillRule.get()); |
| 16 | |
fmalita | 286a865 | 2016-08-10 17:11:29 -0700 | [diff] [blame] | 17 | // TODO: this approach forces duplicate geometry resolution in onDraw(); refactor to avoid. |
fmalita | 2d961e0 | 2016-08-11 09:16:29 -0700 | [diff] [blame] | 18 | if (const SkPaint* fillPaint = ctx.fillPaint()) { |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 19 | this->onDraw(ctx.canvas(), ctx.lengthContext(), *fillPaint, fillType); |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 20 | } |
| 21 | |
fmalita | 2d961e0 | 2016-08-11 09:16:29 -0700 | [diff] [blame] | 22 | if (const SkPaint* strokePaint = ctx.strokePaint()) { |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 23 | this->onDraw(ctx.canvas(), ctx.lengthContext(), *strokePaint, fillType); |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 24 | } |
| 25 | } |
| 26 | |
| 27 | void SkSVGShape::appendChild(sk_sp<SkSVGNode>) { |
| 28 | SkDebugf("cannot append child nodes to an SVG shape.\n"); |
| 29 | } |
Florin Malita | e932d4b | 2016-12-01 13:35:11 -0500 | [diff] [blame] | 30 | |
| 31 | SkPath::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 | } |