Flutter Engine
The Flutter Engine
SvgPathExtractor.cpp
Go to the documentation of this file.
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
9
17#include "src/xml/SkDOM.h"
18
19#include <cstring>
20
21class SkPaint;
22class SkPath;
23
24namespace ToolUtils {
25
26void ExtractPaths(const char filepath[], std::function<PathSniffCallback> callback) {
27 SkFILEStream stream(filepath);
28 if (!stream.isValid()) {
29 SkDebugf("ExtractPaths: invalid input file at \"%s\"\n", filepath);
30 return;
31 }
32
33 class PathSniffer : public SkCanvas {
34 public:
35 PathSniffer(std::function<PathSniffCallback> callback)
36 : SkCanvas(4096, 4096, nullptr)
37 , fPathSniffCallback(callback) {}
38 private:
39 void onDrawPath(const SkPath& path, const SkPaint& paint) override {
40 fPathSniffCallback(this->getTotalMatrix(), path, paint);
41 }
42 std::function<PathSniffCallback> fPathSniffCallback;
43 };
44
46 if (!svg) {
47 SkDebugf("ExtractPaths: couldn't load svg at \"%s\"\n", filepath);
48 return;
49 }
50 PathSniffer pathSniffer(callback);
51 svg->setContainerSize(SkSize::Make(pathSniffer.getBaseLayerSize()));
52 svg->render(&pathSniffer);
53}
54
55} // namespace ToolUtils
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
Definition: SkPath.h:59
static sk_sp< SkSVGDOM > MakeFromStream(SkStream &str)
Definition: SkSVGDOM.h:57
const Paint & paint
Definition: color_source.cc:38
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void ExtractPaths(const char filepath[], std::function< PathSniffCallback > callback)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56
const char * svg