docx_reader/reader/
a_graphic.rs

1use std::io::Read;
2use std::str::FromStr;
3use xml::attribute::OwnedAttribute;
4use xml::reader::{EventReader, XmlEvent};
5
6use super::*;
7
8impl ElementReader for AGraphic {
9	fn read<R: Read>(
10		r: &mut EventReader<R>,
11		_attrs: &[OwnedAttribute],
12	) -> Result<Self, ReaderError> {
13		let mut graphic = AGraphic::new();
14		loop {
15			let e = r.next();
16			match e {
17				Ok(XmlEvent::StartElement {
18					name, attributes, ..
19				}) => {
20					let e = AXMLElement::from_str(&name.local_name)
21						.expect("should convert to XMLElement");
22					if let AXMLElement::GraphicData = e {
23						let data = AGraphicData::read(r, &attributes)?;
24						graphic = graphic.add_graphic_data(data);
25					}
26				}
27				Ok(XmlEvent::EndElement { name, .. }) => {
28					let e = AXMLElement::from_str(&name.local_name).unwrap();
29					if e == AXMLElement::Graphic {
30						return Ok(graphic);
31					}
32				}
33				Err(_) => return Err(ReaderError::XMLReadError),
34				_ => {}
35			}
36		}
37	}
38}