51 releases (17 breaking)

0.17.0 Apr 18, 2024
0.16.0 Feb 23, 2024
0.15.1 Feb 16, 2024
0.14.0 Sep 28, 2023
0.0.7 Feb 27, 2015

#24 in Images

Download history 7743/week @ 2024-01-03 9017/week @ 2024-01-10 11419/week @ 2024-01-17 9945/week @ 2024-01-24 10156/week @ 2024-01-31 10777/week @ 2024-02-07 13424/week @ 2024-02-14 13647/week @ 2024-02-21 12050/week @ 2024-02-28 13050/week @ 2024-03-06 12379/week @ 2024-03-13 12201/week @ 2024-03-20 11087/week @ 2024-03-27 13012/week @ 2024-04-03 17038/week @ 2024-04-10 15104/week @ 2024-04-17

58,773 downloads per month
Used in 206 crates (107 directly)

Apache-2.0 OR MIT

83KB
2K 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";
let mut content = String::new();
for event in svg::open(path, &mut content).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(..) => { /**/ },
                    &Command::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