From 4211b2ae06777d5bbe8261a1ab5c0dd057829a35 Mon Sep 17 00:00:00 2001 From: Rubén Beltrán del Río Date: Fri, 16 Jan 2026 00:36:23 +0100 Subject: Add export image --- src/handlers/export.rs | 26 ++++++++++++++++++++++++++ src/handlers/mod.rs | 1 + 2 files changed, 27 insertions(+) create mode 100644 src/handlers/export.rs (limited to 'src/handlers') diff --git a/src/handlers/export.rs b/src/handlers/export.rs new file mode 100644 index 0000000..7438ef9 --- /dev/null +++ b/src/handlers/export.rs @@ -0,0 +1,26 @@ +use std::path::PathBuf; + +use crate::AppModel; +use crate::actions::ImageFormat; +use crate::dialogs; +use wmap_renderer::{render_to_png, render_to_svg}; + +/// Exports the map to an image file in the specified format. +pub fn export_to_file(model: &AppModel, path: PathBuf, format: ImageFormat) { + let result: Result<(), String> = match format { + ImageFormat::Png => { + render_to_png(&model.map, model.stage_type, &model.render_configuration) + .map_err(|e| e.to_string()) + .and_then(|data| std::fs::write(&path, data).map_err(|e| e.to_string())) + } + ImageFormat::Svg => { + render_to_svg(&model.map, model.stage_type, &model.render_configuration) + .map_err(|e| e.to_string()) + .and_then(|data| std::fs::write(&path, data).map_err(|e| e.to_string())) + } + }; + + if let Err(error) = result { + dialogs::show_error(&model.window, "Error Exporting Image", &error); + } +} diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 7d7cfec..168feb8 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -1,3 +1,4 @@ +pub mod export; pub mod file; pub mod view; pub mod zoom; -- cgit