Skip to main content

docx_rs/reader/
wps_shape.rs

1#![allow(clippy::single_match)]
2
3use std::io::Read;
4use std::str::FromStr;
5
6use super::*;
7
8impl ElementReader for WpsShape {
9    fn read<R: Read>(
10        r: &mut EventReader<R>,
11        _attrs: &[OwnedAttribute],
12    ) -> Result<Self, ReaderError> {
13        let mut shape = WpsShape::new();
14        loop {
15            let e = r.next();
16            match e {
17                Ok(XmlEvent::StartElement {
18                    name, attributes, ..
19                }) => {
20                    let e = WpsXMLElement::from_str(&name.local_name)
21                        .expect("should convert to XMLElement");
22                    match e {
23                        WpsXMLElement::Txbx => {
24                            let text_box = WpsTextBox::read(r, &attributes)?;
25                            shape = shape.add_text_box(text_box);
26                        }
27                        _ => {}
28                    }
29                }
30                Ok(XmlEvent::EndElement { name, .. }) => {
31                    let e = WpsXMLElement::from_str(&name.local_name).unwrap();
32                    if e == WpsXMLElement::Wsp {
33                        return Ok(shape);
34                    }
35                }
36                Err(_) => return Err(ReaderError::XMLReadError),
37                _ => {}
38            }
39        }
40    }
41}