use std::collections::BTreeMap;
#[cfg(feature = "serde")]
use serde::Serialize;
use super::text_underline_values::TextUnderlineValues;
use crate::{
common_types::HexColor,
packaging::relationship::XlsxRelationships,
processed::drawing::{fill::Fill, line::outline::Outline},
raw::drawing::{
scheme::color_scheme::XlsxColorScheme,
text::default_text_run_properties::XlsxTextRunProperties,
},
};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct Underline {
pub r#type: TextUnderlineValues,
pub fill: Fill,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub outline: Option<Outline>,
}
impl Underline {
pub(crate) fn default() -> Self {
Self {
fill: Fill::SolidFill("000000ff".to_string()),
outline: None,
r#type: TextUnderlineValues::default(),
}
}
pub(crate) fn from_text_run_properties(
raw: XlsxTextRunProperties,
default_underline: Option<Self>,
text_outline: Option<Outline>,
text_fill: Fill,
drawing_relationship: XlsxRelationships,
image_bytes: BTreeMap<String, Vec<u8>>,
color_scheme: Option<XlsxColorScheme>,
font_ref_color: Option<HexColor>,
) -> Self {
let fill = if let Some(f) = Fill::from_raw(
raw.clone().underline_fill,
None,
drawing_relationship.clone(),
image_bytes.clone(),
color_scheme.clone(),
font_ref_color.clone(),
) {
f
} else {
if let Some(default_underline) = default_underline.clone() {
default_underline.fill
} else {
text_fill
}
};
let outline = if let Some(outline) =
Outline::from_raw(raw.clone().underline_stroke, color_scheme.clone(), None)
{
Some(outline)
} else {
if let Some(default_underline) = default_underline.clone() {
default_underline.outline
} else {
text_outline
}
};
let underline = if let Some(u) = raw.clone().underline {
TextUnderlineValues::from_string(Some(u))
} else {
if let Some(default_underline) = default_underline.clone() {
default_underline.r#type
} else {
TextUnderlineValues::default()
}
};
return Self {
fill,
outline,
r#type: underline,
};
}
}