Skip to main content

docx_rs/reader/
table_position_property.rs

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