docx_rs/documents/elements/
text_border.rs

1use serde::{Deserialize, Serialize};
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::types::*;
6use crate::xml_builder::*;
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct TextBorder {
11    pub border_type: BorderType,
12    pub size: usize,
13    pub color: String,
14    pub space: usize,
15}
16
17impl TextBorder {
18    pub fn new() -> Self {
19        TextBorder::default()
20    }
21
22    pub fn color(mut self, color: impl Into<String>) -> Self {
23        self.color = color.into();
24        self
25    }
26
27    pub fn size(mut self, size: usize) -> Self {
28        self.size = size;
29        self
30    }
31
32    pub fn space(mut self, space: usize) -> Self {
33        self.space = space;
34        self
35    }
36
37    pub fn border_type(mut self, border_type: BorderType) -> Self {
38        self.border_type = border_type;
39        self
40    }
41}
42
43impl Default for TextBorder {
44    fn default() -> Self {
45        TextBorder {
46            border_type: BorderType::Single,
47            size: 4,
48            space: 0,
49            color: "auto".to_owned(),
50        }
51    }
52}
53
54impl BuildXML for TextBorder {
55    fn build_to<W: Write>(
56        &self,
57        stream: xml::writer::EventWriter<W>,
58    ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
59        XMLBuilder::from(stream)
60            .text_border(self.border_type, self.size, self.space, &self.color)?
61            .into_inner()
62    }
63}