librsvg_crate/examples/render.rs - Basic rendering example with the Rust API

Doesn't build yet; we need to link the C dependencies by hand :(
parent 648fcc8b
......@@ -13,3 +13,6 @@ glib = "0.6.0"
gio = { version="0.5.1", features=["v2_48"] } # per configure.ac
rsvg_internals = { path = "../rsvg_internals" }
url = "1.7.2"
[dev-dependencies]
cairo-rs = { version = "0.5.0", features = ["png"] }
extern crate cairo;
extern crate librsvg;
use std::fs::File;
use std::io::BufWriter;
use std::process;
fn main() {
let args = std::env::args_os();
if args.len() != 3 {
eprintln!("usage: render <input.svg> <output.png>");
process::exit(1);
}
let mut args = args.skip(1);
let input = args.next().unwrap();
let output = args.next().unwrap();
let handle = librsvg::LoadOptions::new().read_path(input).unwrap();
let renderer = handle.get_cairo_renderer();
let (w, h) = renderer.get_dimensions().unwrap();
let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, w, h).unwrap();
let cr = cairo::Context::new(&surface);
renderer.render(&cr).unwrap();
let mut file = BufWriter::new(File::create(output).unwrap());
surface.write_to_png(&mut file).unwrap();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment