Skip to content

Commit be67d3d

Browse files
authored
add fn free
1 parent 97944eb commit be67d3d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ impl RenderedImage {
131131
pub fn height(&self) -> u32 {
132132
self.pix.height()
133133
}
134+
135+
#[cfg(not(target_arch = "wasm32"))]
136+
#[napi]
137+
pub fn free(&mut self) {
138+
self.pix = Pixmap::new(1,1).expect("Failed to create empty Pixmap");
139+
}
134140
}
135141

136142
#[cfg(not(target_arch = "wasm32"))]
@@ -268,6 +274,21 @@ impl Resvg {
268274
pub fn height(&self) -> f32 {
269275
self.tree.size.height().round()
270276
}
277+
278+
#[cfg(not(target_arch = "wasm32"))]
279+
#[napi]
280+
pub fn free(&mut self) {
281+
self.tree = usvg::Tree {
282+
size: usvg::Size::from_wh(1.0, 1.0).unwrap(),
283+
view_box: usvg::ViewBox {
284+
rect: usvg::NonZeroRect::from_ltrb(0.0, 0.0, 1.0, 1.0).unwrap(),
285+
aspect: usvg::AspectRatio::default(),
286+
},
287+
root: usvg::Node::new(usvg::NodeKind::Group(usvg::Group::default()))
288+
};
289+
290+
self.js_options = JsOptions::default();
291+
}
271292
}
272293

273294
#[cfg(target_arch = "wasm32")]

0 commit comments

Comments
 (0)