29 releases

0.5.12 Dec 26, 2018
0.5.11 Jun 8, 2018
0.5.10 Jan 6, 2018
0.5.9 Dec 24, 2017
0.0.7 Feb 27, 2015

#2 in Data formats

Download history 122/week @ 2018-10-17 51/week @ 2018-10-24 348/week @ 2018-10-31 145/week @ 2018-11-07 151/week @ 2018-11-14 125/week @ 2018-11-21 196/week @ 2018-11-28 68/week @ 2018-12-05 166/week @ 2018-12-12 287/week @ 2018-12-19 147/week @ 2018-12-26 101/week @ 2019-01-02 125/week @ 2019-01-09 86/week @ 2019-01-16 107/week @ 2019-01-23

739 downloads per month
Used in 18 crates (15 directly)

Apache-2.0/MIT

56KB
1.5K SLoC

SVG Package Documentation Build

The package provides an SVG composer and parser.

Example: Composing

use svg::Document;
use svg::node::element::Path;
use svg::node::element::path::Data;

let data = Data::new()
    .move_to((10, 10))
    .line_by((0, 50))
    .line_by((50, 0))
    .line_by((0, -50))
    .close();

let path = Path::new()
    .set("fill", "none")
    .set("stroke", "black")
    .set("stroke-width", 3)
    .set("d", data);

let document = Document::new()
    .set("viewBox", (0, 0, 70, 70))
    .add(path);

svg::save("image.svg", &document).unwrap();

Example: Parsing

use svg::node::element::path::{Command, Data};
use svg::node::element::tag::Path;
use svg::parser::Event;

let path = "image.svg";
for event in svg::open(path).unwrap() {
    match event {
        Event::Tag(Path, _, attributes) => {
            let data = attributes.get("d").unwrap();
            let data = Data::parse(data).unwrap();
            for command in data.iter() {
                match command {
                    &Command::Move(..) => println!("Move!"),
                    &Command::Line(..) => println!("Line!"),
                    _ => {}
                }
            }
        }
        _ => {}
    }
}

Contribution

Your contribution is highly appreciated. Do not hesitate to open an issue or a pull request. Note that any contribution submitted for inclusion in the project will be licensed according to the terms given in LICENSE.md.

No runtime deps