diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 102 |
1 files changed, 5 insertions, 97 deletions
@@ -1,4 +1,5 @@ mod configuration; +mod error; mod geometry; mod patterns; mod renderer; @@ -7,114 +8,21 @@ mod smart_positioning; mod stage_type; mod utils; -// Re-export parser types -pub use wmap_parser::{ - Component, Dependency, Evolution, Group, Inertia, Map, Note, Shape, Stage, StageData, -}; - -// Re-export our types pub use configuration::{ Colors, Configuration, Fonts, LineHeights, Opacity, Options, Sizes, Theme, }; +pub use renderer::{render_to_png, render_to_surface, render_to_svg}; pub use stage_type::StageType; -use thiserror::Error; -use cairo::ImageSurface; - -/// Error types for rendering -#[derive(Debug, Error)] -pub enum RenderError { - #[error("Cairo rendering error: {0}")] - Cairo(String), - - #[error("Invalid configuration: {0}")] - InvalidConfig(String), - - #[error("Concave hull calculation failed")] - GeometryError, - - #[error("IO error: {0}")] - Io(#[from] std::io::Error), -} - -impl From<cairo::Error> for RenderError { - fn from(err: cairo::Error) -> Self { - RenderError::Cairo(err.to_string()) - } -} - -impl From<cairo::IoError> for RenderError { - fn from(err: cairo::IoError) -> Self { - RenderError::Cairo(err.to_string()) - } -} - -/// Renders a Wardley map to PNG format -/// -/// # Arguments -/// -/// * `map` - The parsed Wardley map -/// * `stage_type` - The stage type to use for axis labels -/// * `config` - Configuration options -/// -/// # Returns -/// -/// A vector of bytes containing the PNG image data -pub fn render_to_png( - map: &Map, - stage_type: StageType, - config: &Configuration, -) -> Result<Vec<u8>, RenderError> { - renderer::render_to_png(map, stage_type, config) -} - -/// Renders a Wardley map to SVG format -/// -/// # Arguments -/// -/// * `map` - The parsed Wardley map -/// * `stage_type` - The stage type to use for axis labels -/// * `config` - Configuration options -/// -/// # Returns -/// -/// A string containing the SVG data -pub fn render_to_svg( - map: &Map, - stage_type: StageType, - config: &Configuration, -) -> Result<String, RenderError> { - renderer::render_to_svg(map, stage_type, config) -} - -/// Renders a Wardley map to a cairo context. -/// -/// # Arguments -/// -/// * `map` - The parsed Wardley map -/// * `stage_type` - The stage type to use for axis labels -/// * `config` - Configuration options -/// -/// # Returns -/// -/// A string containing the SVG data -pub fn render_to_surface( - map: &Map, - stage_type: StageType, - config: &Configuration, -) -> Result<ImageSurface, RenderError> { - renderer::render_to_surface(map, stage_type, config) -} - #[cfg(test)] mod tests { use super::*; #[test] fn test_default_configuration() { - let config = Configuration::default(); - assert!(config.options.show_background); - assert!(config.options.smart_label_positioning); + let configuration = Configuration::default(); + assert!(configuration.options.show_background); + assert!(configuration.options.smart_label_positioning); } #[test] |