2020-02-11 10:01:39 +02:00
|
|
|
use serde::Serialize;
|
|
|
|
|
2020-05-14 06:01:20 +03:00
|
|
|
use super::*;
|
2019-11-13 11:50:15 +02:00
|
|
|
use crate::documents::BuildXML;
|
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
2020-02-11 10:01:39 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2019-12-15 19:19:30 +02:00
|
|
|
pub struct DocumentRels {
|
2020-02-11 10:01:39 +02:00
|
|
|
pub has_comments: bool,
|
|
|
|
pub has_numberings: bool,
|
2020-05-14 06:01:20 +03:00
|
|
|
pub image_ids: Vec<usize>,
|
2021-07-13 12:46:15 +03:00
|
|
|
pub custom_xml_count: usize,
|
2021-11-25 16:33:13 +02:00
|
|
|
pub header_count: usize,
|
2021-11-24 18:49:27 +02:00
|
|
|
pub footer_count: usize,
|
2019-12-15 19:19:30 +02:00
|
|
|
}
|
2019-11-13 11:50:15 +02:00
|
|
|
|
|
|
|
impl DocumentRels {
|
|
|
|
pub fn new() -> DocumentRels {
|
2020-01-24 10:57:14 +02:00
|
|
|
Default::default()
|
|
|
|
}
|
2021-07-13 12:46:15 +03:00
|
|
|
|
|
|
|
pub fn add_custom_item(mut self) -> Self {
|
|
|
|
self.custom_xml_count += 1;
|
|
|
|
self
|
|
|
|
}
|
2020-01-24 10:57:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for DocumentRels {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2019-12-15 19:19:30 +02:00
|
|
|
has_comments: false,
|
|
|
|
has_numberings: false,
|
2020-05-14 06:01:20 +03:00
|
|
|
image_ids: vec![],
|
2021-07-13 12:46:15 +03:00
|
|
|
custom_xml_count: 0,
|
2021-11-25 16:33:13 +02:00
|
|
|
header_count: 0,
|
2021-11-24 18:49:27 +02:00
|
|
|
footer_count: 0,
|
2019-12-15 19:19:30 +02:00
|
|
|
}
|
2019-11-13 11:50:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for DocumentRels {
|
|
|
|
fn build(&self) -> Vec<u8> {
|
2019-12-15 19:19:30 +02:00
|
|
|
let mut b = XMLBuilder::new();
|
|
|
|
b = b
|
|
|
|
.declaration(None)
|
2019-11-13 11:50:15 +02:00
|
|
|
.open_relationships("http://schemas.openxmlformats.org/package/2006/relationships")
|
|
|
|
.relationship(
|
|
|
|
"rId1",
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
|
|
|
|
"styles.xml",
|
|
|
|
)
|
|
|
|
.relationship(
|
|
|
|
"rId2",
|
2019-12-15 19:19:30 +02:00
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
|
|
|
|
"fontTable.xml",
|
2019-12-06 12:18:48 +02:00
|
|
|
)
|
|
|
|
.relationship(
|
|
|
|
"rId3",
|
2019-12-15 19:19:30 +02:00
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
|
|
|
|
"settings.xml",
|
2020-08-13 11:27:45 +03:00
|
|
|
)
|
2020-08-13 19:57:59 +03:00
|
|
|
.relationship(
|
|
|
|
"rId5",
|
|
|
|
"http://schemas.microsoft.com/office/2011/relationships/commentsExtended",
|
|
|
|
"commentsExtended.xml",
|
2019-12-15 19:19:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if self.has_comments {
|
|
|
|
b = b.relationship(
|
2020-08-13 19:57:59 +03:00
|
|
|
"rId6",
|
2019-12-05 08:44:18 +02:00
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
|
|
|
"comments.xml",
|
|
|
|
)
|
2019-12-15 19:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if self.has_numberings {
|
|
|
|
b = b.relationship(
|
2020-08-13 19:57:59 +03:00
|
|
|
"rId7",
|
2019-12-15 19:19:30 +02:00
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
|
|
|
|
"numbering.xml",
|
2019-11-13 11:50:15 +02:00
|
|
|
)
|
2019-12-15 19:19:30 +02:00
|
|
|
}
|
|
|
|
|
2021-11-25 16:33:13 +02:00
|
|
|
for i in 0..self.header_count {
|
|
|
|
b = b.relationship(
|
|
|
|
&create_header_rid(i + 1),
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
|
|
|
|
&format!("header{}.xml", i + 1),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-11-24 18:49:27 +02:00
|
|
|
for i in 0..self.footer_count {
|
|
|
|
b = b.relationship(
|
|
|
|
&create_footer_rid(i + 1),
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
|
|
|
|
&format!("footer{}.xml", i + 1),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-13 12:46:15 +03:00
|
|
|
for i in 0..self.custom_xml_count {
|
|
|
|
b = b.relationship(
|
|
|
|
&format!("rId{}", i + 8),
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml",
|
|
|
|
&format!("../customXml/item{}.xml", i + 1),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-14 06:01:20 +03:00
|
|
|
for id in self.image_ids.iter() {
|
|
|
|
b = b.relationship(
|
|
|
|
&create_pic_rid(*id),
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
|
|
&format!("media/image{}.jpg", *id),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-15 19:19:30 +02:00
|
|
|
b.close().build()
|
2019-11-13 11:50:15 +02:00
|
|
|
}
|
|
|
|
}
|