resvg is an SVG rendering library.

Overview

resvg

Build Status Crates.io Documentation

resvg is an SVG rendering library.

Purpose

resvg can be used as a Rust library, a C library and as a CLI application to render SVG files based on a static SVG Full 1.1 subset.

The core idea is to make a fast, small, portable SVG library designed for edge-cases. Right now, a resvg CLI application is less than 3MiB and doesn't require any external dependencies.

Another major difference from other SVG rendering libraries is that resvg does a lot of preprocessing before rendering. It converts an input SVG into a simplified one called Micro SVG and only then it begins rendering. So it's very easy to implement a new rendering backend. But we officially support only one. And you can also access Micro SVG as XML directly via the usvg tool.

SVG support

resvg is aiming to support only the static SVG subset; e.g. no a, script, view or cursor elements, no events and no animations.

SVG Tiny 1.2 and SVG 2.0 are not supported and not planned.

Results of the resvg test suite:

You can find a complete table of supported features here. It also includes alternative libraries.

Performance

Comparing performance between different SVG rendering libraries is like comparing apples and oranges. Everyone has a very different set of supported features, implementation languages, build flags, etc. But since resvg is written in Rust and uses tiny-skia for rendering - it's pretty fast.

Safety

resvg and most of its dependencies are pretty safe. The main exception is fonts memory mapping.

License

resvg project is licensed under the MPLv2.0.

