Flutter Engine
The Flutter Engine
Functions | Variables
svg_renderer.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/encode/SkPngEncoder.h"
#include "modules/svg/include/SkSVGDOM.h"
#include "modules/skshaper/utils/FactoryHelpers.h"
#include <cstdio>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

constexpr size_t kWidth = 450
 
constexpr size_t kHeight = 120
 
const char * svg
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 45 of file svg_renderer.cpp.

45 {
46 if (argc != 2) {
47 printf("Usage: %s <name.png>", argv[0]);
48 return 1;
49 }
51 if (!output.isValid()) {
52 printf("Cannot open output file %s\n", argv[1]);
53 return 1;
54 }
55
56 // If necessary, clients should use a font manager that would load fonts from the system.
58#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
60#elif defined(SK_FONTMGR_CORETEXT_AVAILABLE)
62#endif
63 if (!fontMgr) {
64 printf("No Font Manager configured\n");
65 return 1;
66 }
67
68 SkMemoryStream svgStream(svg, std::strlen(svg));
69
70 auto svg_dom = SkSVGDOM::Builder()
71 .setFontManager(fontMgr)
72 .setTextShapingFactory(SkShapers::BestAvailable())
73 .make(svgStream);
74
75 if (!svg_dom) {
76 printf("Could not parse compiled-in svg\n");
77 return 1;
78 }
79
81
82 svg_dom->setContainerSize(SkSize::Make(kWidth, kHeight));
83 svg_dom->render(surface->getCanvas());
84
85 SkPixmap pixmap;
86 surface->peekPixels(&pixmap);
87
88 if (!SkPngEncoder::Encode(&output, pixmap, {})) {
89 printf("PNG encoding failed.\n");
90 return 1;
91 }
92 printf("Success!\n");
93 return 0;
94}
SK_API sk_sp< SkFontMgr > SkFontMgr_New_FontConfig(FcConfig *fc)
SK_API sk_sp< SkFontMgr > SkFontMgr_New_CoreText(CTFontCollectionRef)
VkSurfaceKHR surface
Definition: main.cc:49
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
char ** argv
Definition: library.h:9
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
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
constexpr size_t kHeight
constexpr size_t kWidth
const char * svg

Variable Documentation

◆ kHeight

constexpr size_t kHeight = 120
constexpr

Definition at line 33 of file svg_renderer.cpp.

◆ kWidth

constexpr size_t kWidth = 450
constexpr

Definition at line 32 of file svg_renderer.cpp.

◆ svg

const char* svg
Initial value:
= "<svg viewBox=\"0 0 150 40\" xmlns=\"http://www.w3.org/2000/svg\">"
"<style>"
"text {"
"font: 13px sans-serif;"
"}"
"</style>"
"<text x=\"10\" y=\"30\">VAVAVAVA</text>"
"</svg>"

Definition at line 36 of file svg_renderer.cpp.