Coverage Report

Created: 2021-08-22 09:07

/src/skia/modules/svg/src/SkSVGPoly.cpp
Line
Count
Source
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 "include/core/SkCanvas.h"
9
#include "modules/svg/include/SkSVGPoly.h"
10
#include "modules/svg/include/SkSVGRenderContext.h"
11
#include "modules/svg/include/SkSVGValue.h"
12
#include "src/core/SkTLazy.h"
13
14
1.92k
SkSVGPoly::SkSVGPoly(SkSVGTag t) : INHERITED(t) {}
15
16
4.80k
bool SkSVGPoly::parseAndSetAttribute(const char* n, const char* v) {
17
4.80k
    if (INHERITED::parseAndSetAttribute(n, v)) {
18
2.22k
        return true;
19
2.22k
    }
20
21
2.58k
    if (this->setPoints(SkSVGAttributeParser::parse<SkSVGPointsType>("points", n, v))) {
22
        // TODO: we can likely just keep the points array and create the SkPath when needed.
23
1.20k
        fPath = SkPath::Polygon(
24
1.20k
                fPoints.begin(), fPoints.count(),
25
1.20k
                this->tag() == SkSVGTag::kPolygon);  // only polygons are auto-closed
26
1.20k
    }
27
28
    // No other attributes on this node
29
2.58k
    return false;
30
2.58k
}
31
32
void SkSVGPoly::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
33
2.48k
                       SkPathFillType fillType) const {
34
    // the passed fillType follows inheritance rules and needs to be applied at draw time.
35
2.48k
    fPath.setFillType(fillType);
36
2.48k
    canvas->drawPath(fPath, paint);
37
2.48k
}
38
39
146
SkPath SkSVGPoly::onAsPath(const SkSVGRenderContext& ctx) const {
40
146
    SkPath path = fPath;
41
42
    // clip-rule can be inherited and needs to be applied at clip time.
43
146
    path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType());
44
45
146
    this->mapToParent(&path);
46
146
    return path;
47
146
}
48
49
45
SkRect SkSVGPoly::onObjectBoundingBox(const SkSVGRenderContext& ctx) const {
50
45
    return fPath.getBounds();
51
45
}