svgtypes
svgtypes is a collection of parsers, containers and writers for SVG 1.1 types.
Usage is simple as:
use Path;
let path: Path = "M10-20A5.5.3-4 110-.1".parse.unwrap;
assert_eq!;
You can also use a low-level, pull-based parser:
use PathParser;
let p = from;
for token in p
You can also tweak an output format:
use ;
let path_str = "M10-20A5.5.3-4 110-.1";
let path: Path = path_str.parse.unwrap;
let opt = WriteOptions ;
assert_eq!;
Supported SVG types
SVG Type | Rust Type | Storage | Parser |
---|---|---|---|
<color> | Color | Stack | |
<number> | f64 | Stack | |
<length> | Length | Stack | |
<angle> | Angle | Stack | |
<viewBox> | ViewBox | Stack | |
<path> | Path | Heap | PathParser |
<list-of-numbers> | NumberList | Heap | NumberListParser |
<list-of-lengths> | LengthList | Heap | LengthListParser |
<transform-list> | Transform | Stack | TransformListParser |
<list-of-points> | Points | Heap | PointsParser |
<paint> | - | - | Paint |
- All types implement from string (
FromStr
) and to string traits (Display
,WriteBuffer
). - The library doesn't store transform list as is. It will premultiplied.
- The
paint
type can only be parsed.
Benefits
- Complete support of paths, so data like
M10-20A5.5.3-4 110-.1
will be parsed correctly. - Access to pull-based parsers.
- Pretty fast.
Limitations
- Accepts only normalized values,
e.g. an input text should not contain
 
or&data;
. - All keywords must be lowercase. Case-insensitive parsing is supported only for colors (requires allocation for named colors).
- The
<color>
followed by the<icccolor>
is not supported. As the<icccolor>
itself. - System colors, like
fill="AppWorkspace"
, are not supported. They were deprecated anyway. - Implicit path commands are not supported. All commands will be parsed as explicit.
- Implicit MoveTo commands will be automatically converted into explicit LineTo.
Safety
- The library should not panic. Any panic considered as a critical bug and should be reported.
- The library forbids unsafe code.
Alternatives
None.
Migration from svgparser
This crate is a successor for the svgparser
crate,
but it differs from it in many ways.
- There is no XML parser or writer. You can use any you like.
- Unlike the
svgparser
this crate not only parse values but can also store and write them. Currently, it has a minimal API for manipulating this values. - No
AttributeValue
. This crate provides only value parsers. You should match attributes and values by yourself. - No
ValueId
. It's up to you how to store those values.
Dependency
Rust >= 1.31
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.