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 | |
8 | SVG is notoriously hard to parse. `usvg` presents a layer between an XML library and |
9 | a potential SVG rendering library. It will parse an input SVG into a strongly-typed tree structure |
10 | were all the elements, attributes, references and other SVG features are already resolved |
11 | and presented in the simplest way possible. |
12 | So a caller doesn't have to worry about most of the issues related to SVG parsing |
13 | and 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 | |
55 | mod parser; |
56 | mod tree; |
57 | mod writer; |
58 | |
59 | pub use parser::*; |
60 | pub use tree::*; |
61 | |
62 | pub use roxmltree; |
63 | |
64 | #[cfg (feature = "text" )] |
65 | mod text_to_paths; |
66 | #[cfg (feature = "text" )] |
67 | pub use fontdb; |
68 | |
69 | pub use writer::WriteOptions; |
70 | pub use xmlwriter::Indent; |
71 | |