2020-08-19 18:53:35 +03:00
|
|
|
use super::*;
|
|
|
|
|
2019-11-14 08:54:39 +02:00
|
|
|
use crate::documents::BuildXML;
|
|
|
|
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-11-14 08:54:39 +02:00
|
|
|
pub struct Settings {
|
|
|
|
default_tab_stop: DefaultTabStop,
|
|
|
|
zoom: Zoom,
|
2020-08-19 18:53:35 +03:00
|
|
|
doc_id: Option<DocId>,
|
2020-12-15 08:38:17 +02:00
|
|
|
doc_vars: Vec<DocVar>,
|
2021-11-27 12:12:06 +02:00
|
|
|
even_and_odd_headers: bool,
|
2019-11-14 08:54:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Settings {
|
|
|
|
pub fn new() -> Settings {
|
|
|
|
Default::default()
|
|
|
|
}
|
2020-08-19 18:53:35 +03:00
|
|
|
|
|
|
|
pub fn doc_id(mut self, id: impl Into<String>) -> Self {
|
|
|
|
self.doc_id = Some(DocId::new(id.into()));
|
|
|
|
self
|
|
|
|
}
|
2020-12-15 08:38:17 +02:00
|
|
|
|
2021-03-26 06:37:01 +02:00
|
|
|
pub fn default_tab_stop(mut self, tab_stop: usize) -> Self {
|
|
|
|
self.default_tab_stop = DefaultTabStop::new(tab_stop);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-12-15 08:38:17 +02:00
|
|
|
pub fn add_doc_var(mut self, name: impl Into<String>, val: impl Into<String>) -> Self {
|
|
|
|
self.doc_vars.push(DocVar::new(name, val));
|
|
|
|
self
|
|
|
|
}
|
2021-11-27 12:12:06 +02:00
|
|
|
|
|
|
|
pub fn even_and_odd_headers(mut self) -> Self {
|
|
|
|
self.even_and_odd_headers = true;
|
|
|
|
self
|
|
|
|
}
|
2019-11-14 08:54:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Settings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-03-26 06:37:01 +02:00
|
|
|
default_tab_stop: DefaultTabStop::new(840),
|
2019-11-14 08:54:39 +02:00
|
|
|
zoom: Zoom::new(100),
|
2020-08-19 18:53:35 +03:00
|
|
|
doc_id: None,
|
2020-12-15 08:38:17 +02:00
|
|
|
doc_vars: vec![],
|
2021-11-27 12:12:06 +02:00
|
|
|
even_and_odd_headers: false,
|
2019-11-14 08:54:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for Settings {
|
|
|
|
fn build(&self) -> Vec<u8> {
|
|
|
|
let b = XMLBuilder::new();
|
2020-12-15 08:38:17 +02:00
|
|
|
let mut b = b
|
|
|
|
.declaration(Some(true))
|
2019-11-14 08:54:39 +02:00
|
|
|
.open_settings()
|
|
|
|
.add_child(&self.default_tab_stop)
|
|
|
|
.add_child(&self.zoom)
|
2020-10-10 03:50:22 +03:00
|
|
|
.open_compat()
|
|
|
|
.space_for_ul()
|
|
|
|
.balance_single_byte_double_byte_width()
|
|
|
|
.do_not_leave_backslash_alone()
|
|
|
|
.ul_trail_space()
|
|
|
|
.do_not_expand_shift_return()
|
|
|
|
.adjust_line_height_table()
|
|
|
|
.use_fe_layout()
|
|
|
|
.compat_setting(
|
|
|
|
"compatibilityMode",
|
|
|
|
"http://schemas.microsoft.com/office/word",
|
|
|
|
"15",
|
|
|
|
)
|
|
|
|
.compat_setting(
|
|
|
|
"overrideTableStyleFontSizeAndJustification",
|
|
|
|
"http://schemas.microsoft.com/office/word",
|
|
|
|
"1",
|
|
|
|
)
|
|
|
|
.compat_setting(
|
|
|
|
"enableOpenTypeFeatures",
|
|
|
|
"http://schemas.microsoft.com/office/word",
|
|
|
|
"1",
|
|
|
|
)
|
|
|
|
.compat_setting(
|
|
|
|
"doNotFlipMirrorIndents",
|
|
|
|
"http://schemas.microsoft.com/office/word",
|
|
|
|
"1",
|
|
|
|
)
|
|
|
|
.compat_setting(
|
|
|
|
"differentiateMultirowTableHeaders",
|
|
|
|
"http://schemas.microsoft.com/office/word",
|
|
|
|
"1",
|
|
|
|
)
|
|
|
|
.compat_setting(
|
|
|
|
"useWord2013TrackBottomHyphenation",
|
|
|
|
"http://schemas.microsoft.com/office/word",
|
|
|
|
"0",
|
|
|
|
)
|
|
|
|
.close()
|
2020-12-15 08:38:17 +02:00
|
|
|
.add_optional_child(&self.doc_id);
|
|
|
|
|
|
|
|
if !self.doc_vars.is_empty() {
|
|
|
|
b = b.open_doc_vars();
|
|
|
|
for v in self.doc_vars.iter() {
|
|
|
|
b = b.add_child(v);
|
|
|
|
}
|
|
|
|
b = b.close();
|
|
|
|
}
|
2021-11-27 12:12:06 +02:00
|
|
|
|
|
|
|
if self.even_and_odd_headers {
|
|
|
|
b = b.even_and_odd_headers();
|
|
|
|
}
|
2020-12-15 08:38:17 +02:00
|
|
|
b.close().build()
|
2019-11-14 08:54:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
#[cfg(test)]
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_settings() {
|
|
|
|
let c = Settings::new();
|
|
|
|
let b = c.build();
|
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&b).unwrap(),
|
|
|
|
r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2021-03-26 06:37:01 +02:00
|
|
|
<w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"><w:defaultTabStop w:val="840" /><w:zoom w:percent="100" /><w:compat>
|
2020-10-12 16:58:00 +03:00
|
|
|
<w:spaceForUL />
|
|
|
|
<w:balanceSingleByteDoubleByteWidth />
|
|
|
|
<w:doNotLeaveBackslashAlone />
|
|
|
|
<w:ulTrailSpace />
|
|
|
|
<w:doNotExpandShiftReturn />
|
|
|
|
<w:adjustLineHeightInTable />
|
|
|
|
<w:useFELayout />
|
2020-10-10 03:50:22 +03:00
|
|
|
<w:compatSetting w:name="compatibilityMode" w:uri="http://schemas.microsoft.com/office/word" w:val="15" />
|
|
|
|
<w:compatSetting w:name="overrideTableStyleFontSizeAndJustification" w:uri="http://schemas.microsoft.com/office/word" w:val="1" />
|
|
|
|
<w:compatSetting w:name="enableOpenTypeFeatures" w:uri="http://schemas.microsoft.com/office/word" w:val="1" />
|
|
|
|
<w:compatSetting w:name="doNotFlipMirrorIndents" w:uri="http://schemas.microsoft.com/office/word" w:val="1" />
|
|
|
|
<w:compatSetting w:name="differentiateMultirowTableHeaders" w:uri="http://schemas.microsoft.com/office/word" w:val="1" />
|
|
|
|
<w:compatSetting w:name="useWord2013TrackBottomHyphenation" w:uri="http://schemas.microsoft.com/office/word" w:val="0" />
|
|
|
|
</w:compat>
|
|
|
|
</w:settings>"#
|
2019-11-14 08:54:39 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|