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