docx_reader/reader/attributes/
border.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
37
38
39
use std::str::FromStr;

use xml::attribute::OwnedAttribute;

use crate::types::*;

use super::super::errors::*;

pub struct BorderAttrs {
	pub border_type: BorderType,
	pub color: String,
	pub size: Option<u32>,
	pub space: Option<u32>,
}

pub fn read_border(attrs: &[OwnedAttribute]) -> Result<BorderAttrs, ReaderError> {
	let mut border_type = BorderType::Single;
	let mut color = "000000".to_owned();
	let mut size: Option<u32> = Some(4);
	let mut space: Option<u32> = Some(0);
	for a in attrs {
		let local_name = &a.name.local_name;
		if local_name == "color" {
			color = a.value.to_owned();
		} else if local_name == "sz" {
			size = Some(f64::from_str(&a.value)? as u32);
		} else if local_name == "space" {
			space = Some(f64::from_str(&a.value)? as u32);
		} else if local_name == "val" {
			border_type = BorderType::from_str(&a.value)?;
		}
	}
	Ok(BorderAttrs {
		border_type,
		color,
		size,
		space,
	})
}