#[cfg(feature = "serde")]
use serde::Serialize;
use std::collections::BTreeMap;
use crate::{
common_types::HexColor,
packaging::relationship::XlsxRelationships,
processed::drawing::image::blip::Blip,
raw::drawing::{fill::blip_fill::XlsxBlipFill, scheme::color_scheme::XlsxColorScheme},
};
use super::{fill_rectangle::FillRectangle, tile::Tile};
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug, PartialEq, Clone)]
pub struct BlipFill {
pub blip: Blip,
pub source_rect: FillRectangle,
pub fill_type: BlipFillType,
pub dpi: u64,
pub rotate_with_shape: bool,
}
impl BlipFill {
pub(crate) fn from_raw(
raw: Option<XlsxBlipFill>,
drawing_relationship: XlsxRelationships,
image_bytes: BTreeMap<String, Vec<u8>>,
color_scheme: Option<XlsxColorScheme>,
ref_color: Option<HexColor>,
) -> Option<Self> {
let Some(raw) = raw else { return None };
let Some(blip) = Blip::from_raw(
raw.clone().blip,
drawing_relationship,
image_bytes,
color_scheme.clone(),
ref_color.clone(),
) else {
return None;
};
return Some(Self {
blip,
source_rect: FillRectangle::from_raw(raw.clone().source_rect),
fill_type: BlipFillType::from_raw(raw.clone()),
dpi: raw.clone().dpi.unwrap_or(0),
rotate_with_shape: raw.clone().rot_with_shape.unwrap_or(false),
});
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum BlipFillType {
Stretch(FillRectangle),
Tile(Tile),
}
impl BlipFillType {
pub(crate) fn from_raw(raw: XlsxBlipFill) -> Self {
if let Some(stretch) = raw.stretch {
return Self::Stretch(FillRectangle::from_raw(stretch.fill_rectangle));
}
if let Some(raw_tile) = raw.tile {
return Self::Tile(Tile::from_raw(raw_tile));
};
return Self::Stretch(FillRectangle::default());
}
}