docx_rs/reader/
a_graphic_data.rs1#![allow(clippy::single_match)]
2
3use std::io::Read;
4use std::str::FromStr;
5
6use xml::attribute::OwnedAttribute;
7use xml::reader::{EventReader, XmlEvent};
8
9use super::*;
10
11impl ElementReader for AGraphicData {
12 fn read<R: Read>(
13 r: &mut EventReader<R>,
14 attrs: &[OwnedAttribute],
15 ) -> Result<Self, ReaderError> {
16 let mut t = GraphicDataType::Unsupported;
17 for a in attrs {
18 if a.name.local_name == "uri" {
19 t = GraphicDataType::from_str(&a.value).unwrap();
20 }
21 }
22 let mut graphic_data = AGraphicData::new(t);
23 loop {
24 let e = r.next();
25 match e {
26 Ok(XmlEvent::StartElement {
27 name, attributes, ..
28 }) => {
29 let e = WpsXMLElement::from_str(&name.local_name)
30 .expect("should convert to XMLElement");
31 match e {
32 WpsXMLElement::Wsp => {
33 let shape = WpsShape::read(r, &attributes)?;
34 graphic_data = graphic_data.add_shape(shape);
35 }
36 _ => {}
37 }
38 }
39 Ok(XmlEvent::EndElement { name, .. }) => {
40 let e = AXMLElement::from_str(&name.local_name).unwrap();
41 if e == AXMLElement::GraphicData {
42 return Ok(graphic_data);
43 }
44 }
45 Err(_) => return Err(ReaderError::XMLReadError),
46 _ => {}
47 }
48 }
49 }
50}