docx_reader/reader/attributes/
width.rs

1use std::str::FromStr;
2
3use xml::attribute::OwnedAttribute;
4
5use crate::types::*;
6
7use super::super::errors::*;
8
9pub fn read_width(attrs: &[OwnedAttribute]) -> Result<(isize, WidthType), ReaderError> {
10	let mut w = 0;
11	let mut width_type = WidthType::Auto;
12	for a in attrs {
13		let local_name = &a.name.local_name;
14		if local_name == "type" {
15			width_type = WidthType::from_str(&a.value)?;
16		} else if local_name == "w" {
17			let v = a.value.replace("%", "");
18			w = f64::from_str(&v).expect("should read width.") as isize;
19		}
20	}
21	Ok((w, width_type))
22}