Flutter Engine
The Flutter Engine
Functions
SvgTool.cpp File Reference
#include <iostream>
#include "include/core/SkMatrix.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/encode/SkPngEncoder.h"
#include "modules/skresources/include/SkResources.h"
#include "modules/skshaper/utils/FactoryHelpers.h"
#include "modules/svg/include/SkSVGDOM.h"
#include "src/utils/SkOSPath.h"
#include "tools/CodecUtils.h"
#include "tools/flags/CommandLineFlags.h"
#include "tools/fonts/FontToolUtils.h"
#include "include/ports/SkFontMgr_empty.h"

Go to the source code of this file.

Functions

static DEFINE_string2 (input, i, nullptr, "Input SVG file.")
 
static DEFINE_string2 (output, o, nullptr, "Output PNG file.")
 
static DEFINE_int (width, 1024, "Output width.")
 
static DEFINE_int (height, 1024, "Output height.")
 
int main (int argc, char **argv)
 

Function Documentation

◆ DEFINE_int() [1/2]

static DEFINE_int ( height  ,
1024  ,
"Output height."   
)
static

◆ DEFINE_int() [2/2]

static DEFINE_int ( width  ,
1024  ,
"Output width."   
)
static

◆ DEFINE_string2() [1/2]

static DEFINE_string2 ( input  ,
i  ,
nullptr  ,
"Input SVG file."   
)
static

◆ DEFINE_string2() [2/2]

static DEFINE_string2 ( output  ,
,
nullptr  ,
"Output PNG file."   
)
static

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file SvgTool.cpp.

34 {
36
37 if (FLAGS_input.isEmpty() || FLAGS_output.isEmpty()) {
38 std::cerr << "Missing required 'input' and 'output' args.\n";
39 return 1;
40 }
41
42 if (FLAGS_width <= 0 || FLAGS_height <= 0) {
43 std::cerr << "Invalid width/height.\n";
44 return 1;
45 }
46
47 SkFILEStream in(FLAGS_input[0]);
48 if (!in.isValid()) {
49 std::cerr << "Could not open " << FLAGS_input[0] << "\n";
50 return 1;
51 }
52
53 // If necessary, clients should use a font manager that would load fonts from the system.
54#if defined(SK_BUILD_FOR_MAC)
56#else
58#endif
59
61
65 predecode,
66 fontMgr);
67
68 auto svg_dom = SkSVGDOM::Builder()
69 .setFontManager(fontMgr)
70 .setResourceProvider(std::move(rp))
71 .setTextShapingFactory(SkShapers::BestAvailable())
72 .make(in);
73
74 if (!svg_dom) {
75 std::cerr << "Could not parse " << FLAGS_input[0] << "\n";
76 return 1;
77 }
78
79 auto surface = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(FLAGS_width, FLAGS_height));
80
81 svg_dom->setContainerSize(SkSize::Make(FLAGS_width, FLAGS_height));
82 svg_dom->render(surface->getCanvas());
83
84 SkPixmap pixmap;
85 surface->peekPixels(&pixmap);
86
87 SkFILEWStream out(FLAGS_output[0]);
88 if (!out.isValid()) {
89 std::cerr << "Could not open " << FLAGS_output[0] << " for writing.\n";
90 return 1;
91 }
92
93 // Use default encoding options.
94 SkPngEncoder::Options png_options;
95
96 if (!SkPngEncoder::Encode(&out, pixmap, png_options)) {
97 std::cerr << "PNG encoding failed.\n";
98 return 1;
99 }
100
101 return 0;
102}
SK_API sk_sp< SkFontMgr > SkFontMgr_New_Custom_Empty()
SK_API sk_sp< SkFontMgr > SkFontMgr_New_CoreText(CTFontCollectionRef)
static void Parse(int argc, const char *const *argv)
static SkString Dirname(const char *fullPath)
Definition: SkOSPath.cpp:36
static sk_sp< DataURIResourceProviderProxy > Make(sk_sp< ResourceProvider > rp, ImageDecodeStrategy=ImageDecodeStrategy::kLazyDecode, sk_sp< const SkFontMgr > fontMgr=nullptr)
static sk_sp< FileResourceProvider > Make(SkString base_dir, ImageDecodeStrategy=ImageDecodeStrategy::kLazyDecode)
VkSurfaceKHR surface
Definition: main.cc:49
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
char ** argv
Definition: library.h:9
void RegisterAllAvailable()
Definition: CodecUtils.h:60
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
sk_sp< Factory > BestAvailable()
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
DlVertices::Builder Builder
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56