docx_reader/reader/attributes/
border.rs

1use std::str::FromStr;
2
3use xml::attribute::OwnedAttribute;
4
5use crate::types::*;
6
7use super::super::errors::*;
8
9pub struct BorderAttrs {
10	pub border_type: BorderType,
11	pub color: String,
12	pub size: Option<u32>,
13	pub space: Option<u32>,
14}
15
16pub fn read_border(attrs: &[OwnedAttribute]) -> Result<BorderAttrs, ReaderError> {
17	let mut border_type = BorderType::Single;
18	let mut color = "000000".to_owned();
19	let mut size: Option<u32> = Some(4);
20	let mut space: Option<u32> = Some(0);
21	for a in attrs {
22		let local_name = &a.name.local_name;
23		if local_name == "color" {
24			color = a.value.to_owned();
25		} else if local_name == "sz" {
26			size = Some(f64::from_str(&a.value)? as u32);
27		} else if local_name == "space" {
28			space = Some(f64::from_str(&a.value)? as u32);
29		} else if local_name == "val" {
30			border_type = BorderType::from_str(&a.value)?;
31		}
32	}
33	Ok(BorderAttrs {
34		border_type,
35		color,
36		size,
37		space,
38	})
39}