Crate usvg [] [src]

usvg (micro SVG) is an SVG simplification tool.

Purpose

Imagine, that you have to extract some data from the SVG file, but your library/framework/language doesn't have a good SVG library. And all you need is paths data.

You can try to export it by yourself (how hard can it be, right). All you need is an XML library (I'll hope that your language has one). But soon you realize that paths data has a pretty complex format and a lot of edge-cases. And we didn't mention attributes propagation, transforms, visibility flags, attribute values validation, XML quirks, etc. It will take a lot of time and code to implement this stuff correctly.

So, instead of creating a library that can be used from any language (impossible), usvg takes a different approach. It converts an input SVG to an extremely simple representation, which is still a valid SVG. And now, all you need is to convert your SVG to a simplified one via usvg and an XML library with some small amount of code.

Key features of the simplified SVG

  • No basic shapes (rect, circle, etc). Only paths
  • Simple paths:
    • Only MoveTo, LineTo, CurveTo and ClosePath will be produced
    • All path segments are in absolute coordinates
    • No implicit segment commands
    • All values are separated by space
  • All (supported) attributes are resolved. No implicit one
  • No use. Everything is resolved
  • No invisible elements
  • No invalid elements (like rect with negative/zero size)
  • No units (mm, em, etc.)
  • No comments
  • No DTD
  • No CSS (partial support)
  • No script (simply ignoring it)

Full spec can be found here.

Limitations

  • Currently, it's not lossless. Some SVG features isn't supported yet and will be ignored.
  • CSS support is minimal.
  • Scripting and animation isn't supported and not planned.
  • a elements will be removed.
  • Unsupported elements:
    • filter-based elements
    • font-based elements
    • marker
    • symbol
    • view
    • foreignObject

Re-exports

pub extern crate svgdom;

Modules

tree

Implementation of the nodes tree.

Structs

Options

Processing options.

Enums

FileReadError

List of errors that can be produced by parse_tree_from_file.

Functions

load_svg_file

Loads SVG, SVGZ file content.

parse_tree_from_data

Parsers Tree from SVG data.

parse_tree_from_dom

Parsers Tree from svgdom::Document.

parse_tree_from_file

Parsers Tree from file.

Type Definitions

Rect

Alias for euclid::Rect<f64>.

Size

Alias for euclid::Size2D<f64>.