docx_rs/reader/
table_position_property.rs

1use std::io::Read;
2use std::str::FromStr;
3
4use xml::attribute::OwnedAttribute;
5use xml::reader::EventReader;
6
7use super::*;
8
9impl ElementReader for TablePositionProperty {
10    fn read<R: Read>(
11        _r: &mut EventReader<R>,
12        attrs: &[OwnedAttribute],
13    ) -> Result<Self, ReaderError> {
14        let mut property = TablePositionProperty::new();
15        for a in attrs {
16            let local_name = &a.name.local_name;
17            match local_name.as_str() {
18                "leftFromText" => {
19                    if let Ok(v) = i32::from_str(&a.value) {
20                        property = property.left_from_text(v);
21                    }
22                }
23                "rightFromText" => {
24                    if let Ok(v) = i32::from_str(&a.value) {
25                        property = property.right_from_text(v);
26                    }
27                }
28                "vertAnchor" => {
29                    property = property.vertical_anchor(a.value.clone());
30                }
31                "horzAnchor" => {
32                    property = property.horizontal_anchor(a.value.clone());
33                }
34                "tblpXSpec" => {
35                    property = property.position_x_alignment(a.value.clone());
36                }
37                "tblpYSpec" => {
38                    property = property.position_y_alignment(a.value.clone());
39                }
40                "tblpX" => {
41                    if let Ok(v) = i32::from_str(&a.value) {
42                        property = property.position_x(v);
43                    }
44                }
45                "tblpY" => {
46                    if let Ok(v) = i32::from_str(&a.value) {
47                        property = property.position_y(v);
48                    }
49                }
50                _ => {}
51            }
52        }
53        Ok(property)
54    }
55}