2019-12-13 05:58:01 +02:00
|
|
|
use super::*;
|
|
|
|
use crate::documents::BuildXML;
|
2020-09-02 09:54:43 +03:00
|
|
|
use crate::types::*;
|
2019-12-13 05:58:01 +02:00
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
2020-02-11 10:01:39 +02:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2019-12-13 05:58:01 +02:00
|
|
|
pub struct SectionProperty {
|
|
|
|
page_size: PageSize,
|
|
|
|
page_margin: PageMargin,
|
|
|
|
columns: usize,
|
2021-03-19 18:38:22 +02:00
|
|
|
doc_grid: DocGrid,
|
2020-08-13 11:27:45 +03:00
|
|
|
header_reference: HeaderReference,
|
2020-09-02 09:54:43 +03:00
|
|
|
section_type: Option<SectionType>,
|
2019-12-13 05:58:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SectionProperty {
|
|
|
|
pub fn new() -> SectionProperty {
|
|
|
|
Default::default()
|
|
|
|
}
|
2020-10-09 14:30:55 +03:00
|
|
|
|
|
|
|
pub fn page_size(mut self, size: PageSize) -> Self {
|
|
|
|
self.page_size = size;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn page_margin(mut self, margin: PageMargin) -> Self {
|
|
|
|
self.page_margin = margin;
|
|
|
|
self
|
|
|
|
}
|
2021-03-19 18:38:22 +02:00
|
|
|
|
2021-03-24 09:51:11 +02:00
|
|
|
pub fn page_orient(mut self, o: PageOrientationType) -> Self {
|
|
|
|
self.page_size = self.page_size.orient(o);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-03-19 18:38:22 +02:00
|
|
|
pub fn doc_grid(mut self, doc_grid: DocGrid) -> Self {
|
|
|
|
self.doc_grid = doc_grid;
|
|
|
|
self
|
|
|
|
}
|
2019-12-13 05:58:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SectionProperty {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
page_size: PageSize::new(),
|
|
|
|
page_margin: PageMargin::new(),
|
|
|
|
columns: 425,
|
2021-03-19 18:38:22 +02:00
|
|
|
doc_grid: DocGrid::default(),
|
2020-08-13 11:27:45 +03:00
|
|
|
header_reference: HeaderReference::default(),
|
2020-09-02 09:54:43 +03:00
|
|
|
section_type: None,
|
2019-12-13 05:58:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for SectionProperty {
|
|
|
|
fn build(&self) -> Vec<u8> {
|
2020-09-02 09:54:43 +03:00
|
|
|
let mut b = XMLBuilder::new();
|
|
|
|
b = b
|
|
|
|
.open_section_property()
|
2019-12-13 05:58:01 +02:00
|
|
|
.add_child(&self.page_size)
|
|
|
|
.add_child(&self.page_margin)
|
2020-08-13 11:27:45 +03:00
|
|
|
.add_child(&self.header_reference)
|
2019-12-13 05:58:01 +02:00
|
|
|
.columns(&format!("{}", &self.columns))
|
2021-03-19 18:38:22 +02:00
|
|
|
.add_child(&self.doc_grid);
|
2020-09-02 09:54:43 +03:00
|
|
|
|
|
|
|
if let Some(t) = self.section_type {
|
|
|
|
b = b.type_tag(&t.to_string());
|
|
|
|
}
|
|
|
|
b.close().build()
|
2019-12-13 05:58:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
#[cfg(test)]
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_section_property_default() {
|
|
|
|
let c = SectionProperty::new();
|
|
|
|
let b = c.build();
|
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&b).unwrap(),
|
2021-03-19 18:38:22 +02:00
|
|
|
r#"<w:sectPr><w:pgSz w:w="11906" w:h="16838" /><w:pgMar w:top="1985" w:right="1701" w:bottom="1701" w:left="1701" w:header="851" w:footer="992" w:gutter="0" /><w:headerReference w:type="default" r:id="rId4" /><w:cols w:space="425" /><w:docGrid w:type="lines" w:linePitch="360" /></w:sectPr>"#
|
2019-12-13 05:58:01 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|