xref: /aosp_15_r20/external/skia/modules/svg/include/SkSVGPoly.h (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 #ifndef SkSVGPoly_DEFINED
9 #define SkSVGPoly_DEFINED
10 
11 #include "include/core/SkPath.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/private/base/SkAPI.h"
15 #include "modules/svg/include/SkSVGNode.h"
16 #include "modules/svg/include/SkSVGShape.h"
17 #include "modules/svg/include/SkSVGTypes.h"
18 
19 class SkCanvas;
20 class SkPaint;
21 class SkSVGLengthContext;
22 class SkSVGRenderContext;
23 enum class SkPathFillType;
24 
25 // Handles <polygon> and <polyline> elements.
26 class SK_API SkSVGPoly final : public SkSVGShape {
27 public:
MakePolygon()28     static sk_sp<SkSVGPoly> MakePolygon() {
29         return sk_sp<SkSVGPoly>(new SkSVGPoly(SkSVGTag::kPolygon));
30     }
31 
MakePolyline()32     static sk_sp<SkSVGPoly> MakePolyline() {
33         return sk_sp<SkSVGPoly>(new SkSVGPoly(SkSVGTag::kPolyline));
34     }
35 
36     SVG_ATTR(Points, SkSVGPointsType, SkSVGPointsType())
37 
38 protected:
39     bool parseAndSetAttribute(const char*, const char*) override;
40 
41     void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
42                 SkPathFillType) const override;
43 
44     SkPath onAsPath(const SkSVGRenderContext&) const override;
45 
46     SkRect onObjectBoundingBox(const SkSVGRenderContext&) const override;
47 
48 private:
49     SkSVGPoly(SkSVGTag);
50 
51     mutable SkPath fPath;  // mutated in onDraw(), to apply inherited fill types.
52 
53     using INHERITED = SkSVGShape;
54 };
55 
56 #endif // SkSVGPoly_DEFINED
57