- Notifications
You must be signed in to change notification settings - Fork244
An SVG rendering library.
License
Apache-2.0, MIT licenses found
Licenses found
linebender/resvg
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
resvg is anSVG rendering library.
It can be used as a Rust library, as a C library, and as a CLI application to render static SVG files.
The core idea is to make a fast, small, portable SVG library with the goal to support the whole SVG spec.
SVG is a very complicated format with a large specification (SVG 1.1 is almost 900 pages).You basically need a web browser to handle all of it. But the truth is that even browsersfail at this (seeSVG support).Yes, unlikeresvg
, browsers do support dynamic SVG features like animations and scripting.But using a browser to render SVGcorrectly is sadly not an option.
To prove its correctness,resvg
has a vast test suite that includes around 1600 tests.And those are only SVG-to-PNG regression tests. This doesn't include tests inresvg
dependencies.And the best thing is thatresvg
test suite is available to everyone. It's not tied toresvg
in any way. Which should help people who plan to develop their own SVG libraries.
It's hard not to mention safety when we talk about Rust and processing of a random input.And we're talking not only about SVG/XML, but also about CSS, TTF, PNG, JPEG, GIF, and GZIP.
Whileresvg
is not the only SVG library written in Rust, it's the only one thatis written completely in Rust. There is no non-Rust code in the final binary.
Moreover, there is almost nounsafe
code either. Still, some dependencies have someunsafe
codeand font memory-mapping is inherentlyunsafe
, but it's best you can get in terms of memory safety.
However, this doesn't stop at memory safety.resvg
has extensive checks to prevent endless loops (freezes)and stack overflows (via recursion).
Right now, theresvg
CLI application is less than 3MB in size and doesn't require any external dependencies.The binary contains nothing that isn't needed for rendering SVG files.
resvg
is guaranteed to work everywhere where you can compile the Rust itself,including WASM. There are some rough edges with obscure CPU architectures andmobile OSs (mainly system fonts loading), but it should be pretty painless otherwise.
Another major difference from other SVG rendering libraries is that inresvg
SVG parsing and rendering are two completely separate steps.Those steps are also split into two separate libraries:resvg
andusvg.Meaning you can easily write your own renderer on top ofusvg
using any 2D library of your liking.
Comparing performance between different SVG rendering libraries is like comparing apples and oranges.Everyone has a very different set of supported features, languages, build flags, etc...Anyhow, asresvg
is written in Rust and usestiny-skia for rendering - it's pretty fast.There should also still be quite a lot of room for improvement.
Sinceresvg
doesn't rely on any system libraries it allows us to have reproducible resultson all supported platforms. Meaning if you render an SVG file on x86 Windows and then render iton ARM macOS - the produced image will be identical. Each pixel would have the same value.
- No animations
There are no plans on implementing them either. - No native text rendering
resvg
doesn't rely on any system libraries, which implies that we cannot use native text rendering.Nevertheless, native text rendering is optimized for small horizontal text, which is notthat common in SVG. - Unicode-only
It's the 21st century. Text files that aren't UTF-8 encoded are no longer relevant.
resvg
aims to only support thestaticSVG subset; i.e. noa
,script
,view
orcursor
elements, no events and no animations.
SVG 2 support is being worked on.You can search for relevant issues with thesvg2 tagor ourSVG 2 changelog.
SVG Tiny 1.2 is not supported and support is also not planned.
Results of theresvg test suite:
SVG 2 only results:
You can find a complete table of supported featureshere.It also includes some alternative libraries.
We're not testing against all SVG libraries since many of them are pretty bad.Some libraries are not on the list because they don't pass the 25% mark.Such libraries are: wxSvg, LunaSVG and nanosvg.
There is a subtle difference between resvg as alibrary and resvg as aproject.While most users will interact only with the resvg library, it's just a tip of an iceberg.There are a lot of libraries that I had to write to make resvg possible.Here are some of them:
- resvg - the actual SVG renderer
- usvg - an SVG preprocessor/simplifier
- tiny-skia - aSkia subset ported to Rust
- rustybuzz - aharfbuzz subset ported to Rust
- ttf-parser - a TrueType/OpenType font parser
- fontdb - a simple, in-memory font database with CSS-like queries
- roxmltree - an XML parsing library
- simplecss - a pretty decent CSS 2 parser and selector
- pico-args - an absolutely minimal, but surprisingly popular command-line arguments parser
So while the resvglibrary is deceptively small (around 2500 LOC), the resvgprojectis nearing 75'000 LOC. Which is not that much considering how much resvg does.It's definitely the smallest option out there.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE orhttp://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT orhttp://opensource.org/licenses/MIT)
at your option.
Contributions are welcome by pull request.TheRust code of conduct applies.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.
About
An SVG rendering library.