use anyhow::bail;
use quick_xml::events::Event;
use std::io::Read;
use super::{
adjust_handle_list::{load_adjust_handle_list, XlsxAdjustHandleList},
adjust_value_list::{load_adjust_value_list, XlsxAdjustValueList},
connection_site_list::{load_connection_site_list, XlsxConnectionSiteList},
path::path_list::{load_path_list, XlsxPathList},
shape_guide_list::{load_shape_guide_list, XlsxShapeGuideList},
};
use crate::{excel::XmlReader, raw::drawing::text::shape_text_rectangle::XlsxShapeTextRectangle};
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxCustomGeometry {
pub adjust_handle_list: Option<XlsxAdjustHandleList>,
pub adjust_value_list: Option<XlsxAdjustValueList>,
pub connection_site_list: Option<XlsxConnectionSiteList>,
pub shape_guide_list: Option<XlsxShapeGuideList>,
pub path_list: Option<XlsxPathList>,
pub text_rectangle: Option<XlsxShapeTextRectangle>,
}
impl XlsxCustomGeometry {
pub(crate) fn load(reader: &mut XmlReader<impl Read>) -> anyhow::Result<Self> {
let mut geom = Self {
adjust_handle_list: None,
adjust_value_list: None,
connection_site_list: None,
shape_guide_list: None,
path_list: None,
text_rectangle: None,
};
let mut buf = Vec::new();
loop {
buf.clear();
match reader.read_event_into(&mut buf) {
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"ahLst" => {
geom.adjust_handle_list = Some(load_adjust_handle_list(reader)?);
}
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"avLst" => {
geom.adjust_value_list = Some(load_adjust_value_list(reader)?);
}
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"cxnLst" => {
geom.connection_site_list = Some(load_connection_site_list(reader)?);
}
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"gdLst" => {
geom.shape_guide_list = Some(load_shape_guide_list(reader)?);
}
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"pathLst" => {
geom.path_list = Some(load_path_list(reader)?);
}
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"rect" => {
geom.text_rectangle = Some(XlsxShapeTextRectangle::load(e)?);
}
Ok(Event::End(ref e)) if e.local_name().as_ref() == b"custGeom" => break,
Ok(Event::Eof) => bail!("unexpected end of file."),
Err(e) => bail!(e.to_string()),
_ => (),
}
}
Ok(geom)
}
}