usvgr/
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`usvgr` (micro SVG) is an [SVG] parser that tries to solve most of SVG complexity.
7
8SVG is notoriously hard to parse. `usvgr` 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#![warn(missing_docs)]
51#![warn(missing_debug_implementations)]
52#![warn(missing_copy_implementations)]
53
54#[doc(hidden)]
55pub mod hashers;
56mod parser;
57mod tree;
58mod writer;
59
60pub use parser::*;
61pub use tree::*;
62
63pub use roxmltree;
64
65#[cfg(feature = "text")]
66mod text_to_paths;
67#[cfg(feature = "text")]
68pub use fontdb;
69
70pub use ahash;
71pub use lru;
72#[cfg(feature = "text")]
73pub use text_to_paths::UsvgrTextOutlineCache;
74pub use writer::WriteOptions;
75pub use xmlwriter::Indent;