docx_reader/reader/
theme.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::io::Read;
use std::str::FromStr;
use xml::reader::{EventReader, XmlEvent};

use crate::reader::*;

impl FromXML for Theme {
	fn from_xml<R: Read>(reader: R) -> Result<Self, ReaderError> {
		let mut parser = EventReader::new(reader);
		let mut theme = Self::default();
		loop {
			let e = parser.next();
			match e {
				Ok(XmlEvent::StartElement {
					attributes, name, ..
				}) => {
					let e = AXMLElement::from_str(&name.local_name).unwrap();
					#[allow(clippy::single_match)]
					match e {
						AXMLElement::FontScheme => {
							if let Ok(f) = FontScheme::read(&mut parser, &attributes) {
								theme.font_schema = f;
							}
							continue;
						}
						_ => {}
					}
				}
				Ok(XmlEvent::EndDocument) => break,
				Err(_) => return Err(ReaderError::XMLReadError),
				_ => {}
			}
		}
		Ok(theme)
	}
}