Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bodoni/svg
Composer and parser for SVG
https://github.com/bodoni/svg
composing parsing vector-graphics
Last synced: 2 days ago
JSON representation
Composer and parser for SVG
- Host: GitHub
- URL: https://github.com/bodoni/svg
- Owner: bodoni
- License: other
- Created: 2015-02-08T12:19:39.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2024-09-27T09:59:15.000Z (3 months ago)
- Last Synced: 2024-12-16T02:12:55.871Z (9 days ago)
- Topics: composing, parsing, vector-graphics
- Language: Rust
- Homepage:
- Size: 328 KB
- Stars: 308
- Watchers: 6
- Forks: 44
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# SVG [![Package][package-img]][package-url] [![Documentation][documentation-img]][documentation-url] [![Build][build-img]][build-url]
The package provides an SVG composer and parser.
## Example: Composing
```rust
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
```rust
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](LICENSE.md).[build-img]: https://github.com/bodoni/svg/workflows/build/badge.svg
[build-url]: https://github.com/bodoni/svg/actions/workflows/build.yml
[documentation-img]: https://docs.rs/svg/badge.svg
[documentation-url]: https://docs.rs/svg
[package-img]: https://img.shields.io/crates/v/svg.svg
[package-url]: https://crates.io/crates/svg