use anyhow::bail;
use quick_xml::events::BytesStart;
use crate::{helper::string_to_int, raw::drawing::st_types::STCoordinate};
pub type XlsxChildOffset = XlsxOffset;
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxOffset {
pub x: Option<STCoordinate>,
pub y: Option<STCoordinate>,
}
impl XlsxOffset {
pub(crate) fn load(e: &BytesStart) -> anyhow::Result<Self> {
let attributes = e.attributes();
let mut offset = Self { x: None, y: 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"x" => offset.x = string_to_int(&string_value),
b"y" => offset.y = string_to_int(&string_value),
_ => {}
}
}
Err(error) => {
bail!(error.to_string())
}
}
}
Ok(offset)
}
}