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.

Issues
  • 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
  • Skia backend

    Skia backend

    opened by RazrFalcon 29
  • Use a faster Gaussian blur algorithm

    Use a faster Gaussian blur algorithm

    The current one is pretty slow and single-threaded.

    • [ ] Faster/parallel IIR blur
    • [x] #83
    help wanted optimization 
    opened by RazrFalcon 27
  • Support latest skia

    Support latest skia

    opened by RazrFalcon 22
  • 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
  • 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
  • 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
  • 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
  • No match for any font generic names or substituted names

    No match for any font generic names or substituted names

    Warning (in usvg::text::convert:424): No match for 'Courier,monospace' font-family Warning (in usvg::text::convert:424): No match for 'Helvetica,Arial,sans-serif' font-family. Warning (in usvg::text::convert:424): No match for 'sans-serif' font-family.

    The warnings are kind of correct, but also wrong. There are no fonts with these names installed on the system. However, FontConfig is set up with substitutions for all the named fonts, and it has defaults for the generic font names defined. This is the default in most Linux distributions. I’m not sure what further details you need.

    Fedora Linux 35, resvg 0.19.0

    opened by da2x 3
  • Possibility to take image buffer from memory instead reading file from disk following <image>

    Possibility to take image buffer from memory instead reading file from disk following "xlink:href" attribute

    🙌🏻 Hey and thank you for your hard work again!

    As far as I see, there are 2 ways to read external image files in xlink:href attribute for <image> tag:

    1. Use base64.
    2. Use path to a local file.

    Now, hear me out: would it be possible to use xlink:href attribute that instead path would have some key by which we can read image buffer from memory directly, e.g. use existing Vec instead.

    The use case is that I basically have an image buffer already and I construct SVG dynamically. To avoid encoding image to base64 (which can be huge for big images) or writing it to disk, I could just pass the already prepared buffer to resvg/usvg by key.

    Implementation wise, it could be handled somewhere inside get_href_data function in usvg/src/image.rs.

    I understand that it is probably totally out of scope since resvg library just follows SVG specifications, but I would love to hear what author thinks about it. 🙏🏻 Maybe it's all is overkill and I should just transform image to base64?

    opened by antmelnyk 4
  • [μsvg] convert SVG 2.0 to micro SVG 1.1

    [μsvg] convert SVG 2.0 to micro SVG 1.1

    My library/framework/language/software doesn't have a good SVG library, and only supports the current SVG 1.1-Standard.

    I would like to convert SVG 2.0 to micro SVG 1.1 (as much as possible) to be compatible with my library/framework/language/software.

    I would like to have a option to output a micro SVG 1.1 (I don't mind if it is buggy/slow, but the most common features should be implemented).

    opened by JoKalliauer 2
  • Bidirectional text error

    Bidirectional text error

    <?xml version="1.0" encoding="utf-8"?>
    <svg xmlns="http://www.w3.org/2000/svg"
         width="100%" height="100%" viewBox="0 0 600 72"
         direction="rtl" xml:lang="he">
    
      <title direction="ltr" xml:lang="en">Right-to-left Text</title>
      <desc direction="ltr" xml:lang="en">
        An example for using the 'direction' and 'unicode-bidi' properties
        in documents that predominantly use right-to-left languages.
      </desc>
    
      <text x="300" y="50" text-anchor="middle" font-size="36"> כתובת MAC:&#x200F;
        <tspan direction="ltr" unicode-bidi="embed">00-24-AF-2A-55-FC</tspan> 
      </text>
    </svg>
    

    Test source: https://people.gnome.org/~federico/blog/text-in-librsvg.html

    Chrome

    image

    resvg 0.19.0

    image

    opened by yisibl 1
  • Inconsistent text rendering

    Inconsistent text rendering

    <?xml version="1.0" encoding="utf-8"?>
    <svg xmlns="http://www.w3.org/2000/svg" width="600" height="300">
      <rect x="0" y="0" width="100%" height="100%" fill="white"/>
      <line x1="50%" y1="0" x2="50%" y2="100%" stroke-width="2" stroke="blue"/>
      <line x1="0" y1="100" x2="100%" y2="100" stroke-width="2" stroke="blue"/>
    
      <text x="50%" y="100" font-family="Ahem" font-size="20" text-anchor="end"><tspan dy="-1em">A</tspan><tspan dx="-40" dy="1em">BC</tspan></text>
    </svg>
    

    Chrome

    image

    resvg 0.19.0

    image

    font: https://github.com/web-platform-tests/wpt/blob/master/fonts/Ahem.ttf

    opened by yisibl 0
  • Kerning support via `kerning` or `font-kerning` attributes

    Kerning support via `kerning` or `font-kerning` attributes

    Hey, thank you for the great library 🙌🏻 .

    The issue is about: https://www.w3.org/TR/css-fonts-3/#font-kerning-prop or https://www.w3.org/TR/SVG11/text.html#KerningProperty

    Do I understand correctly that kerning is automatically turned on? And if yes, is it possible to turn it off? I've tried to play with kerning and font-kerning attributes but seems like they don't have any impact. I see there is a-kerning.svg in the tests, but I struggle to find any usage of the attribute inside the source code of a library as well as difference when changing the attribute value.

    If kerning is automatically on, how it's actually implemented? Does it use kern from the font data?

    opened by antmelnyk 4
  • Return errors instead of crashing

    Return errors instead of crashing

    Hi! Thanks for the great library! :)

    I use the c-api binding in resvg-0.19. I noticed that my C++ application crashes if I provide NULL as options to resvg_parse_tree_from_data(). Maybe there are more cases to reproduce the issue unknown to me.

    The request is to return an error and print a warning in such cases, but not to crash the whole application.

    Thanks in advance.

    opened by HappySeaFox 3
  • usvg slow

    usvg slow

    file: https://gitlab.gnome.org/GNOME/librsvg/uploads/028b1646a203b470ac46c3281c9b12f7/case.svg

    time

    |usvg|resvg|librsvg2.50|inkscape|batik| |---|---|---|---|---| |86,875s|100,089s|0,331s|1,605s|20,416s|

    Copyright

    license: -no permission -maybe below Treshhold of orginality

    author: https://gitlab.gnome.org/oleksandr.khylobokyi

    source: https://gitlab.gnome.org/GNOME/librsvg/-/issues/683

    opened by JoKalliauer 0
  • Support SVG2 orient=

    Support SVG2 orient="auto-start-reverse"

    • Doc: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/orient
    • Test case:
    <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
      <defs>
        <!-- arrowhead marker definition -->
        <marker id="arrow" viewBox="0 0 10 10" refX="5" refY="5"
            markerWidth="6" markerHeight="6"
            orient="auto-start-reverse">
          <path d="M 0 0 L 10 5 L 0 10 z" />
        </marker>
      </defs>
    
      <!-- Coordinate axes with a arrowhead in both direction -->
      <polyline points="10,10 10,90 90,90" fill="none" stroke="black"
       marker-start="url(#arrow)" marker-end="url(#arrow)"  />
    </svg>
    
    svg2 
    opened by yisibl 4
