xref: /aosp_15_r20/external/skia/modules/svg/src/SkSVGShape.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/SkSVGShape.h"
9 
10 #include "include/core/SkPaint.h"  // IWYU pragma: keep
11 #include "include/private/base/SkDebug.h"
12 #include "modules/svg/include/SkSVGAttribute.h"
13 #include "modules/svg/include/SkSVGRenderContext.h"
14 #include "modules/svg/include/SkSVGTypes.h"
15 #include "src/base/SkTLazy.h"
16 
17 class SkSVGNode;
18 enum class SkSVGTag;
19 
SkSVGShape(SkSVGTag t)20 SkSVGShape::SkSVGShape(SkSVGTag t) : INHERITED(t) {}
21 
onRender(const SkSVGRenderContext & ctx) const22 void SkSVGShape::onRender(const SkSVGRenderContext& ctx) const {
23     const auto fillType = ctx.presentationContext().fInherited.fFillRule->asFillType();
24 
25     const auto fillPaint = ctx.fillPaint(),
26              strokePaint = ctx.strokePaint();
27 
28     // TODO: this approach forces duplicate geometry resolution in onDraw(); refactor to avoid.
29     if (fillPaint.isValid()) {
30         this->onDraw(ctx.canvas(), ctx.lengthContext(), *fillPaint, fillType);
31     }
32 
33     if (strokePaint.isValid()) {
34         this->onDraw(ctx.canvas(), ctx.lengthContext(), *strokePaint, fillType);
35     }
36 }
37 
appendChild(sk_sp<SkSVGNode>)38 void SkSVGShape::appendChild(sk_sp<SkSVGNode>) {
39     SkDEBUGF("cannot append child nodes to an SVG shape.\n");
40 }
41