2019-11-11 04:10:33 +02:00
|
|
|
use super::XMLBuilder;
|
|
|
|
use super::XmlEvent;
|
|
|
|
use crate::types::*;
|
|
|
|
|
2019-11-11 09:48:28 +02:00
|
|
|
const EXPECT_MESSAGE: &str = "should write buf";
|
|
|
|
|
2019-11-11 04:10:33 +02:00
|
|
|
impl XMLBuilder {
|
|
|
|
// i.e. <w:body... >
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_body, "w:body");
|
2019-11-11 04:10:33 +02:00
|
|
|
// i.e. <w:basedOn ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(based_on, "w:basedOn");
|
2019-11-11 04:10:33 +02:00
|
|
|
// i.e. <w:t ... >
|
|
|
|
pub(crate) fn text(mut self, text: &str, preserve_space: bool) -> Self {
|
|
|
|
let space = if preserve_space {
|
|
|
|
"preserve"
|
|
|
|
} else {
|
|
|
|
"default"
|
|
|
|
};
|
|
|
|
self.writer
|
|
|
|
.write(XmlEvent::start_element("w:t").attr("xml:space", space))
|
2019-11-11 09:48:28 +02:00
|
|
|
.expect(EXPECT_MESSAGE);
|
|
|
|
self.writer.write(text).expect(EXPECT_MESSAGE);
|
2019-11-11 04:10:33 +02:00
|
|
|
self.close()
|
|
|
|
}
|
2020-06-08 07:41:13 +03:00
|
|
|
|
2022-01-06 12:17:34 +02:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-06-08 07:41:13 +03:00
|
|
|
pub(crate) fn run_fonts(
|
|
|
|
mut self,
|
|
|
|
ascii: Option<&String>,
|
|
|
|
hi_ansi: Option<&String>,
|
|
|
|
cs: Option<&String>,
|
|
|
|
east_asia: Option<&String>,
|
2022-01-06 12:17:34 +02:00
|
|
|
ascii_theme: Option<&String>,
|
|
|
|
hi_ansi_theme: Option<&String>,
|
|
|
|
cs_theme: Option<&String>,
|
|
|
|
east_asia_theme: Option<&String>,
|
2022-01-27 08:16:40 +02:00
|
|
|
hint: Option<&String>,
|
2020-06-08 07:41:13 +03:00
|
|
|
) -> Self {
|
|
|
|
let mut w = XmlEvent::start_element("w:rFonts");
|
|
|
|
if let Some(ascii) = ascii {
|
|
|
|
w = w.attr("w:ascii", ascii);
|
|
|
|
}
|
|
|
|
if let Some(hi_ansi) = hi_ansi {
|
|
|
|
w = w.attr("w:hAnsi", hi_ansi);
|
|
|
|
}
|
|
|
|
if let Some(cs) = cs {
|
|
|
|
w = w.attr("w:cs", cs);
|
|
|
|
}
|
|
|
|
if let Some(east_asia) = east_asia {
|
|
|
|
w = w.attr("w:eastAsia", east_asia);
|
|
|
|
}
|
2022-01-06 12:17:34 +02:00
|
|
|
if let Some(ascii_theme) = ascii_theme {
|
|
|
|
w = w.attr("w:asciiTheme", ascii_theme);
|
|
|
|
}
|
|
|
|
if let Some(hi_ansi_theme) = hi_ansi_theme {
|
|
|
|
w = w.attr("w:hAnsiTheme", hi_ansi_theme);
|
|
|
|
}
|
|
|
|
if let Some(cs_theme) = cs_theme {
|
|
|
|
w = w.attr("w:cstheme", cs_theme);
|
|
|
|
}
|
|
|
|
if let Some(east_asia_theme) = east_asia_theme {
|
|
|
|
w = w.attr("w:eastAsiaTheme", east_asia_theme);
|
|
|
|
}
|
2022-01-27 08:16:40 +02:00
|
|
|
if let Some(hint) = hint {
|
|
|
|
w = w.attr("w:hint", hint);
|
|
|
|
}
|
2020-06-08 07:41:13 +03:00
|
|
|
self.writer.write(w).expect(EXPECT_MESSAGE);
|
|
|
|
self.close()
|
|
|
|
}
|
|
|
|
|
2019-11-15 11:15:43 +02:00
|
|
|
// i.e. <w:delText ... >
|
|
|
|
pub(crate) fn delete_text(mut self, text: &str, preserve_space: bool) -> Self {
|
|
|
|
let space = if preserve_space {
|
|
|
|
"preserve"
|
|
|
|
} else {
|
|
|
|
"default"
|
|
|
|
};
|
|
|
|
self.writer
|
|
|
|
.write(XmlEvent::start_element("w:delText").attr("xml:space", space))
|
|
|
|
.expect(EXPECT_MESSAGE);
|
|
|
|
self.writer.write(text).expect(EXPECT_MESSAGE);
|
|
|
|
self.close()
|
|
|
|
}
|
2021-12-09 12:37:54 +02:00
|
|
|
|
|
|
|
pub(crate) fn data_binding(
|
|
|
|
mut self,
|
|
|
|
xpath: Option<&String>,
|
|
|
|
prefix_mappings: Option<&String>,
|
|
|
|
store_item_id: Option<&String>,
|
|
|
|
) -> Self {
|
|
|
|
let mut e = XmlEvent::start_element("w:dataBinding");
|
|
|
|
if let Some(xpath) = xpath {
|
|
|
|
e = e.attr("w:xpath", xpath);
|
|
|
|
}
|
|
|
|
if let Some(prefix_mappings) = prefix_mappings {
|
|
|
|
e = e.attr("w:prefixMappings", prefix_mappings);
|
|
|
|
}
|
|
|
|
if let Some(store_item_id) = store_item_id {
|
|
|
|
e = e.attr("w:storeItemID", store_item_id);
|
|
|
|
}
|
|
|
|
self.writer.write(e).expect(EXPECT_MESSAGE);
|
|
|
|
self.close()
|
|
|
|
}
|
|
|
|
|
2021-12-17 18:03:02 +02:00
|
|
|
pub(crate) fn open_hyperlink(
|
|
|
|
mut self,
|
|
|
|
rid: Option<&String>,
|
|
|
|
anchor: Option<&String>,
|
2022-07-06 04:47:15 +03:00
|
|
|
history: Option<usize>,
|
2021-12-17 18:03:02 +02:00
|
|
|
) -> Self {
|
|
|
|
let mut e = XmlEvent::start_element("w:hyperlink");
|
2022-07-06 04:47:15 +03:00
|
|
|
let history = history.unwrap_or(1);
|
2021-12-17 18:03:02 +02:00
|
|
|
if let Some(rid) = rid {
|
2022-07-06 04:47:15 +03:00
|
|
|
e = e.attr("r:id", rid);
|
2021-12-17 18:03:02 +02:00
|
|
|
}
|
|
|
|
if let Some(anchor) = anchor {
|
|
|
|
e = e.attr("w:anchor", anchor);
|
|
|
|
}
|
2022-07-06 04:47:15 +03:00
|
|
|
let s = format!("{}", history);
|
|
|
|
e = e.attr("w:history", s.as_str());
|
2021-12-17 18:03:02 +02:00
|
|
|
self.writer.write(e).expect(EXPECT_MESSAGE);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-11-11 04:10:33 +02:00
|
|
|
// i.e. <w:r ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_run, "w:r");
|
|
|
|
open!(open_run_property, "w:rPr");
|
|
|
|
open!(open_run_property_default, "w:rPrDefault");
|
2019-11-11 04:10:33 +02:00
|
|
|
// i.e. <w:qFormat ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(q_format, "w:qFormat");
|
2019-11-11 04:10:33 +02:00
|
|
|
// i.e. <w:p ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
// open!(open_paragraph, "w:p");
|
2020-08-13 19:57:59 +03:00
|
|
|
open!(open_paragraph, "w:p", "w14:paraId");
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_paragraph_property, "w:pPr");
|
|
|
|
open!(open_doc_defaults, "w:docDefaults");
|
2021-12-02 17:56:29 +02:00
|
|
|
|
|
|
|
open!(open_structured_tag, "w:sdt");
|
|
|
|
open!(open_structured_tag_content, "w:sdtContent");
|
|
|
|
open!(open_structured_tag_property, "w:sdtPr");
|
2022-01-02 19:18:04 +02:00
|
|
|
closed_with_str!(alias, "w:alias");
|
2021-12-02 17:56:29 +02:00
|
|
|
|
2021-09-10 03:42:08 +03:00
|
|
|
// i.e. <w:outlineLvl ...>
|
|
|
|
closed_with_usize!(outline_lvl, "w:outlineLvl");
|
2019-11-11 04:10:33 +02:00
|
|
|
// i.e. <w:name ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(name, "w:name");
|
2019-11-11 06:05:07 +02:00
|
|
|
// i.e. <w:jc ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(justification, "w:jc");
|
2021-06-07 18:10:44 +03:00
|
|
|
// i.e. <w:vertAlign ... >
|
|
|
|
closed_with_str!(vert_align, "w:vertAlign");
|
2019-11-11 06:05:07 +02:00
|
|
|
// i.e. <w:pStyle ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(paragraph_style, "w:pStyle");
|
2022-03-16 05:24:12 +02:00
|
|
|
// i.e. <w:rStyle ... >
|
|
|
|
closed_with_str!(run_style, "w:rStyle");
|
2019-11-11 04:10:33 +02:00
|
|
|
// i.e. <w:sz ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_usize!(sz, "w:sz");
|
2019-11-11 08:36:26 +02:00
|
|
|
// i.e. <w:szCs ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_usize!(sz_cs, "w:szCs");
|
2019-11-13 09:08:25 +02:00
|
|
|
|
2021-12-05 17:28:31 +02:00
|
|
|
closed!(field_character, "w:fldChar", "w:fldCharType", "w:dirty");
|
|
|
|
|
|
|
|
open!(open_instr_text, "w:instrText");
|
2022-12-20 02:18:48 +02:00
|
|
|
open!(open_delete_instr_text, "w:delInstrText");
|
2021-12-05 17:28:31 +02:00
|
|
|
|
2022-10-14 08:24:13 +03:00
|
|
|
closed!(text_direction, "w:textDirection", "w:val");
|
2021-03-03 03:35:50 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(b, "w:b");
|
|
|
|
closed!(b_cs, "w:bCs");
|
2019-11-13 09:08:25 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(i, "w:i");
|
|
|
|
closed!(i_cs, "w:iCs");
|
2021-12-21 04:54:27 +02:00
|
|
|
|
|
|
|
closed!(strike, "w:strike");
|
|
|
|
|
2019-11-11 04:10:33 +02:00
|
|
|
// Build w:style element
|
|
|
|
// i.e. <w:style ... >
|
|
|
|
pub(crate) fn open_style(mut self, style_type: StyleType, id: &str) -> Self {
|
|
|
|
self.writer
|
|
|
|
.write(
|
|
|
|
XmlEvent::start_element("w:style")
|
|
|
|
.attr("w:type", &style_type.to_string())
|
|
|
|
.attr("w:styleId", id),
|
|
|
|
)
|
2019-11-11 09:48:28 +02:00
|
|
|
.expect(EXPECT_MESSAGE);
|
2019-11-11 04:10:33 +02:00
|
|
|
self
|
|
|
|
}
|
|
|
|
// i.e. <w:next ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(next, "w:next");
|
2019-11-11 04:10:33 +02:00
|
|
|
|
2022-12-20 05:01:08 +02:00
|
|
|
closed_with_str!(link, "w:link");
|
|
|
|
|
2019-11-11 04:10:33 +02:00
|
|
|
// i.e. <w:color ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(color, "w:color");
|
2019-11-13 09:08:25 +02:00
|
|
|
|
|
|
|
// i.e. <w:highlight ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(highlight, "w:highlight");
|
2019-11-11 09:48:28 +02:00
|
|
|
|
2019-12-04 09:28:11 +02:00
|
|
|
// i.e. <w:u ... >
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(underline, "w:u");
|
2019-12-04 09:28:11 +02:00
|
|
|
|
2020-06-03 10:35:12 +03:00
|
|
|
closed_with_str!(suffix, "w:suff");
|
|
|
|
|
2019-11-11 09:48:28 +02:00
|
|
|
// i.e. <w:ind ... >
|
2020-02-11 10:01:39 +02:00
|
|
|
pub(crate) fn indent(
|
|
|
|
mut self,
|
2020-03-10 04:56:12 +02:00
|
|
|
start: Option<i32>,
|
2020-02-11 10:01:39 +02:00
|
|
|
special_indent: Option<SpecialIndentType>,
|
2020-02-28 12:52:41 +02:00
|
|
|
end: i32,
|
2020-03-10 04:56:12 +02:00
|
|
|
start_chars: Option<i32>,
|
2020-02-11 10:01:39 +02:00
|
|
|
) -> Self {
|
2020-03-10 04:56:12 +02:00
|
|
|
let start = &format!("{}", start.unwrap_or(0));
|
2020-02-11 10:01:39 +02:00
|
|
|
let end = &format!("{}", end);
|
2020-03-10 04:56:12 +02:00
|
|
|
let start_chars_value = format!("{}", start_chars.unwrap_or(0));
|
|
|
|
let mut base = XmlEvent::start_element("w:ind")
|
2020-02-11 10:01:39 +02:00
|
|
|
.attr("w:left", start)
|
|
|
|
.attr("w:right", end);
|
|
|
|
|
2020-03-10 04:56:12 +02:00
|
|
|
if start_chars.is_some() {
|
|
|
|
base = base.attr("w:leftChars", &start_chars_value);
|
|
|
|
}
|
|
|
|
|
2019-11-11 09:48:28 +02:00
|
|
|
match special_indent {
|
|
|
|
Some(SpecialIndentType::FirstLine(v)) => self
|
|
|
|
.writer
|
|
|
|
.write(base.attr("w:firstLine", &format!("{}", v)))
|
|
|
|
.expect(EXPECT_MESSAGE),
|
|
|
|
Some(SpecialIndentType::Hanging(v)) => self
|
|
|
|
.writer
|
|
|
|
.write(base.attr("w:hanging", &format!("{}", v)))
|
|
|
|
.expect(EXPECT_MESSAGE),
|
|
|
|
_ => self.writer.write(base).expect(EXPECT_MESSAGE),
|
|
|
|
};
|
2019-11-11 04:10:33 +02:00
|
|
|
self.close()
|
|
|
|
}
|
2019-11-12 06:33:45 +02:00
|
|
|
|
2020-10-14 04:16:13 +03:00
|
|
|
// i.e. <w:spacing ... >
|
2021-09-29 03:03:39 +03:00
|
|
|
pub(crate) fn spacing(mut self, s: i32) -> Self {
|
|
|
|
self.writer
|
|
|
|
.write(XmlEvent::start_element("w:spacing").attr("w:val", &format!("{}", s)))
|
|
|
|
.expect(EXPECT_MESSAGE);
|
|
|
|
self.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
// i.e. <w:spacing ... >
|
|
|
|
pub(crate) fn line_spacing(
|
|
|
|
mut self,
|
|
|
|
before: Option<u32>,
|
|
|
|
after: Option<u32>,
|
|
|
|
line: Option<u32>,
|
2021-11-25 12:42:06 +02:00
|
|
|
before_lines: Option<u32>,
|
|
|
|
after_lines: Option<u32>,
|
2021-09-29 03:03:39 +03:00
|
|
|
spacing: Option<LineSpacingType>,
|
|
|
|
) -> Self {
|
|
|
|
let mut xml_event = XmlEvent::start_element("w:spacing");
|
|
|
|
let before_val: String;
|
|
|
|
let after_val: String;
|
2021-11-25 12:42:06 +02:00
|
|
|
let before_lines_val: String;
|
|
|
|
let after_lines_val: String;
|
2021-09-29 03:03:39 +03:00
|
|
|
let line_val: String;
|
|
|
|
|
|
|
|
if let Some(before) = before {
|
|
|
|
before_val = format!("{}", before);
|
|
|
|
xml_event = xml_event.attr("w:before", &before_val)
|
|
|
|
}
|
|
|
|
if let Some(after) = after {
|
|
|
|
after_val = format!("{}", after);
|
|
|
|
xml_event = xml_event.attr("w:after", &after_val)
|
|
|
|
}
|
2021-11-25 12:42:06 +02:00
|
|
|
if let Some(before_lines) = before_lines {
|
|
|
|
before_lines_val = format!("{}", before_lines);
|
|
|
|
xml_event = xml_event.attr("w:beforeLines", &before_lines_val)
|
|
|
|
}
|
|
|
|
if let Some(after_lines) = after_lines {
|
|
|
|
after_lines_val = format!("{}", after_lines);
|
|
|
|
xml_event = xml_event.attr("w:afterLines", &after_lines_val)
|
|
|
|
}
|
2021-09-29 03:03:39 +03:00
|
|
|
if let Some(line) = line {
|
|
|
|
line_val = format!("{}", line);
|
|
|
|
xml_event = xml_event.attr("w:line", &line_val)
|
|
|
|
}
|
|
|
|
if let Some(spacing_type) = spacing {
|
|
|
|
match spacing_type {
|
|
|
|
LineSpacingType::Auto => {
|
|
|
|
xml_event = xml_event.attr("w:lineRule", "auto");
|
|
|
|
}
|
|
|
|
LineSpacingType::AtLeast => {
|
|
|
|
xml_event = xml_event.attr("w:lineRule", "atLeast");
|
|
|
|
}
|
|
|
|
LineSpacingType::Exact => {
|
|
|
|
xml_event = xml_event.attr("w:lineRule", "exact");
|
|
|
|
}
|
2020-10-14 04:16:13 +03:00
|
|
|
}
|
|
|
|
}
|
2021-09-29 03:03:39 +03:00
|
|
|
self.writer.write(xml_event).expect(EXPECT_MESSAGE);
|
|
|
|
self.close()
|
2020-10-14 04:16:13 +03:00
|
|
|
}
|
|
|
|
|
2019-11-12 06:33:45 +02:00
|
|
|
//
|
|
|
|
// Table elements
|
|
|
|
//
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_table, "w:tbl");
|
|
|
|
open!(open_table_property, "w:tblPr");
|
|
|
|
open!(open_table_grid, "w:tblGrid");
|
|
|
|
open!(open_table_row, "w:tr");
|
|
|
|
open!(open_table_row_property, "w:trPr");
|
|
|
|
open!(open_table_cell, "w:tc");
|
|
|
|
open!(open_table_cell_property, "w:tcPr");
|
|
|
|
open!(open_table_cell_borders, "w:tcBorders");
|
|
|
|
open!(open_table_borders, "w:tblBorders");
|
|
|
|
open!(open_table_cell_margins, "w:tblCellMar");
|
2019-11-12 06:33:45 +02:00
|
|
|
|
2021-03-23 05:01:09 +02:00
|
|
|
closed!(table_layout, "w:tblLayout", "w:type");
|
2020-10-30 13:29:06 +02:00
|
|
|
closed_with_str!(table_style, "w:tblStyle");
|
2019-11-12 06:33:45 +02:00
|
|
|
closed_w_with_type_el!(table_width, "w:tblW");
|
|
|
|
closed_w_with_type_el!(table_indent, "w:tblInd");
|
|
|
|
closed_w_with_type_el!(grid_column, "w:gridCol");
|
|
|
|
closed_w_with_type_el!(table_cell_width, "w:tcW");
|
|
|
|
|
2020-10-13 10:27:03 +03:00
|
|
|
closed!(table_row_height, "w:trHeight", "w:val", "w:hRule");
|
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_usize!(grid_span, "w:gridSpan");
|
|
|
|
closed_with_str!(vertical_merge, "w:vMerge");
|
2020-03-19 18:19:39 +02:00
|
|
|
closed_with_str!(vertical_align, "w:vAlign");
|
2019-11-13 08:00:53 +02:00
|
|
|
|
2019-11-12 10:32:50 +02:00
|
|
|
closed_w_with_type_el!(margin_top, "w:top");
|
|
|
|
closed_w_with_type_el!(margin_left, "w:left");
|
|
|
|
closed_w_with_type_el!(margin_bottom, "w:bottom");
|
|
|
|
closed_w_with_type_el!(margin_right, "w:right");
|
|
|
|
|
|
|
|
closed_border_el!(border_top, "w:top");
|
|
|
|
closed_border_el!(border_left, "w:left");
|
|
|
|
closed_border_el!(border_bottom, "w:bottom");
|
|
|
|
closed_border_el!(border_right, "w:right");
|
|
|
|
closed_border_el!(border_inside_h, "w:insideH");
|
|
|
|
closed_border_el!(border_inside_v, "w:insideV");
|
2021-03-16 09:09:39 +02:00
|
|
|
closed_border_el!(border_tl2br, "w:tl2br");
|
|
|
|
closed_border_el!(border_tr2bl, "w:tr2bl");
|
2019-11-12 10:32:50 +02:00
|
|
|
|
2021-03-20 17:16:43 +02:00
|
|
|
closed_border_el!(text_border, "w:bdr");
|
|
|
|
|
2021-03-18 12:02:28 +02:00
|
|
|
closed!(shd, "w:shd", "w:val", "w:color", "w:fill");
|
2019-11-13 09:51:58 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(tab_with_pos, "w:tab", "w:val", "w:pos");
|
2019-12-06 12:18:48 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(br, "w:br", "w:type");
|
|
|
|
closed!(zoom, "w:zoom", "w:percent");
|
|
|
|
closed_with_usize!(default_tab_stop, "w:defaultTabStop");
|
2019-11-14 12:21:45 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_font, "w:font", "w:name");
|
|
|
|
closed_with_str!(pitch, "w:pitch");
|
|
|
|
closed_with_str!(family, "w:family");
|
|
|
|
closed_with_str!(charset, "w:charset");
|
2019-11-14 18:50:30 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_section_property, "w:sectPr");
|
2020-08-13 11:27:45 +03:00
|
|
|
closed!(header_reference, "w:headerReference", "w:type", "r:id");
|
2021-11-24 18:49:27 +02:00
|
|
|
closed!(footer_reference, "w:footerReference", "w:type", "r:id");
|
2020-08-13 11:27:45 +03:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(type_tag, "w:type");
|
2021-11-27 12:12:06 +02:00
|
|
|
closed!(title_pg, "w:titlePg");
|
|
|
|
closed!(even_and_odd_headers, "w:evenAndOddHeaders");
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(page_size, "w:pgSz", "w:w", "w:h");
|
2021-03-24 09:51:11 +02:00
|
|
|
closed!(page_size_with_orient, "w:pgSz", "w:w", "w:h", "w:orient");
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(
|
2019-11-14 18:50:30 +02:00
|
|
|
page_margin,
|
|
|
|
"w:pgMar",
|
2019-12-13 05:58:01 +02:00
|
|
|
"w:top",
|
2019-11-14 18:50:30 +02:00
|
|
|
"w:right",
|
2019-12-13 05:58:01 +02:00
|
|
|
"w:bottom",
|
|
|
|
"w:left",
|
2019-11-14 18:50:30 +02:00
|
|
|
"w:header",
|
|
|
|
"w:footer",
|
|
|
|
"w:gutter"
|
|
|
|
);
|
2022-08-25 09:30:19 +03:00
|
|
|
closed!(columns, "w:cols", "w:space", "w:num");
|
2022-10-14 08:24:13 +03:00
|
|
|
// closed!(text_direction, "w:val");
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(document_grid, "w:docGrid", "w:type", "w:linePitch");
|
2019-11-15 11:15:43 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_insert, "w:ins", "w:id", "w:author", "w:date");
|
|
|
|
open!(open_delete, "w:del", "w:id", "w:author", "w:date");
|
2022-01-27 08:16:40 +02:00
|
|
|
open!(
|
|
|
|
open_paragraph_property_change,
|
|
|
|
"w:pPrChange",
|
|
|
|
"w:id",
|
|
|
|
"w:author",
|
|
|
|
"w:date"
|
|
|
|
);
|
2019-12-04 09:55:03 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(bookmark_start, "w:bookmarkStart", "w:id", "w:name");
|
|
|
|
closed!(bookmark_end, "w:bookmarkEnd", "w:id");
|
2019-12-04 10:25:31 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(comment_range_start, "w:commentRangeStart", "w:id");
|
|
|
|
closed!(comment_range_end, "w:commentRangeEnd", "w:id");
|
|
|
|
closed!(comment_reference, "w:commentReference", "w:id");
|
|
|
|
open!(
|
2019-12-05 08:44:18 +02:00
|
|
|
open_comment,
|
|
|
|
"w:comment",
|
|
|
|
"w:id",
|
|
|
|
"w:author",
|
|
|
|
"w:date",
|
|
|
|
"w:initials"
|
|
|
|
);
|
2019-12-06 12:18:48 +02:00
|
|
|
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_abstract_num, "w:abstractNum", "w:abstractNumId");
|
|
|
|
open!(open_level, "w:lvl", "w:ilvl");
|
|
|
|
open!(open_tabs, "w:tabs");
|
|
|
|
open!(open_num, "w:num", "w:numId");
|
|
|
|
open!(open_numbering_property, "w:numPr");
|
|
|
|
closed_with_usize!(indent_level, "w:ilvl");
|
|
|
|
closed_with_usize!(num_id, "w:numId");
|
|
|
|
closed_with_usize!(start, "w:start");
|
|
|
|
closed_with_str!(number_format, "w:numFmt");
|
|
|
|
closed_with_str!(level_text, "w:lvlText");
|
2021-04-27 12:18:44 +03:00
|
|
|
closed_with_str!(level_restart, "w:lvlRestart");
|
2020-01-24 10:57:14 +02:00
|
|
|
closed_with_str!(level_justification, "w:lvlJc");
|
|
|
|
closed_with_str!(abstract_num_id, "w:abstractNumId");
|
|
|
|
closed!(vanish, "w:vanish");
|
2022-11-01 08:10:06 +02:00
|
|
|
closed!(spec_vanish, "w:specVanish");
|
2022-11-02 15:34:27 +02:00
|
|
|
closed!(is_lgl, "w:isLgl");
|
2020-04-07 04:24:56 +03:00
|
|
|
|
|
|
|
open!(open_drawing, "w:drawing");
|
|
|
|
open!(open_anchor, "wp:anchor");
|
|
|
|
open!(open_graphic, "a:graphic", "xmlns:a");
|
|
|
|
open!(open_graphic_data, "a:graphicData", "uri");
|
|
|
|
|
|
|
|
// shape
|
|
|
|
open!(open_wp_shape, "wps:wsp");
|
|
|
|
open!(open_wp_text_box, "wps:txbx");
|
|
|
|
open!(open_text_box_content, "w:txbxContent");
|
2020-06-04 11:53:37 +03:00
|
|
|
|
2020-10-10 03:50:22 +03:00
|
|
|
// compat
|
|
|
|
open!(open_compat, "w:compat");
|
2020-10-12 16:58:00 +03:00
|
|
|
closed!(space_for_ul, "w:spaceForUL");
|
2020-10-10 03:50:22 +03:00
|
|
|
closed!(
|
|
|
|
balance_single_byte_double_byte_width,
|
2020-10-12 16:58:00 +03:00
|
|
|
"w:balanceSingleByteDoubleByteWidth"
|
2020-10-10 03:50:22 +03:00
|
|
|
);
|
2020-10-12 16:58:00 +03:00
|
|
|
closed!(do_not_leave_backslash_alone, "w:doNotLeaveBackslashAlone");
|
|
|
|
closed!(ul_trail_space, "w:ulTrailSpace");
|
|
|
|
closed!(do_not_expand_shift_return, "w:doNotExpandShiftReturn");
|
|
|
|
closed!(adjust_line_height_table, "w:adjustLineHeightInTable");
|
|
|
|
closed!(use_fe_layout, "w:useFELayout");
|
2020-10-10 03:50:22 +03:00
|
|
|
closed!(
|
|
|
|
compat_setting,
|
|
|
|
"w:compatSetting",
|
|
|
|
"w:name",
|
|
|
|
"w:uri",
|
|
|
|
"w:val"
|
|
|
|
);
|
|
|
|
|
2021-04-14 06:01:38 +03:00
|
|
|
closed!(keep_next, "w:keepNext");
|
|
|
|
closed!(keep_lines, "w:keepLines");
|
|
|
|
closed!(page_break_before, "w:pageBreakBefore");
|
2022-01-14 08:03:53 +02:00
|
|
|
closed!(widow_control, "w:widowControl");
|
2021-04-14 06:01:38 +03:00
|
|
|
|
2020-06-04 11:53:37 +03:00
|
|
|
/*
|
|
|
|
<w:lvlOverride w:ilvl="0">
|
|
|
|
<w:startOverride w:val="1"/>
|
|
|
|
</w:lvlOverride>
|
|
|
|
*/
|
|
|
|
open!(open_level_override, "w:lvlOverride", "w:ilvl");
|
|
|
|
closed_with_str!(start_override, "w:startOverride");
|
2020-08-13 19:57:59 +03:00
|
|
|
|
2020-08-19 18:53:35 +03:00
|
|
|
closed!(doc_id, "w15:docId", "w15:val");
|
|
|
|
|
2020-12-15 08:38:17 +02:00
|
|
|
open!(open_doc_vars, "w:docVars");
|
|
|
|
closed!(doc_var, "w:docVar", "w:name", "w:val");
|
|
|
|
|
2021-06-30 16:37:13 +03:00
|
|
|
// webextension
|
|
|
|
open!(open_webextension, "we:webextension", "xmlns:we", "id");
|
|
|
|
closed!(
|
|
|
|
webextension_reference,
|
|
|
|
"we:reference",
|
|
|
|
"id",
|
|
|
|
"version",
|
|
|
|
"store",
|
|
|
|
"storeType"
|
|
|
|
);
|
|
|
|
closed!(webextension_alternate_references, "we:alternateReferences");
|
|
|
|
open!(open_webextension_properties, "we:properties");
|
|
|
|
closed!(webextension_property, "we:property", "name", "value");
|
|
|
|
closed!(webextension_bindings, "we:bindings");
|
|
|
|
closed!(webextension_snapshot, "we:snapshot", "xmlns:r");
|
|
|
|
|
|
|
|
// taskpanes
|
|
|
|
open!(open_taskpanes, "wetp:taskpanes", "xmlns:wetp");
|
|
|
|
open!(
|
|
|
|
open_taskpane,
|
|
|
|
"wetp:taskpane",
|
|
|
|
"dockstate",
|
|
|
|
"visibility",
|
|
|
|
"width",
|
|
|
|
"row"
|
|
|
|
);
|
|
|
|
closed!(webextensionref, "wetp:webextensionref", "xmlns:r", "r:id");
|
|
|
|
|
2021-07-13 12:46:15 +03:00
|
|
|
// customXML
|
|
|
|
open!(
|
|
|
|
open_data_store_item,
|
|
|
|
"ds:datastoreItem",
|
|
|
|
"xmlns:ds",
|
|
|
|
"ds:itemID"
|
|
|
|
);
|
|
|
|
open!(open_data_store_schema_refs, "ds:schemaRefs");
|
|
|
|
|
2020-08-13 19:57:59 +03:00
|
|
|
// CommentExtended
|
|
|
|
// w15:commentEx w15:paraId="00000001" w15:paraIdParent="57D1BD7C" w15:done="0"
|
|
|
|
pub(crate) fn comment_extended(
|
|
|
|
mut self,
|
|
|
|
paragraph_id: &str,
|
|
|
|
done: bool,
|
|
|
|
parent_paragraph_id: &Option<String>,
|
|
|
|
) -> Self {
|
|
|
|
if let Some(parent_paragraph_id) = parent_paragraph_id {
|
|
|
|
self.writer
|
|
|
|
.write(
|
|
|
|
XmlEvent::start_element("w15:commentEx")
|
|
|
|
.attr("w15:paraId", paragraph_id)
|
|
|
|
.attr("w15:paraIdParent", parent_paragraph_id)
|
|
|
|
.attr("w15:done", &format!("{}", done as usize)),
|
|
|
|
)
|
|
|
|
.expect(EXPECT_MESSAGE);
|
|
|
|
return self.close();
|
|
|
|
}
|
|
|
|
self.writer
|
|
|
|
.write(
|
|
|
|
XmlEvent::start_element("w15:commentEx")
|
|
|
|
.attr("w15:paraId", paragraph_id)
|
|
|
|
.attr("w15:done", &format!("{}", done as usize)),
|
|
|
|
)
|
|
|
|
.expect(EXPECT_MESSAGE);
|
|
|
|
self.close()
|
|
|
|
}
|
2021-03-19 18:38:22 +02:00
|
|
|
|
|
|
|
// docGrid
|
|
|
|
pub(crate) fn doc_grid(
|
|
|
|
mut self,
|
|
|
|
t: &DocGridType,
|
|
|
|
line_pitch: Option<usize>,
|
2022-06-15 17:43:19 +03:00
|
|
|
char_space: Option<isize>,
|
2021-03-19 18:38:22 +02:00
|
|
|
) -> Self {
|
|
|
|
let t = t.to_string();
|
|
|
|
let line_pitch_string = format!("{}", line_pitch.unwrap_or_default());
|
|
|
|
let char_space_string = format!("{}", char_space.unwrap_or_default());
|
|
|
|
let mut w = XmlEvent::start_element("w:docGrid").attr("w:type", &t);
|
|
|
|
if line_pitch.is_some() {
|
|
|
|
w = w.attr("w:linePitch", &line_pitch_string);
|
|
|
|
}
|
|
|
|
if char_space.is_some() {
|
2021-09-29 03:03:39 +03:00
|
|
|
w = w.attr("w:charSpace", &char_space_string);
|
2021-03-19 18:38:22 +02:00
|
|
|
}
|
|
|
|
self.writer.write(w).expect(EXPECT_MESSAGE);
|
|
|
|
|
|
|
|
self.close()
|
|
|
|
}
|
2022-01-02 19:18:04 +02:00
|
|
|
|
|
|
|
pub(crate) fn tab(
|
|
|
|
mut self,
|
|
|
|
v: Option<TabValueType>,
|
|
|
|
leader: Option<TabLeaderType>,
|
|
|
|
pos: Option<usize>,
|
|
|
|
) -> Self {
|
|
|
|
let v_string = if let Some(v) = v {
|
|
|
|
v.to_string()
|
|
|
|
} else {
|
|
|
|
"".to_string()
|
|
|
|
};
|
|
|
|
|
|
|
|
let leader_string = if let Some(leader) = leader {
|
|
|
|
leader.to_string()
|
|
|
|
} else {
|
|
|
|
"".to_string()
|
|
|
|
};
|
|
|
|
|
|
|
|
let pos_string = format!("{}", pos.unwrap_or_default());
|
|
|
|
|
|
|
|
let mut t = XmlEvent::start_element("w:tab");
|
|
|
|
if v.is_some() {
|
|
|
|
t = t.attr("w:val", &v_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if leader.is_some() {
|
|
|
|
t = t.attr("w:leader", &leader_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if pos.is_some() {
|
|
|
|
t = t.attr("w:pos", &pos_string);
|
|
|
|
}
|
|
|
|
self.writer.write(t).expect(EXPECT_MESSAGE);
|
|
|
|
|
|
|
|
self.close()
|
|
|
|
}
|
2019-11-11 04:10:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
#[cfg(test)]
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sz() {
|
|
|
|
let b = XMLBuilder::new();
|
|
|
|
let r = b.sz(20).build();
|
|
|
|
assert_eq!(str::from_utf8(&r).unwrap(), r#"<w:sz w:val="20" />"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_declaration() {
|
|
|
|
let b = XMLBuilder::new();
|
|
|
|
let r = b
|
|
|
|
.open_style(StyleType::Paragraph, "Heading")
|
|
|
|
.close()
|
|
|
|
.build();
|
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&r).unwrap(),
|
|
|
|
r#"<w:style w:type="paragraph" w:styleId="Heading" />"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_next() {
|
|
|
|
let b = XMLBuilder::new();
|
|
|
|
let r = b.next("Normal").build();
|
|
|
|
assert_eq!(str::from_utf8(&r).unwrap(), r#"<w:next w:val="Normal" />"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_name() {
|
|
|
|
let b = XMLBuilder::new();
|
|
|
|
let r = b.name("Heading").build();
|
|
|
|
assert_eq!(str::from_utf8(&r).unwrap(), r#"<w:name w:val="Heading" />"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_color() {
|
|
|
|
let b = XMLBuilder::new();
|
|
|
|
let r = b.color("2E74B5").build();
|
|
|
|
assert_eq!(str::from_utf8(&r).unwrap(), r#"<w:color w:val="2E74B5" />"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_based_on() {
|
|
|
|
let b = XMLBuilder::new();
|
|
|
|
let r = b.based_on("Normal").build();
|
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&r).unwrap(),
|
|
|
|
r#"<w:basedOn w:val="Normal" />"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|