32 releases

✓ Uses Rust 2018 edition

0.7.1 Mar 3, 2020
0.6.0 Sep 7, 2019
0.5.12 Dec 26, 2018
0.5.11 Jun 8, 2018
0.0.7 Feb 27, 2015

#1 in Data formats

Download history 912/week @ 2019-12-10 705/week @ 2019-12-17 430/week @ 2019-12-24 744/week @ 2019-12-31 1124/week @ 2020-01-07 1042/week @ 2020-01-14 751/week @ 2020-01-21 714/week @ 2020-01-28 822/week @ 2020-02-04 1242/week @ 2020-02-11 1666/week @ 2020-02-18 1272/week @ 2020-02-25 1143/week @ 2020-03-03 1078/week @ 2020-03-10 1176/week @ 2020-03-17 1582/week @ 2020-03-24

4,002 downloads per month
Used in 39 crates (27 directly)

Apache-2.0/MIT

60KB
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