usvg/
lib.rs

1// Copyright 2018 the Resvg Authors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4/*!
5`usvg` (micro SVG) is an [SVG] parser that tries to solve most of SVG complexity.
6
7SVG is notoriously hard to parse. `usvg` presents a layer between an XML library and
8a potential SVG rendering library. It will parse an input SVG into a strongly-typed tree structure
9were all the elements, attributes, references and other SVG features are already resolved
10and presented in the simplest way possible.
11So a caller doesn't have to worry about most of the issues related to SVG parsing
12and can focus just on the rendering part.
13
14## Features
15
16- All supported attributes are resolved.
17  No need to worry about inheritable, implicit and default attributes
18- CSS will be applied
19- Only simple paths
20  - Basic shapes (like `rect` and `circle`) will be converted into paths
21  - Paths contain only absolute *MoveTo*, *LineTo*, *QuadTo*, *CurveTo* and *ClosePath* segments.
22    ArcTo, implicit and relative segments will be converted
23- `use` will be resolved and replaced with the reference content
24- Nested `svg` will be resolved
25- Invalid, malformed elements will be removed
26- Relative length units (mm, em, etc.) will be converted into pixels/points
27- External images will be loaded
28- Internal, base64 images will be decoded
29- All references (like `#elem` and `url(#elem)`) will be resolved
30- `switch` will be resolved
31- Text elements, which are probably the hardest part of SVG, will be completely resolved.
32  This includes all the attributes resolving, whitespaces preprocessing (`xml:space`),
33  text chunks and spans resolving
34- Markers will be converted into regular elements. No need to place them manually
35- All filters are supported. Including filter functions, like `filter="contrast(50%)"`
36- Recursive elements will be detected and removed
37- `objectBoundingBox` will be replaced with `userSpaceOnUse`
38
39## Limitations
40
41- Unsupported SVG features will be ignored
42- CSS support is minimal
43- Only [static](http://www.w3.org/TR/SVG11/feature#SVG-static) SVG features,
44  e.g. no `a`, `view`, `cursor`, `script`, no events and no animations
45
46[SVG]: https://en.wikipedia.org/wiki/Scalable_Vector_Graphics
47*/
48
49#![forbid(unsafe_code)]
50#![warn(missing_docs)]
51#![warn(missing_debug_implementations)]
52#![warn(missing_copy_implementations)]
53
54mod parser;
55#[cfg(feature = "text")]
56mod text;
57mod tree;
58mod writer;
59
60pub use parser::*;
61#[cfg(feature = "text")]
62pub use text::*;
63pub use tree::*;
64
65pub use roxmltree;
66
67#[cfg(feature = "text")]
68pub use fontdb;
69
70pub use writer::WriteOptions;
71pub use xmlwriter::Indent;