docx_rs/reader/
theme.rs

1use std::io::Read;
2use std::str::FromStr;
3
4use crate::reader::*;
5use xml::reader::{EventReader, XmlEvent};
6
7impl FromXML for Theme {
8    fn from_xml<R: Read>(reader: R) -> Result<Self, ReaderError> {
9        let mut parser = EventReader::new(reader);
10        let mut theme = Self::default();
11        loop {
12            let e = parser.next();
13            match e {
14                Ok(XmlEvent::StartElement {
15                    attributes, name, ..
16                }) => {
17                    let e = AXMLElement::from_str(&name.local_name).unwrap();
18                    #[allow(clippy::single_match)]
19                    match e {
20                        AXMLElement::FontScheme => {
21                            if let Ok(f) = FontScheme::read(&mut parser, &attributes) {
22                                theme.font_schema = f;
23                            }
24                            continue;
25                        }
26                        _ => {}
27                    }
28                }
29                Ok(XmlEvent::EndDocument) => break,
30                Err(_) => return Err(ReaderError::XMLReadError),
31                _ => {}
32            }
33        }
34        Ok(theme)
35    }
36}