28 releases (breaking)
|0.23.0||Jun 11, 2022|
|0.22.0||Feb 21, 2022|
|0.21.0||Feb 13, 2022|
|0.20.0||Dec 30, 2021|
|0.2.0||May 23, 2018|
#7 in Images
16,830 downloads per month
Used in 120 crates (67 directly)
usvg (micro SVG) is an SVG simplification tool.
Imagine, that you have to extract some data from the SVG file, but your library/framework/language doesn't have a good SVG library. And all you need is paths data.
You can try to export it by yourself (how hard can it be, right). All you need is an XML library (I'll hope that your language has one). But soon you realize that paths data has a pretty complex format and a lot of edge-cases. And we didn't mention attributes propagation, transforms, visibility flags, attribute values validation, XML quirks, etc. It will take a lot of time and code to implement this stuff correctly.
So, instead of creating a library that can be used from any language (impossible), usvg takes a different approach. It converts an input SVG into an extremely simple representation, which is still a valid SVG. And now, all you need is an XML library with some small amount of code.
- No basic shapes (rect, circle, etc). Only paths
- Simple paths:
- Only MoveTo, LineTo, CurveTo and ClosePath will be produced
- All path segments are in absolute coordinates
- No implicit segment commands
- All values are separated by a space
- All (supported) attributes are resolved. No implicit one
usewill be resolved
- Invisible elements will be removed
- Invalid elements (like
rectwith negative/zero size) will be removed
- Units (mm, em, etc.) will be resolved
- Comments will be removed
- DTD will be resolved
- CSS will be resolved
styleattribute will be resolved
inheritattribute value will be resolved
currentColorattribute value will be resolved
- Paint fallback will be resolved
script(simply ignoring it)
Full spec can be found here.
- Currently, its not lossless. Some SVG features isn't supported yet and will be ignored.
- CSS support is minimal.
- Only static SVG features,
- Font-based elements are not supported.
The latest stable Rust.
You can't. The idea is that you should not store files produced by usvg. You should use them immediately. Like an intermediate data.
usvg is licensed under the MPLv2.0.