Crates.io | svg |
lib.rs | svg |
version | 0.18.0 |
source | src |
created_at | 2015-02-08 12:22:46.291135 |
updated_at | 2024-09-27 10:28:57.788291 |
description | The package provides an SVG composer and parser. |
homepage | https://github.com/bodoni/svg |
repository | https://github.com/bodoni/svg |
max_upload_size | |
id | 1363 |
size | 88,862 |
The package provides an SVG composer and parser.
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();
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(..) => { /* … */ },
_ => {}
}
}
}
_ => {}
}
}
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.