The package provides an SVG parser, which is currently limited to paths.
The example given below can be ran using the following command:
cargo run --example path
```rust extern crate svg;
use svg::{Event, Tag}; use svg::path::{Command, Data};
fn main() { let file = svg::open("tests/fixtures/benton.svg").unwrap(); for event in file.parse() { match event { Event::Tag(Tag::Path(_, attributes)) => { let data = attributes.get("d").unwrap(); let data = Data::parse(data).unwrap(); draw(data); }, _ => { println!("Not sure how to react."); }, } } }
fn draw(data: Data) { for command in data.iter() { match *command { Command::MoveTo(, ref parameters) => { println!("Move to {:?}.", parameters); }, Command::LineTo(, ref parameters) => { println!("Line to {:?}.", parameters); }, Command::CurveTo(, ref parameters) => { println!("Curve to {:?}.", parameters); }, Command::SmoothCurveTo(, ref parameters) => { println!("Smooth curve to {:?}.", parameters); }, Command::ClosePath => { println!("Close the path."); }, _ => { println!("Not sure what to do."); } } } } ```