52 releases (18 breaking)

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

#8 in Images

Download history 17251/week @ 2024-07-31 15839/week @ 2024-08-07 17731/week @ 2024-08-14 18401/week @ 2024-08-21 18694/week @ 2024-08-28 19952/week @ 2024-09-04 17147/week @ 2024-09-11 14442/week @ 2024-09-18 16306/week @ 2024-09-25 17301/week @ 2024-10-02 13447/week @ 2024-10-09 20138/week @ 2024-10-16 17606/week @ 2024-10-23 15915/week @ 2024-10-30 14744/week @ 2024-11-06 10204/week @ 2024-11-13

62,034 downloads per month
Used in 240 crates (124 directly)

Apache-2.0 OR MIT

85KB
2.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";
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