use std::collections::BTreeMap;
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::{
common_types::HexColor,
packaging::relationship::XlsxRelationships,
raw::{
drawing::{
scheme::color_scheme::XlsxColorScheme, text::shape_text_body::XlsxShapeTextBody,
},
spreadsheet::workbook::defined_name::XlsxDefinedNames,
},
};
use super::{
body_properties::BodyProperties,
font::Font,
paragraph::{paragraph_properties::ParagraphProperties, Paragraph},
};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct ShapeTextBody {
pub body_properties: BodyProperties,
pub text_paragraph: Vec<Paragraph>,
}
impl ShapeTextBody {
pub(crate) fn from_raw(
raw: Option<XlsxShapeTextBody>,
drawing_relationship: XlsxRelationships,
defined_names: XlsxDefinedNames,
image_bytes: BTreeMap<String, Vec<u8>>,
color_scheme: Option<XlsxColorScheme>,
ref_font: Option<Font>,
font_ref_color: Option<HexColor>,
) -> Option<Self> {
let Some(raw) = raw else { return None };
let mut default_paragraph_properties: Option<ParagraphProperties> = None;
if let Some(lst) = raw.clone().text_list_style {
if let Some(def_pr) = lst.default_paragraph_style {
default_paragraph_properties = Some(ParagraphProperties::from_raw(
Some(*def_pr.clone()),
None,
drawing_relationship.clone(),
image_bytes.clone(),
color_scheme.clone(),
))
}
}
let paragraphs: Vec<Paragraph> = raw
.clone()
.text_paragraph
.unwrap_or(vec![])
.into_iter()
.map(|p| {
Paragraph::from_raw(
p,
default_paragraph_properties.clone(),
drawing_relationship.clone(),
defined_names.clone(),
image_bytes.clone(),
color_scheme.clone(),
ref_font.clone(),
font_ref_color.clone(),
)
})
.collect();
return Some(Self {
body_properties: BodyProperties::from_raw(
raw.clone().body_properties,
color_scheme.clone(),
),
text_paragraph: paragraphs,
});
}
}