aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorRuben Beltran del Rio <jj@r.bdr.sh>2025-12-16 10:40:44 +0100
committerRuben Beltran del Rio <jj@r.bdr.sh>2025-12-16 10:55:34 +0100
commitf08648e4b5a9f7855a2ed9068a386e2f3c596322 (patch)
tree1f1567ea609a1f74aaeab3cbbfdb249c5c47d723 /src/lib.rs
Initial implementation
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..b56c670
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,105 @@
+mod configuration;
+mod geometry;
+mod patterns;
+mod renderer;
+mod shapes;
+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 stage_type::StageType;
+
+use thiserror::Error;
+
+/// 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)
+}
+
+#[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);
+ }
+
+ #[test]
+ fn test_default_stage_type() {
+ let stage = StageType::default();
+ assert_eq!(stage, StageType::Activities);
+ }
+}