use anyhow::bail;
use quick_xml::events::BytesStart;
use crate::{helper::string_to_int, raw::drawing::st_types::STPercentage};
pub type XlsxTileRectangle = XlsxFillRectangle;
pub type XlsxSourceRectangle = XlsxFillRectangle;
pub type XlsxFillToRectangle = XlsxFillRectangle;
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxFillRectangle {
pub b: Option<STPercentage>,
pub l: Option<STPercentage>,
pub r: Option<STPercentage>,
pub t: Option<STPercentage>,
}
impl XlsxFillRectangle {
pub(crate) fn load(e: &BytesStart) -> anyhow::Result<Self> {
let attributes = e.attributes();
let mut rect = Self {
b: None,
l: None,
r: None,
t: None,
};
for a in attributes {
match a {
Ok(a) => {
let string_value = String::from_utf8(a.value.to_vec())?;
match a.key.local_name().as_ref() {
b"b" => {
rect.b = string_to_int(&string_value);
}
b"l" => {
rect.l = string_to_int(&string_value);
}
b"r" => {
rect.r = string_to_int(&string_value);
}
b"t" => {
rect.t = string_to_int(&string_value);
}
_ => {}
}
}
Err(error) => {
bail!(error.to_string())
}
}
}
Ok(rect)
}
}