Debian Codegraph @

README.md

raw symbols SCIP
1 # SVG [![Package][package-img]][package-url] [![Documentation][documentation-img]][documentation-url] [![Build][build-img]][build-url]
2
3 The package provides an SVG composer and parser.
4
5 ## Example: Composing
6
7 ```rust
8 use svg::Document;
9 use svg::node::element::Path;
10 use svg::node::element::path::Data;
11
12 let 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
19 let path = Path::new()
20 .set("fill", "none")
21 .set("stroke", "black")
22 .set("stroke-width", 3)
23 .set("d", data);
24
25 let document = Document::new()
26 .set("viewBox", (0, 0, 70, 70))
27 .add(path);
28
29 svg::save("image.svg", &document).unwrap();
30 ```
31
32 ## Example: Parsing
33
34 ```rust
35 use svg::node::element::path::{Command, Data};
36 use svg::node::element::tag::Path;
37 use svg::parser::Event;
38
39 let path = "image.svg";
40 let mut content = String::new();
41 for 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(..) => { /* … */ },
49 &Command::Line(..) => { /* … */ },
50 _ => {}
51 }
52 }
53 }
54 _ => {}
55 }
56 }
57 ```
58
59 ## Contribution
60
61 Your contribution is highly appreciated. Do not hesitate to open an issue or a
62 pull request. Note that any contribution submitted for inclusion in the project
63 will 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