resvg is an SVG rendering library.
resvg can be used as:
to render SVG files based on a static SVG Full 1.1 subset (see SVG support for details).
The core idea is to make a fast, small, portable, multiple-backend SVG library designed for edge-cases.
SVG can be rendered to a raster image or to a backend's canvas (e.g. to a QWidget via QPainter).
resvg is competing with [librsvg], [QtSvg] and [Inkscape] (only as a CLI SVG-to-PNG converter).
One of the major differences from other rendering libraries is that resvg does a lot of preprocessing before rendering. It converts shapes to paths, resolves attributes, removes groups and invisible elements, fixes a lot of issues in malformed SVG files. Then it creates a simple render tree with all elements and attributes resolved. And only then it begins rendering. So it's very easy to implement a new rendering backend.
More details here.
librsvg is the main competitor to resvg. And even though librsvg itself is being rewritten in Rust, as resvg, the architecture of the library is completely different:
Inkscape is often used to convert SVG to PNG, but it's not an actual competitor to resvg, since it's still a complete vector editor, not a tiny library. Also, it's very slow. But it has the best SVG support amongst others.
Without a doubt, [QtSvg] is heavily used in [Qt] applications. But [QtSvg] itself is very limited. It officially supports only a tiny portion of the SVG Tiny 1.2 subset. In simple terms – it correctly renders only primitive SVG images. Also, it's deprecated.
resvg is aiming to support only the static
SVG subset; e.g. no a
, script
, view
or cursor
elements, no events and no animations.
A list of unsupported features can be found here.
SVG Tiny 1.2 and SVG 2.0 are not supported and not planned.
Results of the static subset of the SVG test suite:
Results of the resvg test suite:
You can find a complete table of supported features here. It also includes alternative libraries.
Note that all tested applications have a different SVG support, which impacts the performance.
Also, we do not test against Chrome, Firefox, Inkscape and Batik because they have a huge startup time.
QRasterPaintEngine
is slow..svgz
to .svg
beforehand.resvg
is slower than librsvg
because the Oxygen icon theme uses Gaussian blur heavily, which is expensive.
And librsvg
uses box blur optimization and multithreading, while resvg
always uses a single-threaded IIR blur (at least for now).filter
, clipPath
, mask
and pattern
that are heavily used in the Oxygen icon theme.
So it's actually very slow.resvg
– rendering backends implementation
All other dependencies aren't written by me for this project.
capi
– C/FFI interface for resvgdocs
– basic documentationexamples
– usage examples for resvg as a libraryresvg-qt
– minimal bindings to Qt used by resvgsrc
– source codetesting-tools
– scripts used for testingtools
– useful toolsusvg
– an SVG simplification library used by resvgunsafe
,
but since all backends are implemented via FFI, we are stuck with unsafe
anyway.
Also, usvg
uses unsafe for fonts memory mapping.resvg is licensed under the MPLv2.0.