#[cfg(feature = "serde")]
use serde::Serialize;
use std::collections::BTreeMap;
use crate::{
common_types::{HexColor, Text},
packaging::relationship::XlsxRelationships,
raw::{
drawing::{scheme::color_scheme::XlsxColorScheme, text::text_field::XlsxTextField},
spreadsheet::workbook::defined_name::XlsxDefinedNames,
},
};
use super::{
font::Font, paragraph::paragraph_properties::ParagraphProperties,
text_run_properties::TextRunProperties,
};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct TextField {
pub text: Text,
pub run_properties: TextRunProperties,
pub r#type: String,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub paragraph_properties: Option<ParagraphProperties>,
}
impl TextField {
pub(crate) fn from_raw(
raw: XlsxTextField,
default_properties: Option<TextRunProperties>,
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 {
return Self {
run_properties: TextRunProperties::from_raw(
raw.clone().run_properties,
default_properties.clone(),
drawing_relationship.clone(),
defined_names.clone(),
image_bytes.clone(),
color_scheme.clone(),
ref_font.clone(),
font_ref_color.clone(),
),
text: raw.clone().text.unwrap_or(String::new()),
r#type: raw.clone().r#type.unwrap_or(String::new()),
paragraph_properties: if let Some(pr) = raw.clone().paragraph_properties {
Some(ParagraphProperties::from_raw(
Some(*pr),
None,
drawing_relationship.clone(),
image_bytes.clone(),
color_scheme.clone(),
))
} else {
None
},
};
}
}