...
 
Commits (2)
......@@ -62,6 +62,12 @@ enum ProcessingError {
RenderingError
}
impl From<cairo::Status> for ProcessingError {
fn from(status: cairo::Status) -> ProcessingError {
ProcessingError::CairoError { status: status }
}
}
fn process_path<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> {
let meta = fs::metadata(&path)?;
......@@ -118,25 +124,24 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> {
Ok(())
}
fn render_to_pixbuf(handle: &rsvg::Handle) -> Result<(), Error> {
fn render_to_pixbuf(handle: &rsvg::Handle) -> Result<(), ProcessingError> {
handle.get_pixbuf()
.ok_or(Error::from(ProcessingError::RenderingError))
.ok_or(ProcessingError::RenderingError)
.map(|_| ())
}
fn render_to_cairo(handle: &rsvg::Handle) -> Result<(), Error> {
fn render_to_cairo(handle: &rsvg::Handle) -> Result<(), ProcessingError> {
let dim = handle.get_dimensions();
let surface = cairo::ImageSurface::create(cairo::Format::ARgb32,
dim.width,
dim.height)
.map_err(|e| ProcessingError::CairoError { status: e })?;
dim.height)?;
let cr = cairo::Context::new(&surface);
if handle.render_cairo(&cr) {
Ok(())
} else {
Err(Error::from(ProcessingError::RenderingError))
Err(ProcessingError::RenderingError)
}
}
......