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
  • C-API `resvg_options_set_font_family` doesn't work in release v0.28.0

    C-API `resvg_options_set_font_family` doesn't work in release v0.28.0

    Hello, I tried to use the function in my C++ project as I've done before, but when rendering the svg, text is not displayed after providing a font and calling the function with the font family. This used to work in releases before v0.28.0.

    I see in the commit history that this function was removed then added back, so maybe something was missed when reverting that change?

    The C++ project I'm referring to is: https://github.com/ANSH3LL/Graphics-Extensions-for-Solar2D and the line where I'm using the function is: https://github.com/ANSH3LL/Graphics-Extensions-for-Solar2D/blob/23151db1257915cf0aaa47df7728f6c0c4291b30/shared/PluginGfxe.cpp#L772

    opened by ANSH3LL 26
  • Add a way to enumerate fonts used in a SVG before rendering

    Add a way to enumerate fonts used in a SVG before rendering

    Loading fonts can be a pretty expensive operation, especially on targets like JS/Wasm, where there is no mmap-like feature, and one must load fonts asynchronously before invoking resvg.

    To optimise this case, it would be handy if usvg provided a way to get set of fonts used in the SVG document before rendering it to the final form. That way, resvg-js users, as well as native ones, could only load fonts that will be definitely necessary for rendering the document.

    I'm not sure how feasible this is given that usvg downcasts text to shapes as part of its processing, but maybe it could preserve text nodes in some intermediate form to give user the chance to do this async loading?

    opened by RReverser 23
  • 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
  • Support SVG Native

    Support SVG Native

    There is recent work to define an SVG Native spec, which is a subset of SVG 1.1. Adobe recently published a SVG Native Viewer library (C++ 11), and the FreeType project is considering resvg among the candidates as the backend for rendering OpenType+SVG fonts.

    I wonder how resvg relates to SVG Native, and if you have any plans to provide full compatibility to the SVG Native profile?

    • http://lists.nongnu.org/archive/html/freetype-devel/2019-05/threads.html#00064
    • https://w3c.github.io/svgwg/specs/svg-native/index.html
    • https://github.com/adobe/svg-native-viewer
    • https://docs.microsoft.com/en-us/typography/opentype/spec/svg
    • https://helpx.adobe.com/fonts/using/ot-svg-color-fonts.html

    There are some tools that allow people to make OpenType+SVG fonts

    • https://www.fontlab.com/font-editor/fontlab-vi/
    • https://github.com/microsoft/OpenType-SVG-Font-Editor
    • https://github.com/adobe-type-tools/opentype-svg
    opened by twardoch 19
  • 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
  • Support rendering parts/tiles of an SVG, repeatedly

    Support rendering parts/tiles of an SVG, repeatedly

    What

    I.e. I only want the lower left quadrant of the image I would specify a ViewBox with a Rect::new(0.5, 0.5, 0.5, 0.5). FitTo would then pertain to the size of that region, not the total canvas.

    Why

    I am looking into adding support for SVG textures to a 3D renderer. During render time the renderer will request texture tiles at certain resolutions. These tiles are the aforementioned sub images.

    Another use case is a viewer that e.g. allows zooming. When you zoom in 10000 times you do not want to be forced to render the whole canvas but only the visible portion.

    How

    ~~It would be best if this worked by creating some sort of persistent representation of the SVG that can be queried for such 'sub' Pixmaps to keep any initial set-up/overhead of parsing etc. a one time cost.~~

    ~~I.e. you would create an SVG struct and call render_region() or the like on it, repeatedly.~~

    I guess this already works efficiently when querying the same Tree/Node repeatedly?

    opened by virtualritz 17
  • 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
  • Build instructions

    Build instructions

    Please consider adding build instructions to resvg and usvg showing people how to build a binary using rust/Cargo. (I tried for about 30 minutes before giving up.)

    opened by DaveJarvis 9
  • Figure out how to implement custom markers paint order

    Figure out how to implement custom markers paint order

    Since usvg converts markers into regular nodes, we cannot render them between path's fill and stroke. Which is allowed by the spec. We can render them only below or above the path.

    The only way to implement this is by rewriting markers support. Basically removing this simplification step from usvg, which is unfortunate.

    svg2 
    opened by RazrFalcon 0
  • 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
Releases(v0.28.0)
Owner
Evgeniy Reizner
Evgeniy Reizner
🔭 Annict での今期の視聴状況を SVG 画像として出力するサーバ (WIP)

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

Nep 16 Dec 20, 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.4k Dec 25, 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 16 Jan 2, 2023
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 264 Dec 9, 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 79 Dec 9, 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 323 Dec 27, 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 59 Jan 6, 2023
A Simple-to-use, cross-platform Rust Webcam Capture Library

Cross Platform Rust Library for powerful Webcam Capture and Virtual Webcams

null 246 Jan 8, 2023
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 998 Jan 2, 2023
😱 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 12 Dec 2, 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 115 Jan 5, 2023
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 247 Dec 25, 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 97 Oct 18, 2022
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 47 Dec 30, 2022
Image operation rust library

Image operation rust library

LongYinan 166 Dec 20, 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