• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H03-May-2022-3327

src/H03-May-2022-2,5191,984

tests/fixtures/H03-May-2022-

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.gitignoreH A D29-Nov-197320 32

Cargo.tomlH A D01-Jan-19701.5 KiB2624

Cargo.toml.orig-cargoH A D29-Nov-19731 KiB2928

LICENSE.mdH A D29-Nov-19732 KiB5036

README.mdH A D29-Nov-19731.9 KiB7157

README.md

1# SVG [![Package][package-img]][package-url] [![Documentation][documentation-img]][documentation-url] [![Build][build-img]][build-url]
2
3The package provides an SVG composer and parser.
4
5## Example: Composing
6
7```rust
8use svg::Document;
9use svg::node::element::Path;
10use svg::node::element::path::Data;
11
12let data = Data::new()
13    .move_to((10, 10))
14    .line_by((0, 50))
15    .line_by((50, 0))
16    .line_by((0, -50))
17    .close();
18
19let path = Path::new()
20    .set("fill", "none")
21    .set("stroke", "black")
22    .set("stroke-width", 3)
23    .set("d", data);
24
25let document = Document::new()
26    .set("viewBox", (0, 0, 70, 70))
27    .add(path);
28
29svg::save("image.svg", &document).unwrap();
30```
31
32## Example: Parsing
33
34```rust
35use svg::node::element::path::{Command, Data};
36use svg::node::element::tag::Path;
37use svg::parser::Event;
38
39let path = "image.svg";
40let mut content = String::new();
41for event in svg::open(path, &mut content).unwrap() {
42    match event {
43        Event::Tag(Path, _, attributes) => {
44            let data = attributes.get("d").unwrap();
45            let data = Data::parse(data).unwrap();
46            for command in data.iter() {
47                match command {
48                    &Command::Move(..) => println!("Move!"),
49                    &Command::Line(..) => println!("Line!"),
50                    _ => {}
51                }
52            }
53        }
54        _ => {}
55    }
56}
57```
58
59## Contribution
60
61Your contribution is highly appreciated. Do not hesitate to open an issue or a
62pull request. Note that any contribution submitted for inclusion in the project
63will be licensed according to the terms given in [LICENSE.md](LICENSE.md).
64
65[build-img]: https://github.com/bodoni/svg/workflows/build/badge.svg
66[build-url]: https://github.com/bodoni/svg/actions/workflows/build.yml
67[documentation-img]: https://docs.rs/svg/badge.svg
68[documentation-url]: https://docs.rs/svg
69[package-img]: https://img.shields.io/crates/v/svg.svg
70[package-url]: https://crates.io/crates/svg
71