Skip to content

Commit

Permalink
add fn free
Browse files Browse the repository at this point in the history
  • Loading branch information
tyutjohn authored Nov 25, 2024
1 parent 97944eb commit be67d3d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ impl RenderedImage {
pub fn height(&self) -> u32 {
self.pix.height()
}

#[cfg(not(target_arch = "wasm32"))]
#[napi]
pub fn free(&mut self) {
self.pix = Pixmap::new(1,1).expect("Failed to create empty Pixmap");
}
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -268,6 +274,21 @@ impl Resvg {
pub fn height(&self) -> f32 {
self.tree.size.height().round()
}

#[cfg(not(target_arch = "wasm32"))]
#[napi]
pub fn free(&mut self) {
self.tree = usvg::Tree {
size: usvg::Size::from_wh(1.0, 1.0).unwrap(),
view_box: usvg::ViewBox {
rect: usvg::NonZeroRect::from_ltrb(0.0, 0.0, 1.0, 1.0).unwrap(),
aspect: usvg::AspectRatio::default(),
},
root: usvg::Node::new(usvg::NodeKind::Group(usvg::Group::default()))
};

self.js_options = JsOptions::default();
}
}

#[cfg(target_arch = "wasm32")]
Expand Down

0 comments on commit be67d3d

Please sign in to comment.