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::*;
|
|
|
|
|
2022-03-28 13:40:32 +03:00
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Default)]
|
2020-02-11 10:01:39 +02:00
|
|
|
#[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,
|
2022-03-28 13:40:32 +03:00
|
|
|
pub images: Vec<(String, String)>,
|
2022-07-06 04:47:15 +03:00
|
|
|
pub hyperlinks: Vec<(String, String)>,
|
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
|
|
|
|
}
|
2022-05-20 11:00:24 +03:00
|
|
|
|
|
|
|
pub fn add_image(mut self, id: impl Into<String>, path: impl Into<String>) -> Self {
|
|
|
|
self.images.push((id.into(), path.into()));
|
|
|
|
self
|
|
|
|
}
|
2022-07-06 04:47:15 +03:00
|
|
|
|
|
|
|
pub fn add_hyperlinks(mut self, id: impl Into<String>, path: impl Into<String>) -> Self {
|
|
|
|
self.hyperlinks.push((id.into(), path.into()));
|
|
|
|
self
|
|
|
|
}
|
2020-01-24 10:57:14 +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),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-28 13:40:32 +03:00
|
|
|
for (id, path) in self.images.iter() {
|
2020-05-14 06:01:20 +03:00
|
|
|
b = b.relationship(
|
2022-03-28 13:40:32 +03:00
|
|
|
id,
|
2020-05-14 06:01:20 +03:00
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
2022-03-28 13:40:32 +03:00
|
|
|
path,
|
2020-05-14 06:01:20 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-06 04:47:15 +03:00
|
|
|
for (id, path) in self.hyperlinks.iter() {
|
|
|
|
b = b.relationship_with_mode(
|
|
|
|
id,
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
|
|
|
|
path,
|
|
|
|
"External",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-15 19:19:30 +02:00
|
|
|
b.close().build()
|
2019-11-13 11:50:15 +02:00
|
|
|
}
|
|
|
|
}
|