#[cfg(feature = "serde")]
use serde::Serialize;
use std::collections::BTreeMap;
use crate::{
common_types::HexColor,
packaging::relationship::XlsxRelationships,
processed::drawing::{
effect::effect_style::EffectStyle,
fill::Fill,
line::outline::Outline,
shape::{geometry::GeometryTypeValues, shape_properties::ShapeProperties},
text::{font::Font, shape_text_body::ShapeTextBody},
worksheet_drawing::non_visual_properties::NonVisualDrawingProperty,
},
raw::{
drawing::{
scheme::color_scheme::XlsxColorScheme,
worksheet_drawing::{
client_data::XlsxClientData, spreadsheet_extent::XlsxSpreadsheetExtent,
spreadsheet_position::XlsxSpreadsheetPosition, spreadsheet_shape::XlsxShape,
},
},
spreadsheet::workbook::defined_name::XlsxDefinedNames,
},
};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct Shape {
pub geometry: GeometryTypeValues,
pub text_box: bool,
pub lock_text: bool,
pub text_link: String,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub text: Option<ShapeTextBody>,
pub r#macro: String,
pub published: bool,
pub visual_properties: ShapeProperties,
pub non_visual_properties: NonVisualDrawingProperty,
}
impl Shape {
pub(crate) fn from_raw(
raw: XlsxShape,
extent: Option<XlsxSpreadsheetExtent>,
position: Option<XlsxSpreadsheetPosition>,
client_data: Option<XlsxClientData>,
parent_group_fill: Option<Fill>,
drawing_relationship: XlsxRelationships,
image_bytes: BTreeMap<String, Vec<u8>>,
defined_names: XlsxDefinedNames,
color_scheme: Option<XlsxColorScheme>,
line_ref: Option<Outline>,
fill_ref: Option<Fill>,
effect_ref: Option<EffectStyle>,
font_ref: (Option<HexColor>, Option<Font>), ) -> Self {
let text_box =
if let Some(non_visual_shape_properties) = raw.non_visual_shape_properties.clone() {
if let Some(p) = non_visual_shape_properties.non_visual_shape_drawing_properties {
p.text_box.unwrap_or(false)
} else {
false
}
} else {
false
};
return Self {
geometry: GeometryTypeValues::from_shape_properties(raw.clone().shape_properties),
text_box,
lock_text: raw.clone().lock_text.unwrap_or(true),
text_link: raw.clone().text_link.unwrap_or(String::new()),
text: ShapeTextBody::from_raw(
raw.clone().text_body,
drawing_relationship.clone(),
defined_names.clone(),
image_bytes.clone(),
color_scheme.clone(),
font_ref.1,
font_ref.0,
),
r#macro: raw.clone().r#macro.unwrap_or(String::new()),
published: raw.clone().published.unwrap_or(false),
non_visual_properties: NonVisualDrawingProperty::from_non_visual_shape_properties(
raw.non_visual_shape_properties,
client_data.clone(),
drawing_relationship.clone(),
defined_names,
),
visual_properties: ShapeProperties::from_shape_properties(
raw.shape_properties,
extent,
position,
parent_group_fill.clone(),
drawing_relationship.clone(),
image_bytes.clone(),
color_scheme.clone(),
line_ref.clone(),
fill_ref.clone(),
effect_ref.clone(),
),
};
}
}