Skip to content

Using blend2d vector library as backed to svg rendering

License

Notifications You must be signed in to change notification settings

christianbrugger/svg2b2d

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

svg2b2d

SVG parser, using blend2d as backend renderer

Accordion

look at projects/genimage to see how easy it is to construct a BLImage from an SVG

The main interface is in svg.h

#pragma once

#include "blend2d.h"


#ifdef __cplusplus
extern "C" {
#endif

bool parseSVG(const void *bytes, const size_t sz, BLImage &outImage);

#ifdef __cplusplus
}
#endif

The process of using it is as simple as this:

#include "blend2d.h"
#include "mmap.h"
#include "svg.h"

using namespace filemapper;
using namespace svg2b2d;

int main(int argc, char** argv)
{
    if (argc < 2)
    {
        printf("Usage: genimage <svg file>  [output file]\n");
        return 1;
    }

    // create an mmap for the specified file
    const char *filename = argv[1];
    auto mapped = mmap::createShared(filename);

    if (mapped == nullptr)
        return 0;

    // Create the BLImage we're going to draw into
    BLImage outImage(1000, 1000, BL_FORMAT_PRGB32);

    // parse the svg, and draw it into the image
    parseSVG(mapped->data(), mapped->size(), outImage);
    
    // save the image to a png file
    const char *output = argc > 2 ? argv[2] : "output.png";
    outImage.writeToFile(output);

    // close the mapped file
    mapped->close();


    return 0;
}

The generated image will be the size of the .svg.

If you want to try the svg2png.exe it's like this:

svg2png.exe filename.svg fileout.png

If you leave off the "fileout.png", it will use 'output.png' as the filename.

And that's it!

About

Using blend2d vector library as backed to svg rendering

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 99.3%
  • Other 0.7%