Skip to main content

docx_rs/reader/
doc_grid.rs

1use std::io::Read;
2use std::str::FromStr;
3
4use crate::types::*;
5
6use super::*;
7
8impl ElementReader for DocGrid {
9    fn read<R: Read>(
10        _r: &mut EventReader<R>,
11        attrs: &[OwnedAttribute],
12    ) -> Result<Self, ReaderError> {
13        let mut doc_grid = DocGrid::with_empty();
14        for a in attrs {
15            let local_name = &a.name.local_name;
16            if local_name == "type" {
17                let t = DocGridType::from_str(&a.value)?;
18                doc_grid = doc_grid.grid_type(t);
19            } else if local_name == "linePitch" {
20                let line_pitch = f32::from_str(&a.value)?;
21                doc_grid = doc_grid.line_pitch(line_pitch as usize);
22            } else if local_name == "charSpace" {
23                let char_space = f32::from_str(&a.value)?;
24                doc_grid = doc_grid.char_space(char_space as isize);
25            }
26        }
27        Ok(doc_grid)
28    }
29}