Releases(v0.19.0)
Owner
Evgeniy Reizner
Evgeniy Reizner
🔭 Annict での今期の視聴状況を SVG 画像として出力するサーバ (WIP)

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

Nep 12 Nov 22, 2021
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 3k Nov 24, 2021
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 1 Oct 27, 2021
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 219 Nov 24, 2021
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 67 Nov 5, 2021
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 290 Nov 18, 2021
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 22 Nov 22, 2021
A Simple-to-use, cross-platform Rust Webcam Capture Library

Cross Platform Rust Library for powerful Webcam Capture and Virtual Webcams

null 79 Nov 20, 2021
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 871 Nov 19, 2021
😱 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 8 Nov 6, 2021
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 41 Nov 29, 2021
An SVG toolkit based on resvg

rusty-svg An SVG toolkit based on resvg This module is compiled to WASM and currently only supports Node.js Comparing with the backend ReSVG, this mod

Zimon Dai 8 Sep 19, 2021
A high-performance SVG renderer, powered by Rust based resvg and napi-rs.

resvg-js resvg-js is a high-performance SVG renderer, powered by Rust based resvg and napi-rs. Fast, safe and zero dependencies! No need for node-gyp

一丝 66 Nov 20, 2021
An SVG rendering library.

resvg 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 o

Evgeniy Reizner 1.1k Nov 24, 2021
svgcleaner could help you to clean up your SVG files from the unnecessary data.

svgcleaner svgcleaner helps you clean up your SVG files, keeping them free from unnecessary data. Table of Contents Purpose Goals Alternatives Charts

Evgeniy Reizner 1.4k Nov 21, 2021
🔭 Annict での今期の視聴状況を SVG 画像として出力するサーバ (WIP)

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

Nep 12 Nov 22, 2021
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 3k Nov 24, 2021
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 1 Oct 27, 2021
Sub-pixel precision light spot rendering library for astronomy and video tracking applications.

Planetarium Sub-pixel precision light spot rendering library for astronomy and video tracking applications. Example usage use planetarium::{Canvas, Sp

Sergey Kvachonok 3 Nov 23, 2021
grr and rust-gpu pbr rendering

grr-gltf Barebone gltf viewer using grr and rust-gpu. Currently only supports a single gltf model! Assets These files need to be downloaded and placed

Markus Siglreithmaier 28 Nov 24, 2021
Vulkan rendering sandbox for raytracing

sol-rs ☀ sol-rs is a small rendering toolkit for Vulkan, with a focus on real-time raytracing (which is not currently available via other APIs such as

Éric Renaud-Houde 56 Aug 9, 2021
Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering.

Provok Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering. Input Provok is fed with a JSON

Ossama Hjaji 53 Oct 31, 2021
A tilemap rendering crate for bevy which is more ECS friendly.

bevy_ecs_tilemap A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile. Features A tile per entity Fast renderin

John 118 Nov 25, 2021
Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions

Introduction Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions. (hand interaction with boxes missing

Mika 29 Oct 26, 2021
Modify fonts to remove bitmap and disable gridfit for Windows font rendering.

Since Windows 10 version 1703 (Creators Update), its built-in TrueType renderer now supports vertical anti-aliasing. Despite there are only 30 levels of grayscale shade, it dramatically improves text rendering, especially for CJK languages. Sadly, it is only enabled for selected fonts at selected sizes.

Star Brilliant 13 Aug 27, 2021
Perseus is a blazingly fast frontend web development framework built in Rust with support for major rendering strategies

Perseus is a blazingly fast frontend web development framework built in Rust with support for major rendering strategies, reactivity without a virtual DOM, and extreme customizability

arctic_hen7 324 Nov 30, 2021
Detect whether the current terminal supports rendering hyperlinks

Detects whether the current terminal supports hyperlinks in terminal emulators. It tries to detect and support all known terminals and terminal famili

Kat Marchán 15 Nov 9, 2021