Skip to main content

docx_rs/reader/
wps_text_box.rs

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