docx_rs/reader/
wps_text_box.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 WpsTextBox {
12 fn read<R: Read>(
13 r: &mut EventReader<R>,
14 _attrs: &[OwnedAttribute],
15 ) -> Result<Self, ReaderError> {
16 let mut text_box = WpsTextBox::new();
17 loop {
18 let e = r.next();
19 match e {
20 Ok(XmlEvent::StartElement {
21 name, attributes, ..
22 }) => {
23 let e = XMLElement::from_str(&name.local_name)
24 .expect("should convert to XMLElement");
25 match e {
26 XMLElement::TxbxContent => {
27 let content = TextBoxContent::read(r, &attributes)?;
28 text_box = text_box.add_content(content);
29 }
30 _ => {}
31 }
32 }
33 Ok(XmlEvent::EndElement { name, .. }) => {
34 let e = WpsXMLElement::from_str(&name.local_name).unwrap();
35 if e == WpsXMLElement::Txbx {
36 return Ok(text_box);
37 }
38 }
39 Err(_) => return Err(ReaderError::XMLReadError),
40 _ => {}
41 }
42 }
43 }
44}