Coverage Report

Created: 2024-05-20 07:14

/src/skia/tools/SvgPathExtractor.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2023 Google LLC
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 "tools/SvgPathExtractor.h"
9
10
#include "include/core/SkCanvas.h"
11
#include "include/core/SkPicture.h"
12
#include "include/core/SkRefCnt.h"
13
#include "include/core/SkStream.h"
14
#include "include/private/base/SkDebug.h"
15
#include "modules/svg/include/SkSVGDOM.h"
16
#include "modules/svg/include/SkSVGNode.h"
17
#include "src/xml/SkDOM.h"
18
19
#include <cstring>
20
21
class SkPaint;
22
class SkPath;
23
24
namespace ToolUtils {
25
26
0
void ExtractPaths(const char filepath[], std::function<PathSniffCallback> callback) {
27
0
    SkFILEStream stream(filepath);
28
0
    if (!stream.isValid()) {
29
0
        SkDebugf("ExtractPaths: invalid input file at \"%s\"\n", filepath);
30
0
        return;
31
0
    }
32
33
0
    class PathSniffer : public SkCanvas {
34
0
    public:
35
0
        PathSniffer(std::function<PathSniffCallback> callback)
36
0
                : SkCanvas(4096, 4096, nullptr)
37
0
                , fPathSniffCallback(callback) {}
38
0
    private:
39
0
        void onDrawPath(const SkPath& path, const SkPaint& paint) override {
40
0
            fPathSniffCallback(this->getTotalMatrix(), path, paint);
41
0
        }
42
0
        std::function<PathSniffCallback> fPathSniffCallback;
43
0
    };
44
45
0
    sk_sp<SkSVGDOM> svg = SkSVGDOM::MakeFromStream(stream);
46
0
    if (!svg) {
47
0
        SkDebugf("ExtractPaths: couldn't load svg at \"%s\"\n", filepath);
48
0
        return;
49
0
    }
50
0
    PathSniffer pathSniffer(callback);
51
0
    svg->setContainerSize(SkSize::Make(pathSniffer.getBaseLayerSize()));
52
0
    svg->render(&pathSniffer);
53
0
}
54
55
}  // namespace ToolUtils