svgtypes is a collection of parsers, containers and writers for SVG types.
Usage is simple as:
```rust use svgtypes::Path;
let path: Path = "M10-20A5.5.3-4 110-.1".parse().unwrap(); asserteq!(path.tostring(), "M 10 -20 A 5.5 0.3 -4 1 1 0 -0.1"); ```
You can also use a low-level, pull-based parser:
```rust use svgtypes::PathParser;
let p = PathParser::from("M10-20A5.5.3-4 110-.1"); for token in p { println!("{:?}", token); } ```
You can also tweak an output format:
```rust use svgtypes::{Path, WriteBuffer, WriteOptions};
let pathstr = "M10-20A5.5.3-4 110-.1"; let path: Path = pathstr.parse().unwrap();
let opt = WriteOptions { removeleadingzero: true, usecompactpathnotation: true, joinarctoflags: true, .. WriteOptions::default() };
asserteq!(path.withwriteopt(&opt).tostring(), path_str); ```
| SVG Type | Rust Type | Storage | Parser |
| ------------------------- | ------------- | ------- | ------------------- |
| [\ None. This crate is a successor for the Dependency: Rust >= 1.18 Add this to your Licensed under either of at your option. 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.
FromStr
, FromSpan
) and
to string traits (Display
, WriteBuffer
).style
and paint
types can only be parsed.Benefits
M10-20A5.5.3-4 110-.1
will be parsed correctly.Limitations
<color>
followed by the <icccolor>
is not supported. As the <icccolor>
itself.style
attribute.fill="AppWorkspace"
,
are not supported.coordinate
type. It will be parsed as <length>
,opacity-value
type. It will be parsed as <number>
,
but will be bound to 0..1 range.Safety
Alternatives
Migration from svgparser
svgparser
crate,
but it differs from it in many ways.
xmlparser
and reexports it - you can use it too.svgparser
this crate not only parse values but can also store and write them.
Currently, it has a minimal API for manipulating this values.AttributeValue
.
This crate provides only value parsers. You should match attributes and values by yourself.ValueId
.
It's up to you how to store those values.Usage
Cargo.toml
:toml
[dependencies]
svgtypes = "0.1"
License
Contribution