2019-12-11 07:12:22 +02:00
|
|
|
use super::*;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
#[derive(Debug)]
|
2020-01-24 12:44:43 +02:00
|
|
|
pub struct Docx(docx_rs::Docx);
|
2019-12-11 07:12:22 +02:00
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
pub fn createDocx() -> Docx {
|
2020-01-24 12:44:43 +02:00
|
|
|
Docx(docx_rs::Docx::new())
|
2019-12-11 07:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
impl Docx {
|
|
|
|
pub fn add_paragraph(mut self, p: Paragraph) -> Self {
|
|
|
|
self.0 = self.0.add_paragraph(p.take());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-09-02 12:23:53 +03:00
|
|
|
pub fn add_bookmark_start(mut self, id: usize, name: &str) -> Self {
|
|
|
|
self.0 = self.0.add_bookmark_start(id, name);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_bookmark_end(mut self, id: usize) -> Docx {
|
|
|
|
self.0 = self.0.add_bookmark_end(id);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-12-11 07:12:22 +02:00
|
|
|
pub fn add_table(mut self, t: Table) -> Docx {
|
|
|
|
self.0.document = self.0.document.add_table(t.take());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:21:26 +02:00
|
|
|
pub fn add_abstract_numbering(mut self, num: AbstractNumbering) -> Docx {
|
|
|
|
self.0.numberings = self.0.numberings.add_abstract_numbering(num.take());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-12-11 07:12:22 +02:00
|
|
|
pub fn add_numbering(mut self, num: Numbering) -> Docx {
|
|
|
|
self.0.numberings = self.0.numberings.add_numbering(num.take());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-02-25 03:27:59 +02:00
|
|
|
pub fn created_at(mut self, date: &str) -> Self {
|
|
|
|
self.0.doc_props = self.0.doc_props.created_at(date);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn updated_at(mut self, date: &str) -> Self {
|
|
|
|
self.0.doc_props = self.0.doc_props.updated_at(date);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-06-23 12:39:01 +03:00
|
|
|
pub fn custom_property(mut self, name: &str, item: &str) -> Self {
|
|
|
|
self.0.doc_props = self.0.doc_props.custom_property(name, item);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-08-19 18:53:35 +03:00
|
|
|
pub fn doc_id(mut self, id: &str) -> Docx {
|
|
|
|
self.0 = self.0.doc_id(id);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-12-15 08:38:17 +02:00
|
|
|
pub fn add_doc_var(mut self, name: &str, val: &str) -> Docx {
|
|
|
|
self.0 = self.0.add_doc_var(name, val);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-03-26 06:37:01 +02:00
|
|
|
pub fn default_tab_stop(mut self, stop: usize) -> Docx {
|
|
|
|
self.0 = self.0.default_tab_stop(stop);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-10-09 14:30:55 +03:00
|
|
|
pub fn page_size(mut self, w: u32, h: u32) -> Docx {
|
|
|
|
self.0 = self.0.page_size(w, h);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-03-24 09:51:11 +02:00
|
|
|
pub fn page_orient(mut self, o: docx_rs::PageOrientationType) -> Docx {
|
|
|
|
self.0 = self.0.page_orient(o);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-10-12 18:04:09 +03:00
|
|
|
pub fn page_margin(mut self, margin: PageMargin) -> Docx {
|
|
|
|
self.0 = self.0.page_margin(margin.take());
|
2020-10-09 14:30:55 +03:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-12-14 08:01:23 +02:00
|
|
|
pub fn default_size(mut self, size: usize) -> Self {
|
|
|
|
self.0.styles = self.0.styles.default_size(size);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn default_spacing(mut self, spacing: i32) -> Self {
|
|
|
|
self.0.styles = self.0.styles.default_spacing(spacing);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn default_fonts(mut self, font: RunFonts) -> Self {
|
|
|
|
self.0.styles = self.0.styles.default_fonts(font.take());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-06-30 16:37:13 +03:00
|
|
|
pub fn taskpanes(mut self) -> Self {
|
|
|
|
self.0 = self.0.taskpanes();
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn web_extension(mut self, ext: WebExtension) -> Self {
|
|
|
|
self.0 = self.0.web_extension(ext.take());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-03-19 18:38:22 +02:00
|
|
|
pub fn doc_grid(
|
|
|
|
mut self,
|
|
|
|
grid_type: docx_rs::DocGridType,
|
|
|
|
line_pitch: Option<usize>,
|
|
|
|
char_space: Option<usize>,
|
|
|
|
) -> Self {
|
|
|
|
let mut doc_grid = docx_rs::DocGrid::with_empty().grid_type(grid_type);
|
|
|
|
if let Some(line_pitch) = line_pitch {
|
|
|
|
doc_grid = doc_grid.line_pitch(line_pitch);
|
|
|
|
}
|
|
|
|
if let Some(char_space) = char_space {
|
|
|
|
doc_grid = doc_grid.char_space(char_space);
|
|
|
|
}
|
|
|
|
self.0.document = self.0.document.doc_grid(doc_grid);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 09:51:45 +03:00
|
|
|
pub fn build(&mut self, has_numberings: bool) -> Result<Vec<u8>, JsValue> {
|
2019-12-11 07:12:22 +02:00
|
|
|
let buf = Vec::new();
|
|
|
|
let mut cur = std::io::Cursor::new(buf);
|
2020-05-15 09:51:45 +03:00
|
|
|
if has_numberings {
|
|
|
|
self.0.document_rels.has_numberings = true;
|
|
|
|
}
|
2019-12-11 07:12:22 +02:00
|
|
|
let res = self.0.build().pack(&mut cur);
|
|
|
|
if res.is_err() {
|
|
|
|
return Err(format!("{:?}", res).into());
|
|
|
|
}
|
|
|
|
Ok(cur.into_inner())
|
|
|
|
}
|
2020-12-21 11:44:31 +02:00
|
|
|
|
2020-12-21 13:52:15 +02:00
|
|
|
pub fn json_with_update_comments(&mut self) -> String {
|
|
|
|
self.0.json_with_update_comments()
|
2020-12-21 11:44:31 +02:00
|
|
|
}
|
2019-12-11 07:12:22 +02:00
|
|
|
}
|