Comments
  • Raqote backend

    Raqote backend

    TODO:

    • [x] Ugly stroking: e-image-003 (especially S), e-image-017, e-image-022 (clearly visible) (raqote bug)
    • [x] a-stroke-dasharray-004 (raqote bug)
    • [x] a-stroke-linecap-004 (should be done on the resvg size)
    • [x] a-stroke-linecap-005 (should be done on the resvg size)
    • [x] e-clipPath-019
    • [x] e-feBlend-002 (raqote bug, BlendMode::Multiply produce nothing)
    • [x] e-image-010 (raqote bug? Looks like some issue with a pattern.)
    • [x] e-mask-007 (~~raqote bug? Looks like something is wrong with clip~~)
    • [x] e-path-013 (raqote bug)
    • [x] e-radialGradient-011 (raqote bug)
    • [x] e-radialGradient-029
    • [x] ~~e-stop-016 (raqote bug)~~
    • [x] Markers are very slow, aka multiple sublayers.
    • [x] Optional anti-aliasing.

    Closes #134

    opened by RazrFalcon 84
  • Render text in wasm32-unknown-unknown

    Render text in wasm32-unknown-unknown

    usvg currently works great in wasm environments as long as the optional "text" feature is disabled. I'd love to get text support working too. From my understanding so far, there are at least 3 issues:

    • a dependency on memmap2, used for reading fonts
    • reading fonts from system directories (#202)
    • a dependency on harfbuzz

    The first two are relatively straightforward. As part of #202, design an API to feed a FontDB into usvg that can be instantiated many different ways, one of them just being raw bytes of a font file. (include_bytes! is a low-effort way to get this working in a wasm environment.)

    The harfbuzz dependency seems harder. My requirements are limited to simple Latin left-to-right text; harfbuzz is overkill. I found font2svg and think it might be possible to make something much simpler. Before I go down this rabbit hole, I wanted to ask for your advice.

    Background

    I'm using usvg in A/B Street to turn both normal SVG files and text into paths for lyon, which then give me polygons. This does the usvg->lyon->my simple Polygon abstraction path, based off this example from lyon. I'm using this same pipeline for text as well. (There are many inefficient and silly things that the text pipeline does right now, like constantly re-load fonts.) In a few weeks, I'm hoping to properly split off my drawing, geometry, and GUI libraries as new crates for other people to use. These libraries attempt to give exactly the same experience on native and web -- not using system UI controls/style -- without any changes to user code needed for different platforms.

    opened by dabreegster 21
  • Benchmark on something other than icons

    Benchmark on something other than icons

    Benchmarking on icons only is not particularly representative of performance in general.

    I've tried rendering Inkscape about screens as they're bigger than icons and represent a wide variety of SVG feature combinations, using more advanced features over time as Inkscape itself evolved.

    On my machine resvg takes 1 second to render them all while librsvg takes 5 seconds. I've blacklisted 0.48 splash screen as it has some unsupported filters. librsvg also renders the 0.92 splash screen incorrectly, while resvg works fine.

    opened by Shnatsel 18
  • Skia backend

    Skia backend

    TODO:

    • [x] Sync with master.
    • [ ] e-pattern-18
    • [ ] e-marker-22 is very slow
    • [x] Support older Skia.
    • [x] Update BUILD.adoc
    • [x] Test on all platforms.
    • [ ] ~~Test on CI.~~

    Closes #44

    opened by RazrFalcon 17
  • Support providing a separate fontdb

    Support providing a separate fontdb

    I would like to provide my own set of fonts with my application (as binary objects) and not reply on any system fonts at all. Is there a way to skip all system font resolution and to provide a font manually?

    opened by hjmallon 16
  • Use Skia Canvas instead of Surface where possible

    Use Skia Canvas instead of Surface where possible

    Hey, I've made some changes to allow you to use Skia's Canvas wherever possible. This allows you to use resvg with PDFs 🎉.

    https://skia.org/user/api/skcanvas_creation

    The SkPDF backend uses SkDocument instead of SkSurface, since a document must include multiple pages.

    Something like this:

    let pdf_doc = skia::PDF::make_document(&pdf_stream);
    let pdf_canvas = pdf_doc.begin_page(width, height);
    resvg::backend_skia::render_to_canvas(&tree, &opt, size, pdf_canvas);
    
    opened by therealbnut 16
  • If font-family is not found, no text is rendered

    If font-family is not found, no text is rendered

    Hi, this is really more of a question than a bug probably. I am setting up a new Windows 10 build server for OpenShot, and noticed that resvg.dll does not render any text. It does in fact render other shapes, gradients, and lines just fine... but anywhere "text" is supposed to be, it renders nothing.

    git clone https://github.com/RazrFalcon/resvg
    cd resvg/capi
    QT_DIR="C:\\msys64\\mingw64\\" cargo build --verbose --release --features="qt-backend"
    

    I compiled resvg on MSYS2 (using the latest version of Qt 5.12.4). No errors were reported during the build. I was also able to link to it with no issues. When OpenShot renders a SVG file though, all text is missing.

    So, just curious if this rings a bell or if this is something silly on my part, missing a dependency, etc... If not, what do you suggest as the best way to troubleshoot an issue like this? Thank again!

    opened by jonoomph 16
  • Provide vendored tarball

    Provide vendored tarball

    I'm the maintainer of the OpenShot (https://www.openshot.org) flatpak (https://flatpak.org):

    https://flathub.org/apps/details/org.openshot.OpenShot https://github.com/flathub/org.openshot.OpenShot

    In version 2.4.4 of OpenShot, a dependency on resvg was added.

    While building the flatpak, no network access is permitted. To make compiling with cargo possible, other flatpaks like e.g. GNOME Fractal (https://gitlab.gnome.org/GNOME/fractal) use cargo vendor (https://crates.io/crates/cargo-vendor) to offer tarballs that bundle all rust dependencies:

    https://gitlab.gnome.org/GNOME/fractal/uploads/ad6a483327c3e9ef5bb926b89fb26e2b/fractal-4.0.0.tar.xz

    opened by eszlari 16
  • Error: the file has no valid ID's

    Error: the file has no valid ID's

    I'm trying to - once again - replace inkscape with resvg tools but I'm already running into problems using --query-all. This is my test svg file:

    <svg
       xmlns="http://www.w3.org/2000/svg"
       version="1.1"
       width="800"
       height="1970"
       viewbox="0 0 800 1970">
        <g id="notice">
            <g id="n-2ddbd3ff-a1c8-4775-89fe-892a8c4066fc">
                <g id="n-2026ef7e-e1b4-419b-b0d4-5d2a7a83d4a1">
                <text id="n-2026ef7e-e1b4-419b-b0d4-5d2a7a83d4a1-line-1" x="675" y="39">
                    <tspan x="504" y="39" id="tspan15">Test</tspan>
                </text>
                </g>
            </g>
        </g>
    </svg>
    
    

    What am I missing here? Shouldn't resvg find at least 5 IDs?

    This is the inkscape output:

    svg7,504.12,30.432,22.2959,8.688
    notice,504.12,30.432,22.2959,8.688
    n-2ddbd3ff-a1c8-4775-89fe-892a8c4066fc,504.12,30.432,22.2959,8.688
    n-2026ef7e-e1b4-419b-b0d4-5d2a7a83d4a1,504.12,30.432,22.2959,8.688
    n-2026ef7e-e1b4-419b-b0d4-5d2a7a83d4a1-line-1,504.12,30.432,22.2959,8.688
    tspan15,504.12,30.432,22.2959,8.688
    
    opened by daviddeutsch 15
  • Add features to build for web-sys. #229

    Add features to build for web-sys. #229

    This is the other half of https://github.com/RazrFalcon/resvg/issues/229. A user can depend on usvg with default-features = false, features = ["text", "text_web-sys"] to enable this new behavior.

    After the PR in fontdb is merged, I'll change this PR to pin to the latest git commit on the upstream fontdb repo, and regenerate Cargo.lock for usvg.

    I tested both of these PRs by pinning A/B Street web to my local copies.

    opened by dabreegster 15
  • [usvg] slow compared to librsvg, inkscape, batik for specific file

    [usvg] slow compared to librsvg, inkscape, batik for specific file

    I compared the average rendering times for 141 images at https://commons.wikimedia.org/wiki/Category:Featured_pictures_on_Wikimedia_Commons_-_vector

    With https://commons.wikimedia.org/wiki/Commons:Imker_(batch_download) you can download the whole category at commons.

    I know resvg supports more features (e.g: textPath) and maybe has a better precession (e.g. gausian blur), however I wondered that it was the slowest of all rendering engines, even slower than Inkscape.

    svg | librsvg 2.50.3 | resvg 0.14.0 | Inkscape 1.0.2 | batik 1.14 -- | -- | -- | -- | -- time | 8,82min | 24,58min | 18,82min | 19,2min

    -I think all of the rendering-engines use singe-CPU? -Since I did hardly use the PC during rendering, CPU,RAM,SSD should have almost no utilization. So I don't think it is because of CPU-prioritization . -Since librsvg renders nearly all files almost correct, the time-difference should imho be neglibible. -Since it contains 141 files I don't think it is related to a singe file

    I know it is bad elaborated bug-report, but maybe you can comment on that where I should reinvestigate.

    PS: Do you know how to check the CPU-times of commands in a bash-script?

    opened by JoKalliauer 14
  • Anti-aliased edges of patterns with non-integer width/height

    Anti-aliased edges of patterns with non-integer width/height

    Hallo, I've noticed that patterns result in some anti-aliasing issues at the edges, if they have non-integer dimensions and the shapes inside the pattern go right against the edge.

    To illustrate the case I made a large white rectangle covered by a rectangle on top, which has a pattern of 20.13x20.13 containing just a black rectangle filling the pattern exactly. In the PNG result you can see the white shining through, but the whole area should be black. (Note: the viewBox is only 0 0 200 200, but the image has to be larger to see the effect, so its width and height are set to 1000)

    Any of these workarounds make it render correctly:

    • the pattern has a width of 20x20
    • the rectangle inside the pattern extends past the pattern dimensions, e.g. from -1,-1 to 21,21
    • the rectangle inside the pattern uses shape-rendering "crispEdges"

    but I believe the result should be the same without any of them.

    Perhaps the pattern should be copied on all four sides while rendering its content?

    pattern-anti-aliasing

    pattern-anti-aliasing

    opened by or 10
  • `usvg --keep-named-groups` also keeps transforms

    `usvg --keep-named-groups` also keeps transforms

    Given the following input:

    <svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
      <g id="grp" transform="translate(2,2)" fill="blue">
        <rect id="sq" x="1" y="1" width="4" height="4"/>
      </g>
    </svg>
    

    Running usvg resolves attributes as expected:

    <svg width="10" height="10" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
        <defs/>
        <path id="sq" fill="#0000ff" stroke="none" transform="matrix(1 0 0 1 2 2)" d="M 1 1 L 5 1 L 5 5 L 1 5 Z"/>
    </svg>
    

    However, when running usvg --keep-named-groups the transform from the group is translated to its matrix form but not propagated to the descendants, leaving the path element with an implicit/inherited transform attribute:

    <svg width="10" height="10" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
        <defs/>
        <g id="grp" transform="matrix(1 0 0 1 2 2)">
            <path id="sq" fill="#0000ff" stroke="none" d="M 1 1 L 5 1 L 5 5 L 1 5 Z"/>
        </g>
    </svg>
    

    It feels like we would expect the following output in order to comply with the Micro SVG spec:

    <svg width="10" height="10" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
        <defs/>
        <g id="grp">
            <path id="sq" fill="#0000ff" stroke="none" transform="matrix(1 0 0 1 2 2)" d="M 1 1 L 5 1 L 5 5 L 1 5 Z"/>
        </g>
    </svg>
    
    opened by snoyer 4
  • Try to bake transforms when possible

    Try to bake transforms when possible

    We can bake/apply transforms to paths filled/stroked with solid colors.

    This is not really a performance optimization, but rather a way to simplify input files even more.

    usvg 
    opened by RazrFalcon 6
  • feat: support paint order

    feat: support paint order

    This modifies desire to paint strokes below fills without having to duplicate an element. paint-order is a standard specification of svg2 as discussed #422

    opened by tyutjohn 4
Releases(v0.23.0)
Owner
Evgeniy Reizner
Evgeniy Reizner
🔭 Annict での今期の視聴状況を SVG 画像として出力するサーバ (WIP)

annict-profile-card ?? Annict の視聴状況などを SVG 画像として出力する API サーバ (WIP) Annict GraphQL API を使用しています。

Nep 15 Aug 13, 2022
Convert your ascii diagram scribbles into happy little SVG

Svgbob Svgbob can create a nice graphical representation of your text diagrams. Svgbob provides a cli which takes text as an input and creates an svg

Jovansonlee Cesar 3.3k Sep 24, 2022
The tool to make svg with triangles by length from two points.

The tool to make svg with triangles by length from two points.

null 2 Sep 27, 2021
Convert UFO .glif files to SVG, whether they're part of a font or not

Convert UFO glyph files (.glif) to SVG There exists already an svg2glif, but for some reason not the opposite operation. My MFEKglif editor treats .gl

Modular Font Editor K 3 Apr 26, 2022
A Rust-implementation of devout’s tutorial to create an SVG graphic device using extendr.

A Rust-implementation of devout’s tutorial to create an SVG graphic device using extendr.

Hiroaki Yutani 1 Jan 25, 2022
Use free svg icons in your Dioxus projects easily with dioxus-free-icons.

dioxus-free-icons Use free svg icons in your Dioxus projects easily with dioxus-free-icons. More information about this crate can be found in the crat

Daiki Nishikawa 10 Sep 22, 2022
A Rust library for calculating perceptual hash values of images

img_hash Now builds on stable Rust! (But needs nightly to bench.) A library for getting perceptual hash values of images. Thanks to Dr. Neal Krawetz f

Austin Bonander 253 Sep 17, 2022
A simple steganography library written in rust

steganography A stable steganography library written in rust Crates.io Usage Add the following to the Cargo.toml in your project: [dependencies] stega

Teodor Voinea 74 Aug 22, 2022
Face detection library for the Rust programming language

Rustface SeetaFace detection library for the Rust programming language Example of demo program output SEETAFACE C++ – Github repository for the origin

Andrei Tomashpolskiy 310 Sep 21, 2022
2D polyline/shape library for offsetting, combining, etc.

This project is a continuation of the C++ CavalierContours library rewritten in Rust with the goal of building out more functionality, better

Jedidiah Buck McCready 52 Aug 26, 2022
A Simple-to-use, cross-platform Rust Webcam Capture Library

Cross Platform Rust Library for powerful Webcam Capture and Virtual Webcams

null 167 Sep 21, 2022
A linear algebra and mathematics library for computer graphics.

cgmath-rs A linear algebra and mathematics library for computer graphics. The library provides: vectors: Vector2, Vector3, Vector4 square matrices: Ma

rustgd 971 Sep 21, 2022
😱 Dead fast thumbnail library for browser and NodeJs! Built with Rust 🦀 and WebAssembly 🕸

thumbo-core ?? Dead fast thumbnail library for browser and NodeJs Built with Rust ?? & WebAssembly ?? ?? About thumbo-core is a thubnail library for b

Victor Aremu 10 Mar 31, 2022
Rust library for fast image resizing with using of SIMD instructions.

fast_image_resize Rust library for fast image resizing with using of SIMD instructions. CHANGELOG Supported pixel formats and available optimisations:

Kirill Kuzminykh 86 Sep 6, 2022
PNG decoding and encoding library in pure Rust

PNG Decoder/Encoder PNG decoder/encoder in pure Rust. It contains all features required to handle the entirety of the PngSuite by Willem van Schack. p

image-rs 237 Sep 18, 2022
An advanced image processing library for Rust.

ImageProc Maintainers: @chyh1990 Note: this project is under active depvelopment, API may change! imageproc is a advanced image proccessing library fo

Chen Yuheng 96 Dec 17, 2021
Rust library to get image size and format without loading/decoding

imageinfo-rs Rust library to get image size and format without loading/decoding. The imageinfo don't get image format by file ext name, but infer by f

xiaozhuai, Weihang Ding 43 Jul 8, 2022
Image operation rust library

Image operation rust library

LongYinan 159 Sep 5, 2022
ePaperify: Framebuffer/image pre-processing library for e-Paper displays

ePaperify: Framebuffer/image pre-processing library for e-Paper displays

Jackson Ming Hu 5 Mar 15, 2022