Skip to content

Commit

Permalink
Simplify internal svg rendering API a little bit
Browse files Browse the repository at this point in the history
Since there is only one call site now, we can also return the correct
type without inconveniencing any other code.
  • Loading branch information
tronical committed Jul 20, 2022
1 parent 68543e3 commit 6a8e117
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/core/graphics/image.rs
Expand Up @@ -347,7 +347,7 @@ impl ImageInner {
#[cfg(feature = "svg")]
ImageInner::Svg(svg) => {
match svg.render(_target_size_for_scalable_source.unwrap_or_default()) {
Ok(b) => Some(SharedImageBuffer::RGBA8Premultiplied(b)),
Ok(b) => Some(b),
Err(err) => {
eprintln!("Error rendering SVG: {}", err);
return None;
Expand Down
8 changes: 3 additions & 5 deletions internal/core/graphics/image/svg.rs
Expand Up @@ -6,7 +6,7 @@
#[cfg(not(target_arch = "wasm32"))]
use crate::SharedString;

use super::{ImageCacheKey, SharedPixelBuffer};
use super::{ImageCacheKey, SharedImageBuffer, SharedPixelBuffer};

pub struct ParsedSVG {
svg_tree: usvg::Tree,
Expand All @@ -32,12 +32,10 @@ impl ParsedSVG {
}

/// Renders the SVG with the specified size.
///
/// NOTE: returned Rgba8Pixel buffer has alpha pre-multiplied
pub fn render(
&self,
size: euclid::default::Size2D<u32>,
) -> Result<SharedPixelBuffer<super::Rgba8Pixel>, usvg::Error> {
) -> Result<SharedImageBuffer, usvg::Error> {
let tree = &self.svg_tree;
// resvg doesn't support scaling to width/height, just fit to width.
// FIXME: the fit should actually depends on the image-fit property
Expand All @@ -50,7 +48,7 @@ impl ParsedSVG {
.ok_or(usvg::Error::InvalidSize)?;
resvg::render(tree, fit, Default::default(), skia_buffer)
.ok_or(usvg::Error::InvalidSize)?;
Ok(buffer)
Ok(SharedImageBuffer::RGBA8Premultiplied(buffer))
}
}

Expand Down

0 comments on commit 6a8e117

Please sign in to comment.