use hwpforge_foundation::{
ArrowSize, ArrowType, Color, DropCapStyle, Flip, GradientType, ImageFillMode, PatternType,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::error::CoreError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct ShapePoint {
pub x: i32,
pub y: i32,
}
impl ShapePoint {
pub fn new(x: i32, y: i32) -> Self {
Self { x, y }
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub enum LineStyle {
#[default]
Solid,
Dash,
Dot,
DashDot,
DashDotDot,
None,
}
impl std::fmt::Display for LineStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Solid => f.write_str("SOLID"),
Self::Dash => f.write_str("DASH"),
Self::Dot => f.write_str("DOT"),
Self::DashDot => f.write_str("DASH_DOT"),
Self::DashDotDot => f.write_str("DASH_DOT_DOT"),
Self::None => f.write_str("NONE"),
}
}
}
impl std::str::FromStr for LineStyle {
type Err = CoreError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"SOLID" | "Solid" | "solid" => Ok(Self::Solid),
"DASH" | "Dash" | "dash" => Ok(Self::Dash),
"DOT" | "Dot" | "dot" => Ok(Self::Dot),
"DASH_DOT" | "DashDot" | "dash_dot" => Ok(Self::DashDot),
"DASH_DOT_DOT" | "DashDotDot" | "dash_dot_dot" => Ok(Self::DashDotDot),
"NONE" | "None" | "none" => Ok(Self::None),
_ => Err(CoreError::InvalidStructure {
context: "LineStyle".to_string(),
reason: format!(
"unknown line style '{s}', valid: SOLID, DASH, DOT, DASH_DOT, DASH_DOT_DOT, NONE"
),
}),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct ArrowStyle {
pub arrow_type: ArrowType,
pub size: ArrowSize,
pub filled: bool,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub enum Fill {
Solid {
color: Color,
},
Gradient {
gradient_type: GradientType,
angle: i32,
colors: Vec<(Color, u32)>,
},
Pattern {
pattern_type: PatternType,
fg_color: Color,
bg_color: Color,
},
Image {
image_id: String,
mode: ImageFillMode,
},
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ShapeStyle {
pub line_color: Option<Color>,
pub fill_color: Option<Color>,
pub line_width: Option<u32>,
pub line_style: Option<LineStyle>,
pub rotation: Option<f32>,
pub flip: Option<Flip>,
pub head_arrow: Option<ArrowStyle>,
pub tail_arrow: Option<ArrowStyle>,
pub fill: Option<Fill>,
#[serde(default)]
pub drop_cap_style: DropCapStyle,
}