load_image_to_surface(): take an AllowedUrl, not a string

parent 5f72ad67
......@@ -3,6 +3,7 @@ use std::ptr;
use cairo::{self, ImageSurface, MatrixTrait, PatternTrait};
use allowed_url::AllowedUrl;
use aspect_ratio::AspectRatio;
use attributes::Attribute;
use defs::Href;
......@@ -126,8 +127,11 @@ impl Image {
unreachable!();
};
let aurl = AllowedUrl::from_href(url, handle::get_base_url(self.handle.get()).as_ref())
.map_err(|_| FilterError::InvalidInput)?;
// FIXME: translate the error better here
let surface = handle::load_image_to_surface(self.handle.get() as *mut _, url)
let surface = handle::load_image_to_surface(self.handle.get() as *mut _, &aurl)
.map_err(|_| FilterError::InvalidInput)?;
let output_surface = ImageSurface::create(
......
......@@ -7,7 +7,6 @@ use cairo_sys;
use gdk_pixbuf::{PixbufLoader, PixbufLoaderExt};
use gio::{Cancellable, File as GFile, InputStream};
use gio_sys;
use glib;
use glib::translate::*;
use glib_sys;
use libc;
......@@ -16,7 +15,7 @@ use url::Url;
use allowed_url::AllowedUrl;
use css::{self, CssStyles};
use defs::{Defs, RsvgDefs};
use error::{set_gerror, LoadingError, RsvgError};
use error::{set_gerror, LoadingError};
use io;
use surface_utils::shared_surface::SharedImageSurface;
......@@ -111,14 +110,9 @@ fn keep_image_data(handle: *const RsvgHandle) -> bool {
pub fn load_image_to_surface(
handle: *mut RsvgHandle,
href_str: &str,
aurl: &AllowedUrl,
) -> Result<ImageSurface, LoadingError> {
let rhandle = get_rust_handle(handle);
let aurl = AllowedUrl::from_href(href_str, rhandle.base_url.borrow().as_ref())
.map_err(|_| glib::Error::new(RsvgError, "FIXME"))?;
let data = acquire_data(handle, &aurl)?;
let data = acquire_data(handle, aurl)?;
if data.data.len() == 0 {
return Err(LoadingError::EmptyData);
......
......@@ -2,6 +2,7 @@ use cairo;
use cairo::{MatrixTrait, PatternTrait};
use std::cell::{Cell, RefCell};
use allowed_url::AllowedUrl;
use aspect_ratio::AspectRatio;
use attributes::Attribute;
use bbox::BoundingBox;
......@@ -68,12 +69,16 @@ impl NodeTrait for NodeImage {
self.aspect.set(parse("preserveAspectRatio", value, ())?)
}
// "path" is used by some older Adobe Illustrator versions
Attribute::XlinkHref | Attribute::Path => {
// "path" is used by some older Adobe Illustrator versions
// FIXME: use better errors here; these should be loading errors
let aurl = AllowedUrl::from_href(value, handle::get_base_url(handle).as_ref())
.map_err(|_| NodeError::value_error(attr, "invalid URL"))?;
*self.surface.borrow_mut() = Some(
// FIXME: translate the error better here
handle::load_image_to_surface(handle as *mut _, value)
handle::load_image_to_surface(handle as *mut _, &aurl)
.map_err(|_| NodeError::value_error(attr, "could not load image"))?,
);
}
......
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