• 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 "SkSVGRenderContext.h"
9 #include "SkSVGShape.h"
10 
SkSVGShape(SkSVGTag t)11 SkSVGShape::SkSVGShape(SkSVGTag t) : INHERITED(t) {}
12 
onRender(const SkSVGRenderContext & ctx) const13 void SkSVGShape::onRender(const SkSVGRenderContext& ctx) const {
14     const SkPath::FillType fillType =
15         FillRuleToFillType(*ctx.presentationContext().fInherited.fFillRule.get());
16 
17     // TODO: this approach forces duplicate geometry resolution in onDraw(); refactor to avoid.
18     if (const SkPaint* fillPaint = ctx.fillPaint()) {
19         this->onDraw(ctx.canvas(), ctx.lengthContext(), *fillPaint, fillType);
20     }
21 
22     if (const SkPaint* strokePaint = ctx.strokePaint()) {
23         this->onDraw(ctx.canvas(), ctx.lengthContext(), *strokePaint, fillType);
24     }
25 }
26 
appendChild(sk_sp<SkSVGNode>)27 void SkSVGShape::appendChild(sk_sp<SkSVGNode>) {
28     SkDebugf("cannot append child nodes to an SVG shape.\n");
29 }
30 
FillRuleToFillType(const SkSVGFillRule & fillRule)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 }
42