Crate svg [−] [src]
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"; for event in svg::open(path).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(..) => println!("Move!"), &Command::Line(..) => println!("Line!"), _ => {} } } } _ => {} } }
Re-exports
pub use node::Node; | 
pub use parser::Parser; | 
Modules
| node | 
                                 The nodes.  | 
                       
| parser | 
                                 The parser.  | 
                       
Functions
| open | 
                                 Open a document.  | 
                       
| read | 
                                 Read a document.  | 
                       
| save | 
                                 Save a document.  | 
                       
| write | 
                                 Write a document.  | 
                       
Type Definitions
| Document | 
                                 A document.  |