#[cfg(feature = "serde")]
use serde::Serialize;
use crate::{
common_types::HexColor,
raw::drawing::{
scheme::color_scheme::XlsxColorScheme, shape::shape_3d_type::XlsxShape3DType,
st_types::emu_to_pt,
},
};
use super::{bevel::Bevel, preset_material::PresetMaterialTypeValues};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct Shape3DProperties {
pub contour_color: HexColor,
pub contour_width: f64,
pub extrusion_color: HexColor,
pub extrusion_height: f64,
pub shape_depth: f64,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub bottom_bevel: Option<Bevel>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub top_bevel: Option<Bevel>,
pub preset_material: PresetMaterialTypeValues,
}
impl Shape3DProperties {
pub(crate) fn from_raw(
raw: Option<XlsxShape3DType>,
color_scheme: Option<XlsxColorScheme>,
ref_color: Option<HexColor>,
) -> Option<Self> {
let Some(raw) = raw else { return None };
let mut contour_color = "020b0fff".to_string();
let mut extrusion_color = "00000000".to_string();
if let Some(c) = raw.clone().contour_clr {
if let Some(hex) = c.to_hex(color_scheme.clone(), ref_color.clone()) {
contour_color = hex
}
};
if let Some(c) = raw.clone().extrusion_clr {
if let Some(hex) = c.to_hex(color_scheme.clone(), ref_color.clone()) {
extrusion_color = hex
}
};
return Some(Self {
contour_color,
contour_width: emu_to_pt(raw.clone().contour_w.unwrap_or(0) as i64),
extrusion_color,
extrusion_height: emu_to_pt(raw.clone().extrusion_h.unwrap_or(0) as i64),
shape_depth: emu_to_pt(raw.clone().z.unwrap_or(0)),
bottom_bevel: Bevel::from_raw(raw.clone().bevel_b),
top_bevel: Bevel::from_raw(raw.clone().bevel_t),
preset_material: PresetMaterialTypeValues::from_string(raw.clone().prst_material),
});
}
}