39 breaking releases

0.40.0 Feb 17, 2024
0.38.0 Jan 21, 2024
0.37.0 Dec 16, 2023
0.36.0 Oct 5, 2023
0.2.0 May 23, 2018

#593 in Images

Download history 18966/week @ 2023-11-27 16913/week @ 2023-12-04 17351/week @ 2023-12-11 18298/week @ 2023-12-18 12461/week @ 2023-12-25 17998/week @ 2024-01-01 21735/week @ 2024-01-08 26600/week @ 2024-01-15 28037/week @ 2024-01-22 28117/week @ 2024-01-29 29217/week @ 2024-02-05 29440/week @ 2024-02-12 31872/week @ 2024-02-19 27563/week @ 2024-02-26 25999/week @ 2024-03-04 14712/week @ 2024-03-11

103,028 downloads per month
Used in fewer than 92 crates

MPL-2.0 license

535KB
13K 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.1–3MB
~62K SLoC