[go: up one dir, main page]

Documentation

SVG Build Status

Currently the library is limited to paths.

Documentation

Example

The example given below can be ran using the following command:

cargo run --example path
extern crate svg;

use std::path::Path;

use svg::{Event, Tag};
use svg::path::{Command, Data};

fn main() {
    let file = svg::open(&Path::new("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.");
            }
        }
    }
}

Contributing

  1. Fork the project.
  2. Implement your idea.
  3. Create a pull request.