resvg

resvg is a high-performance SVG rendering library written in Rust. It can function as a Rust library, a C library, and a CLI application, making it versatile for various use cases involving static SVG files.

Core Features

Designed for Edge-Cases

SVG is complex, with the SVG 1.1 specification running nearly 900 pages. resvg aims to support the entire SVG spec. Its vast test suite, featuring around 1600 tests, ensures correctness. This suite is open to the public, aiding developers who wish to create their own SVG libraries.

Safety

Written entirely in Rust, resvg boasts minimal use of unsafe code, enhancing memory safety. It rigorously checks for issues like endless loops and stack overflows, crucial when processing random inputs such as SVG/XML, CSS, TTF, PNG, JPEG, GIF, and GZIP.

Zero Bloat

The resvg CLI application is less than 3MB and has no external dependencies. It includes only what's necessary for rendering SVG files, ensuring a lean and efficient tool.

Portability

resvg works on all platforms where Rust can be compiled, including WASM. Although there are minor challenges with obscure CPU architectures and mobile OSs, overall, it offers broad compatibility.

SVG Preprocessing

resvg separates SVG parsing and rendering into two distinct steps, facilitated by two libraries: resvg and usvg. This allows developers to create custom renderers using any 2D library.

Performance

With resvg leveraging [tiny-skia] for rendering, it delivers impressive performance. There is ongoing potential for further optimization.

Reproducibility

resvg's independence from system libraries ensures consistent results across all supported platforms. An SVG rendered on one platform will produce identical images on another, down to each pixel.

Limitations

  • No animations: resvg does not support and has no plans to support animations.
  • No native text rendering: resvg avoids system libraries, which precludes native text rendering. However, this is optimized for SVG's typical use cases.
  • Unicode-only: Embracing modern standards, resvg supports only UTF-8 encoded text files.

SVG Support

resvg focuses on the static SVG subset, excluding elements like a, script, view, or cursor, and excluding events and animations. Progress on SVG 2 support can be tracked through the svg2 tag and the SVG 2 changelog. Support for SVG Tiny 1.2 is neither available nor planned.

The resvg Project

The resvg project encompasses more than just the resvg library. It includes several auxiliary libraries developed to enable resvg's functionality:

  • resvg: The core SVG renderer
  • [usvg]: An SVG preprocessor and simplifier
  • [tiny-skia]: A subset of Skia ported to Rust
  • [rustybuzz]: A subset of Harfbuzz ported to Rust
  • [ttf-parser]: A TrueType/OpenType font parser
  • [fontdb]: An in-memory font database with CSS-like queries
  • [roxmltree]: An XML parsing library
  • [simplecss]: A CSS 2 parser and selector
  • [pico-args]: A minimal command-line arguments parser

Despite its relatively small size (around 2500 lines of code for the library), the entire resvg project comprises nearly 75,000 lines of code, reflecting its comprehensive capabilities.

Similar Projects