43 breaking releases

0.44.0 Sep 28, 2024
0.42.0 Jun 1, 2024
0.40.0 Feb 17, 2024
0.37.0 Dec 16, 2023
0.2.0 May 23, 2018

#178 in Images

Download history 55987/week @ 2024-10-19 56781/week @ 2024-10-26 65172/week @ 2024-11-02 46295/week @ 2024-11-09 53900/week @ 2024-11-16 58021/week @ 2024-11-23 60607/week @ 2024-11-30 63131/week @ 2024-12-07 63613/week @ 2024-12-14 32171/week @ 2024-12-21 39824/week @ 2024-12-28 65129/week @ 2025-01-04 74690/week @ 2025-01-11 71258/week @ 2025-01-18 72982/week @ 2025-01-25 67949/week @ 2025-02-01

299,311 downloads per month
Used in 386 crates (106 directly)

MPL-2.0 license

590KB
14K SLoC

usvg

Crates.io Documentation Rust 1.65+

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

SVG is notoriously hard to parse. usvg 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

usvg is licensed under the MPLv2.0.

Dependencies

~2.2–3.5MB
~65K SLoC