docx_rs/documents/elements/
doc_grid.rs1use serde::{Deserialize, Serialize};
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::types::*;
6use crate::xml_builder::*;
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
9#[serde(rename_all = "camelCase")]
10pub struct DocGrid {
11 grid_type: DocGridType,
12 line_pitch: Option<usize>,
13 char_space: Option<isize>,
14}
15
16impl DocGrid {
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn with_empty() -> Self {
22 Self {
23 grid_type: DocGridType::Default,
24 line_pitch: None,
25 char_space: None,
26 }
27 }
28
29 pub fn grid_type(mut self, t: DocGridType) -> Self {
30 self.grid_type = t;
31 self
32 }
33
34 pub fn line_pitch(mut self, line_pitch: usize) -> Self {
35 self.line_pitch = Some(line_pitch);
36 self
37 }
38
39 pub fn char_space(mut self, char_space: isize) -> Self {
40 self.char_space = Some(char_space);
41 self
42 }
43}
44
45impl Default for DocGrid {
46 fn default() -> Self {
47 Self {
48 grid_type: DocGridType::Lines,
49 line_pitch: Some(360),
50 char_space: None,
51 }
52 }
53}
54
55impl BuildXML for DocGrid {
56 fn build_to<W: Write>(
57 &self,
58 stream: xml::writer::EventWriter<W>,
59 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
60 XMLBuilder::from(stream)
61 .doc_grid(&self.grid_type, self.line_pitch, self.char_space)?
62 .into_inner()
63 }
64}