28 breaking releases

0.29.0 Feb 6, 2023
0.28.0 Dec 3, 2022
0.27.0 Nov 26, 2022
0.23.0 Jun 11, 2022
0.2.0 May 23, 2018

#14 in Images

Download history 7250/week @ 2022-12-01 8513/week @ 2022-12-08 5912/week @ 2022-12-15 5060/week @ 2022-12-22 6157/week @ 2022-12-29 6495/week @ 2023-01-05 6643/week @ 2023-01-12 7032/week @ 2023-01-19 7667/week @ 2023-01-26 9885/week @ 2023-02-02 9055/week @ 2023-02-09 9577/week @ 2023-02-16 8713/week @ 2023-02-23 8004/week @ 2023-03-02 8567/week @ 2023-03-09 8464/week @ 2023-03-16

35,361 downloads per month
Used in 170 crates (86 directly)

MPL-2.0 license

375KB
9K 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 a 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, 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 an removed

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

~1.5MB
~34K SLoC