mod types;
mod xml;
pub use types::{GradientFill, GradientStop, PatternFill, PictureFill, SolidFill};
use crate::dml::color::ColorFormat;
use crate::enums::dml::MsoFillType;
use crate::units::RelationshipId;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum FillFormat {
NoFill,
Solid(SolidFill),
Gradient(GradientFill),
Pattern(PatternFill),
Picture(PictureFill),
Background,
}
impl FillFormat {
#[must_use]
pub const fn solid(color: ColorFormat) -> Self {
Self::Solid(SolidFill { color })
}
#[must_use]
pub const fn no_fill() -> Self {
Self::NoFill
}
pub fn picture(image_r_id: &str) -> Result<Self, crate::error::PptxError> {
Ok(Self::Picture(PictureFill {
image_r_id: RelationshipId::try_from(image_r_id)?,
stretch: true,
tile: false,
}))
}
pub fn picture_tiled(image_r_id: &str) -> Result<Self, crate::error::PptxError> {
Ok(Self::Picture(PictureFill {
image_r_id: RelationshipId::try_from(image_r_id)?,
stretch: false,
tile: true,
}))
}
#[must_use]
pub const fn background() -> Self {
Self::Background
}
#[must_use]
pub const fn fill_type(&self) -> MsoFillType {
match self {
Self::NoFill => MsoFillType::Background,
Self::Solid(_) => MsoFillType::Solid,
Self::Gradient(_) => MsoFillType::Gradient,
Self::Pattern(_) => MsoFillType::Patterned,
Self::Picture(_) => MsoFillType::Picture,
Self::Background => MsoFillType::Group,
}
}
#[must_use]
pub fn linear_gradient(start_color: ColorFormat, end_color: ColorFormat, angle: f64) -> Self {
Self::Gradient(GradientFill {
stops: vec![
GradientStop {
position: 0.0,
color: start_color,
},
GradientStop {
position: 1.0,
color: end_color,
},
],
angle: Some(angle),
})
}
}