pub mod auto_numbered_bullet;
pub mod bullet;
pub mod character_bullet;
pub mod paragraph_properties;
pub mod picture_bullet;
pub mod spacing_type;
pub mod tab_alignment_values;
pub mod tab_stop;
#[cfg(feature = "serde")]
use serde::Serialize;
use std::collections::BTreeMap;
use super::{font::Font, run_type::RunTypeValues, text_run_properties::TextRunProperties};
use crate::{
common_types::HexColor,
packaging::relationship::XlsxRelationships,
raw::{
drawing::{
scheme::color_scheme::XlsxColorScheme,
text::paragraph::text_paragraphs::XlsxTextParagraphs,
},
spreadsheet::workbook::defined_name::XlsxDefinedNames,
},
};
use paragraph_properties::ParagraphProperties;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct Paragraph {
pub paragraph_properties: ParagraphProperties,
pub runs: Vec<RunTypeValues>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub end_paragraph_run_properties: Option<TextRunProperties>,
}
impl Paragraph {
pub(crate) fn from_raw(
raw: XlsxTextParagraphs,
default_paragraph_properties: Option<ParagraphProperties>,
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>,
) -> Self {
let paragraph_properties = if let Some(ppr) = raw.clone().paragraph_properties {
Some(*ppr)
} else {
None
};
let default_run_properties = if let Some(p_pr) = paragraph_properties.clone() {
Some(TextRunProperties::from_raw(
p_pr.default_run_properties,
None,
drawing_relationship.clone(),
defined_names.clone(),
image_bytes.clone(),
color_scheme.clone(),
ref_font.clone(),
font_ref_color.clone(),
))
} else {
None
};
let runs: Vec<RunTypeValues> = raw
.clone()
.runs
.unwrap_or(vec![])
.into_iter()
.map(|r| {
RunTypeValues::from_raw(
r,
default_run_properties.clone(),
drawing_relationship.clone(),
defined_names.clone(),
image_bytes.clone(),
color_scheme.clone(),
ref_font.clone(),
font_ref_color.clone(),
)
})
.collect();
return Self {
paragraph_properties: ParagraphProperties::from_raw(
paragraph_properties.clone(),
default_paragraph_properties.clone(),
drawing_relationship.clone(),
image_bytes.clone(),
color_scheme.clone(),
),
runs,
end_paragraph_run_properties: if let Some(e_pr) =
raw.clone().end_paragraph_run_properties
{
Some(TextRunProperties::from_raw(
Some(e_pr.clone()),
default_run_properties,
drawing_relationship.clone(),
defined_names.clone(),
image_bytes.clone(),
color_scheme.clone(),
ref_font.clone(),
font_ref_color.clone(),
))
} else {
None
},
};
}
}