40 breaking releases

0.41.0 Apr 3, 2024
0.40.0 Feb 17, 2024
0.39.0 Feb 6, 2024
0.37.0 Dec 16, 2023
0.2.0 May 23, 2018

#282 in Images

Download history 28334/week @ 2024-01-20 28257/week @ 2024-01-27 28136/week @ 2024-02-03 28891/week @ 2024-02-10 33209/week @ 2024-02-17 27427/week @ 2024-02-24 25433/week @ 2024-03-02 30057/week @ 2024-03-09 29537/week @ 2024-03-16 31630/week @ 2024-03-23 29225/week @ 2024-03-30 22917/week @ 2024-04-06 28568/week @ 2024-04-13 29146/week @ 2024-04-20 29897/week @ 2024-04-27 28424/week @ 2024-05-04

119,109 downloads per month
Used in 281 crates (92 directly)

MPL-2.0 license

555KB
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.2–3MB
~63K SLoC