19 unstable releases (8 breaking)

1.1.1 Mar 21, 2024
0.43.2 Oct 24, 2024
0.43.1 Sep 22, 2024
0.42.2 May 13, 2024
0.26.0 Nov 20, 2022

#252 in Images

Download history 356/week @ 2024-09-18 88/week @ 2024-09-25 27/week @ 2024-10-02 1/week @ 2024-10-09 4/week @ 2024-10-16 225/week @ 2024-10-23 53/week @ 2024-10-30 12/week @ 2024-11-06 15/week @ 2024-11-13 67/week @ 2024-11-20 23/week @ 2024-11-27 44/week @ 2024-12-04 69/week @ 2024-12-11 22/week @ 2024-12-18 55/week @ 2025-01-01

160 downloads per month
Used in 8 crates (6 directly)

MPL-2.0 license

585KB
14K SLoC

usvgr

Crates.io Documentation Rust 1.65+

usvgr (micro SVG) is an SVG parser that tries to solve most of SVG complexity.

SVG is notoriously hard to parse. usvgr presents a layer between an XML library and a potential SVG rendering library. It will parse an input SVG into a strongly-typed tree structure were all the elements, attributes, references and other SVG features are already resolved and presented in the simplest way possible. So a caller doesn't have to worry about most of the issues related to SVG parsing and can focus just on the rendering part.

Features

  • All supported attributes are resolved. No need to worry about inheritable, implicit and default attributes
  • CSS will be applied
  • Only simple paths
    • Basic shapes (like rect and circle) will be converted into paths
    • Paths contain only absolute MoveTo, LineTo, QuadTo, CurveTo and ClosePath segments. ArcTo, implicit and relative segments will be converted
  • use will be resolved and replaced with the reference content
  • Nested svg will be resolved
  • Invalid, malformed elements will be removed
  • Relative length units (mm, em, etc.) will be converted into pixels/points
  • External images will be loaded
  • Internal, base64 images will be decoded
  • All references (like #elem and url(#elem)) will be resolved
  • switch will be resolved
  • Text elements, which are probably the hardest part of SVG, will be completely resolved. This includes all the attributes resolving, whitespaces preprocessing (xml:space), text chunks and spans resolving
  • Markers will be converted into regular elements. No need to place them manually
  • All filters are supported. Including filter functions, like filter="contrast(50%)"
  • Recursive elements will be detected and removed
  • objectBoundingBox will be replaced with userSpaceOnUse

Limitations

  • Unsupported SVG features will be ignored
  • CSS support is minimal
  • Only static SVG features, e.g. no a, view, cursor, script, no events and no animations

License

usvgr is licensed under the MPLv2.0.

Dependencies

~3.5–5MB
~91K SLoC