diff --git a/crates/kas-resvg/src/svg.rs b/crates/kas-resvg/src/svg.rs index 9c22327b9..e87449b36 100644 --- a/crates/kas-resvg/src/svg.rs +++ b/crates/kas-resvg/src/svg.rs @@ -153,22 +153,20 @@ impl_scope! { pub fn new(data: &'static [u8]) -> Result { let mut svg = Svg::default(); let source = Source::Static(data, None); - svg.load_source(source).map(|_action| svg) + svg.load_source(source).map(|_| svg) } /// Construct from a path pub fn new_path>(path: P) -> Result { let mut svg = Svg::default(); - let _action = svg.load_path_(path.as_ref())?; + svg._load_path(path.as_ref())?; Result::::Ok(svg) } /// Load from `data` /// - /// Replaces existing data, but does not re-render until a resize - /// happens (hence returning [`Action::RESIZE`]). - /// - /// This sets [`PixmapScaling::size`] from the SVG. + /// Replaces existing data and request a resize. The sizing policy is + /// set to [`PixmapScaling::size`] using dimensions from the SVG. pub fn load( &mut self, cx: &mut EventState, @@ -176,10 +174,10 @@ impl_scope! { resources_dir: Option<&Path>, ) -> Result<(), impl std::error::Error> { let source = Source::Static(data, resources_dir.map(|p| p.to_owned())); - self.load_source(source).map(|act| cx.action(self, act)) + self.load_source(source).map(|_| cx.resize(self)) } - fn load_source(&mut self, source: Source) -> Result { + fn load_source(&mut self, source: Source) -> Result<(), usvg::Error> { // Set scaling size. TODO: this is useless if Self::with_size is called after. let size = source.tree()?.size(); self.scaling.size = LogicalSize(size.width(), size.height()); @@ -188,7 +186,7 @@ impl_scope! { State::Ready(_, px) => State::Ready(source, px), _ => State::Initial(source), }; - Ok(Action::RESIZE) + Ok(()) } /// Load from a path @@ -199,10 +197,10 @@ impl_scope! { cx: &mut EventState, path: P, ) -> Result<(), impl std::error::Error> { - self.load_path_(path.as_ref()).map(|act| cx.action(self, act)) + self._load_path(path.as_ref()).map(|_| cx.resize(self)) } - fn load_path_(&mut self, path: &Path) -> Result { + fn _load_path(&mut self, path: &Path) -> Result<(), LoadError> { let buf = std::fs::read(path)?; let rd = path.parent().map(|path| path.to_owned()); let source = Source::Heap(buf.into(), rd);