docx_reader/reader/attributes/
indent.rs

1use std::str::FromStr;
2
3use xml::attribute::OwnedAttribute;
4
5use crate::types::*;
6
7use super::super::errors::*;
8
9pub type ReadIndentResult = Result<
10	(
11		Option<i32>,
12		Option<i32>,
13		Option<SpecialIndentType>,
14		Option<i32>,
15		Option<i32>,
16		Option<i32>,
17	),
18	ReaderError,
19>;
20
21pub fn read_indent(attrs: &[OwnedAttribute]) -> ReadIndentResult {
22	let mut start: Option<i32> = None;
23	let mut start_chars: Option<i32> = None;
24	let mut hanging_chars: Option<i32> = None;
25	let mut first_line_chars: Option<i32> = None;
26	let mut end: Option<i32> = None;
27	let mut special: Option<SpecialIndentType> = None;
28	for a in attrs {
29		let local_name = &a.name.local_name;
30		if local_name == "left" || local_name == "start" {
31			let v = super::value_to_dax(&a.value)?;
32			start = Some(v);
33		} else if local_name == "leftChars" || local_name == "startChars" {
34			start_chars = Some(f64::from_str(&a.value)? as i32);
35		} else if local_name == "end" || local_name == "right" {
36			let v = super::value_to_dax(&a.value)?;
37			end = Some(v);
38		} else if local_name == "hanging" {
39			let v = super::value_to_dax(&a.value)?;
40			special = Some(SpecialIndentType::Hanging(v))
41		} else if local_name == "firstLine" {
42			let v = super::value_to_dax(&a.value)?;
43			special = Some(SpecialIndentType::FirstLine(v))
44		} else if local_name == "firstLineChars" {
45			if let Ok(chars) = f64::from_str(&a.value) {
46				first_line_chars = Some(chars as i32);
47			}
48		} else if local_name == "hangingChars" {
49			if let Ok(chars) = f64::from_str(&a.value) {
50				hanging_chars = Some(chars as i32);
51			}
52		}
53	}
54	Ok((
55		start,
56		end,
57		special,
58		start_chars,
59		hanging_chars,
60		first_line_chars,
61	))
62}