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