refactor to use exception helper factories

This commit is contained in:
Vukašin Stepanović
2023-02-15 10:46:13 +00:00
parent 3e27279dc8
commit 722ce78fd0
132 changed files with 966 additions and 1132 deletions

View File

@@ -56,11 +56,11 @@ impl SVGLuminanceSource {
pub fn new(svg_data: &[u8]) -> Result<Self, Exceptions> {
// Load the SVG file
let Ok(tree) = resvg::usvg::Tree::from_data(svg_data, &Options::default()) else {
return Err(Exceptions::FormatException(Some(format!("could not parse svg data: {}", "err"))));
return Err(Exceptions::format(format!("could not parse svg data: {}", "err")));
};
let Some(mut pixmap) = resvg::tiny_skia::Pixmap::new(tree.size.width() as u32, tree.size.height() as u32) else {
return Err(Exceptions::FormatException(Some("could not create pixmap".to_owned())));
return Err(Exceptions::format("could not create pixmap".to_owned()));
};
resvg::render(
@@ -71,11 +71,11 @@ impl SVGLuminanceSource {
);
let Some(buffer) = RgbaImage::from_raw(tree.size.width() as u32, tree.size.height() as u32, pixmap.data().to_vec()) else {
return Err(Exceptions::FormatException(Some("could not create image buffer".to_owned())));
return Err(Exceptions::format("could not create image buffer".to_owned()));
};
// let Ok(image) = image::load_from_memory_with_format(pixmap.data(), image::ImageFormat::Bmp) else {
// return Err(Exceptions::FormatException(Some("could not generate image".to_owned())));
// return Err(Exceptions::format("could not generate image".to_owned()));
// };
Ok(Self(BufferedImageLuminanceSource::new(DynamicImage::from(