Support floating image (#75)

* feat: Support floating image

* chore: update README

* fix: lint error
main
bokuweb 2020-06-03 03:27:04 +09:00 committed by GitHub
parent d3fcef1e2f
commit 69aedcb9d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 527 additions and 69 deletions

View File

@ -80,6 +80,7 @@ writeFileSync("hello.docx", buf);
- [Numbering](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/numbering.rs) - [Numbering](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/numbering.rs)
- [Table](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/table.rs) - [Table](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/table.rs)
- [Comment](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/comment.rs) - [Comment](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/comment.rs)
- [Image](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/image_inline.rs)
- [History](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/history.rs) - [History](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/history.rs)
## Features ## Features
@ -100,7 +101,7 @@ writeFileSync("hello.docx", buf);
- [ ] Header - [ ] Header
- [ ] Footer - [ ] Footer
- [x] Comment - [x] Comment
- [ ] Image - [x] Image
- [x] Style - [x] Style
- [x] Table - [x] Table
- [x] HIstory - [x] HIstory

View File

@ -0,0 +1,23 @@
use std::fs::*;
use std::io::Read;
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./output/image.docx");
let file = File::create(&path).unwrap();
let mut img = File::open("./images/cat_min.jpg").unwrap();
let mut buf = Vec::new();
let _ = img.read_to_end(&mut buf).unwrap();
let pic = Pic::new(buf)
.size(320, 240)
.floating()
.offset_x(300)
.offset_y(400);
Docx::new()
.add_paragraph(Paragraph::new().add_run(Run::new().add_image(pic)))
.build()
.pack(file)?;
Ok(())
}

View File

@ -8,6 +8,8 @@ use crate::xml_builder::*;
#[derive(Debug, Clone, Serialize, PartialEq)] #[derive(Debug, Clone, Serialize, PartialEq)]
pub struct Drawing { pub struct Drawing {
pub position_type: DrawingPositionType, pub position_type: DrawingPositionType,
pub position_h: DrawingPosition,
pub position_v: DrawingPosition,
pub data: Option<DrawingData>, pub data: Option<DrawingData>,
// TODO: Old definition, remove later // TODO: Old definition, remove later
pub children: Vec<DrawingChild>, pub children: Vec<DrawingChild>,
@ -56,6 +58,7 @@ impl Drawing {
Default::default() Default::default()
} }
// TODO: Remove later
pub fn add_anchor(mut self, a: WpAnchor) -> Drawing { pub fn add_anchor(mut self, a: WpAnchor) -> Drawing {
self.children.push(DrawingChild::WpAnchor(a)); self.children.push(DrawingChild::WpAnchor(a));
self self
@ -65,6 +68,21 @@ impl Drawing {
self.data = Some(DrawingData::Pic(pic)); self.data = Some(DrawingData::Pic(pic));
self self
} }
pub fn floating(mut self) -> Drawing {
self.position_type = DrawingPositionType::Anchor;
self
}
pub fn position_h(mut self, pos: DrawingPosition) -> Drawing {
self.position_h = pos;
self
}
pub fn position_v(mut self, pos: DrawingPosition) -> Drawing {
self.position_v = pos;
self
}
} }
impl Default for Drawing { impl Default for Drawing {
@ -77,12 +95,14 @@ impl Default for Drawing {
dist_r: 0, dist_r: 0,
}, },
data: None, data: None,
position_v: DrawingPosition::Offset(0),
position_h: DrawingPosition::Offset(0),
children: vec![], children: vec![],
} }
} }
} }
impl BuildXML for Drawing { impl BuildXML for Box<Drawing> {
fn build(&self) -> Vec<u8> { fn build(&self) -> Vec<u8> {
let b = XMLBuilder::new(); let b = XMLBuilder::new();
let mut b = b.open_drawing(); let mut b = b.open_drawing();
@ -90,7 +110,21 @@ impl BuildXML for Drawing {
if let DrawingPositionType::Inline { .. } = self.position_type { if let DrawingPositionType::Inline { .. } = self.position_type {
b = b.open_wp_inline("0", "0", "0", "0") b = b.open_wp_inline("0", "0", "0", "0")
} else { } else {
b = b.open_wp_anchor("0", "0", "0", "0"); b = b
.open_wp_anchor("0", "0", "0", "0", "0", "1", "0", "0", "1", "1905000")
.simple_pos("0", "0")
.open_position_h("page");
if let DrawingPosition::Offset(x) = self.position_h {
let x = format!("{}", crate::types::emu::from_px(x as u32));
b = b.pos_offset(&x).close();
}
b = b.open_position_v("page");
if let DrawingPosition::Offset(y) = self.position_v {
let y = format!("{}", crate::types::emu::from_px(y as u32));
b = b.pos_offset(&y).close();
}
} }
match &self.data { match &self.data {
Some(DrawingData::Pic(p)) => { Some(DrawingData::Pic(p)) => {
@ -101,6 +135,7 @@ impl BuildXML for Drawing {
// One inch equates to 914400 EMUs and a centimeter is 360000 // One inch equates to 914400 EMUs and a centimeter is 360000
.wp_extent(&w, &h) .wp_extent(&w, &h)
.wp_effect_extent("0", "0", "0", "0") .wp_effect_extent("0", "0", "0", "0")
.wrap_none()
.wp_doc_pr("1", "Figure") .wp_doc_pr("1", "Figure")
.open_wp_c_nv_graphic_frame_pr() .open_wp_c_nv_graphic_frame_pr()
.a_graphic_frame_locks( .a_graphic_frame_locks(
@ -135,13 +170,14 @@ mod tests {
let mut img = std::fs::File::open("../images/cat_min.jpg").unwrap(); let mut img = std::fs::File::open("../images/cat_min.jpg").unwrap();
let mut buf = Vec::new(); let mut buf = Vec::new();
let _ = img.read_to_end(&mut buf).unwrap(); let _ = img.read_to_end(&mut buf).unwrap();
let d = Drawing::new().pic(Pic::new(buf)).build(); let d = Box::new(Drawing::new().pic(Pic::new(buf))).build();
assert_eq!( assert_eq!(
str::from_utf8(&d).unwrap(), str::from_utf8(&d).unwrap(),
r#"<w:drawing> r#"<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0"> <wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="3048000" cy="2286000" /> <wp:extent cx="3048000" cy="2286000" />
<wp:effectExtent b="0" l="0" r="0" t="0" /> <wp:effectExtent b="0" l="0" r="0" t="0" />
<wp:wrapNone />
<wp:docPr id="1" name="Figure" /> <wp:docPr id="1" name="Figure" />
<wp:cNvGraphicFramePr> <wp:cNvGraphicFramePr>
<a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1" /> <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1" />

View File

@ -1,15 +1,33 @@
use super::*;
use image::*; use image::*;
use serde::Serialize; use serde::Serialize;
use crate::documents::*; use crate::documents::*;
use crate::xml_builder::*; use crate::xml_builder::*;
#[derive(Debug, Clone, Copy, Serialize, PartialEq)]
pub enum PicAlign {
Left,
Right,
Bottom,
Top,
}
#[derive(Debug, Clone, Copy, Serialize, PartialEq)]
pub enum DrawingPosition {
Offset(usize),
Align(PicAlign),
}
#[derive(Debug, Clone, Serialize, PartialEq)] #[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Pic { pub struct Pic {
pub id: usize, pub id: usize,
pub image: Vec<u8>, pub image: Vec<u8>,
pub size: (u32, u32), pub size: (u32, u32),
pub position_type: DrawingPositionType,
pub position_h: DrawingPosition,
pub position_v: DrawingPosition,
} }
impl Pic { impl Pic {
@ -21,13 +39,40 @@ impl Pic {
dimg dimg
.write_to(&mut image, ImageFormat::Png) .write_to(&mut image, ImageFormat::Png)
.expect("Unable to write"); .expect("Unable to write");
Self { id, image, size } Self {
id,
image,
size,
position_type: DrawingPositionType::Inline {
dist_t: 0,
dist_b: 0,
dist_l: 0,
dist_r: 0,
},
position_h: DrawingPosition::Offset(0),
position_v: DrawingPosition::Offset(0),
}
} }
pub fn size(mut self, w_px: u32, h_px: u32) -> Pic { pub fn size(mut self, w_px: u32, h_px: u32) -> Pic {
self.size = (w_px, h_px); self.size = (w_px, h_px);
self self
} }
pub fn floating(mut self) -> Pic {
self.position_type = DrawingPositionType::Anchor;
self
}
pub fn offset_x(mut self, x: usize) -> Pic {
self.position_h = DrawingPosition::Offset(x);
self
}
pub fn offset_y(mut self, y: usize) -> Pic {
self.position_v = DrawingPosition::Offset(y);
self
}
} }
impl BuildXML for Pic { impl BuildXML for Pic {

View File

@ -29,7 +29,7 @@ pub enum RunChild {
DeleteText(DeleteText), DeleteText(DeleteText),
Tab(Tab), Tab(Tab),
Break(Break), Break(Break),
Drawing(Drawing), Drawing(Box<Drawing>),
} }
impl Serialize for RunChild { impl Serialize for RunChild {
@ -95,14 +95,26 @@ impl Run {
} }
pub fn add_image(mut self, pic: Pic) -> Run { pub fn add_image(mut self, pic: Pic) -> Run {
if pic.position_type == DrawingPositionType::Anchor {
let pos_h = pic.position_h;
let pos_v = pic.position_v;
self.children.push(RunChild::Drawing(Box::new(
Drawing::new()
.pic(pic)
.floating()
.position_h(pos_h)
.position_v(pos_v),
)));
} else {
self.children self.children
.push(RunChild::Drawing(Drawing::new().pic(pic))); .push(RunChild::Drawing(Box::new(Drawing::new().pic(pic))));
}
self self
} }
// TODO: Remove later // TODO: Remove later
pub fn add_drawing(mut self, d: Drawing) -> Run { pub fn add_drawing(mut self, d: Drawing) -> Run {
self.children.push(RunChild::Drawing(d)); self.children.push(RunChild::Drawing(Box::new(d)));
self self
} }

View File

@ -2,9 +2,30 @@ use super::XMLBuilder;
use super::XmlEvent; use super::XmlEvent;
impl XMLBuilder { impl XMLBuilder {
open!(open_wp_inline, "wp:inline", "distT", "distB", "distL", "distR"); open!(
// TODO: Add some parameters open_wp_inline,
open!(open_wp_anchor, "wp:inline", "distT", "distB", "distL", "distR"); "wp:inline",
"distT",
"distB",
"distL",
"distR"
);
#[allow(clippy::too_many_arguments)]
open!(
open_wp_anchor,
"wp:anchor",
"distT",
"distB",
"distL",
"distR",
"simplePos",
"allowOverlap",
"behindDoc",
"locked",
"layoutInCell",
"relativeHeight"
);
open!(open_a_graphic, "a:graphic", "xmlns:a"); open!(open_a_graphic, "a:graphic", "xmlns:a");
open!(open_a_graphic_data, "a:graphicData", "uri"); open!(open_a_graphic_data, "a:graphicData", "uri");
@ -18,4 +39,10 @@ impl XMLBuilder {
"xmlns:a", "xmlns:a",
"noChangeAspect" "noChangeAspect"
); );
closed!(simple_pos, "wp:simplePos", "x", "y");
open!(open_position_h, "wp:positionH", "relativeFrom");
open!(open_position_v, "wp:positionV", "relativeFrom");
closed_with_child!(pos_offset, "wp:posOffset");
closed!(wrap_none, "wp:wrapNone");
} }

View File

@ -19,7 +19,11 @@ macro_rules! open {
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str) -> Self { pub(crate) fn $name(mut self, arg0: &str, arg1: &str) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1),
)
.expect("should write to buf"); .expect("should write to buf");
self self
} }
@ -27,7 +31,12 @@ macro_rules! open {
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str) -> Self { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2),
)
.expect("should write to buf"); .expect("should write to buf");
self self
} }
@ -35,15 +44,210 @@ macro_rules! open {
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str) -> Self { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3),
)
.expect("should write to buf"); .expect("should write to buf");
self self
} }
}; };
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str) -> Self { pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4),
)
.expect("should write to buf");
self
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr) => {
pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
) -> Self {
self.writer
.write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5),
)
.expect("should write to buf");
self
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr) => {
pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
arg6: &str,
) -> Self {
self.writer
.write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5)
.attr($attr6, arg6),
)
.expect("should write to buf");
self
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr) => {
pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
arg6: &str,
arg7: &str,
) -> Self {
self.writer
.write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5)
.attr($attr6, arg6)
.attr($attr7, arg7),
)
.expect("should write to buf");
self
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr, $attr8: expr) => {
pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
arg6: &str,
arg7: &str,
arg8: &str,
) -> Self {
self.writer
.write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5)
.attr($attr6, arg6)
.attr($attr7, arg7)
.attr($attr8, arg8),
)
.expect("should write to buf");
self
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr, $attr8: expr, $attr9: expr) => {
#[allow(clippy::too_many_arguments)]
pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
arg6: &str,
arg7: &str,
arg8: &str,
arg9: &str,
) -> Self {
self.writer
.write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5)
.attr($attr6, arg6)
.attr($attr7, arg7)
.attr($attr8, arg8)
.attr($attr9, arg9),
)
.expect("should write to buf");
self
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr, $attr8: expr, $attr9: expr, $attr10: expr) => {
pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
arg6: &str,
arg7: &str,
arg8: &str,
arg9: &str,
arg10: &str,
) -> Self {
self.writer
.write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5)
.attr($attr6, arg6)
.attr($attr7, arg7)
.attr($attr8, arg8)
.attr($attr9, arg9)
.attr($attr10, arg10),
)
.expect("should write to buf"); .expect("should write to buf");
self self
} }
@ -63,9 +267,7 @@ macro_rules! open_with_attrs {
val = &attr.1; val = &attr.1;
e = e.attr(key, val); e = e.attr(key, val);
} }
self.writer self.writer.write(e).expect("should write to buf");
.write(e)
.expect("should write to buf");
self self
} }
}; };
@ -78,9 +280,7 @@ macro_rules! closed_with_child {
self.writer self.writer
.write(XmlEvent::start_element($el_name)) .write(XmlEvent::start_element($el_name))
.expect("should write to buf"); .expect("should write to buf");
self.writer self.writer.write(child).expect("should write to buf");
.write(child)
.expect("should write to buf");
self.close() self.close()
} }
}; };
@ -89,31 +289,34 @@ macro_rules! closed_with_child {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0)) .write(XmlEvent::start_element($el_name).attr($attr0, arg0))
.expect("should write to buf"); .expect("should write to buf");
self.writer self.writer.write(child).expect("should write to buf");
.write(child)
.expect("should write to buf");
self.close() self.close()
} }
}; };
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, child: &str) -> Self { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, child: &str) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1)) .write(
.expect("should write to buf"); XmlEvent::start_element($el_name)
self.writer .attr($attr0, arg0)
.write(child) .attr($attr1, arg1),
)
.expect("should write to buf"); .expect("should write to buf");
self.writer.write(child).expect("should write to buf");
self.close() self.close()
} }
}; };
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, child: &str) -> Self { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, child: &str) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2)) .write(
.expect("should write to buf"); XmlEvent::start_element($el_name)
self.writer .attr($attr0, arg0)
.write(child) .attr($attr1, arg1)
.attr($attr2, arg2),
)
.expect("should write to buf"); .expect("should write to buf");
self.writer.write(child).expect("should write to buf");
self.close() self.close()
} }
}; };
@ -140,7 +343,11 @@ macro_rules! closed {
#[allow(dead_code)] #[allow(dead_code)]
pub(crate) fn $name(mut self, arg0: &str, arg1: &str) -> Self { pub(crate) fn $name(mut self, arg0: &str, arg1: &str) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1),
)
.expect("should write to buf"); .expect("should write to buf");
self.close() self.close()
} }
@ -148,7 +355,12 @@ macro_rules! closed {
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str) -> Self { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2),
)
.expect("should write to buf"); .expect("should write to buf");
self.close() self.close()
} }
@ -156,50 +368,146 @@ macro_rules! closed {
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str) -> Self { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3),
)
.expect("should write to buf"); .expect("should write to buf");
self.close() self.close()
} }
}; };
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str) -> Self { pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4),
)
.expect("should write to buf"); .expect("should write to buf");
self.close() self.close()
} }
}; };
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr) => {
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str, arg5: &str) -> Self { pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4).attr($attr5, arg5)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5),
)
.expect("should write to buf"); .expect("should write to buf");
self.close() self.close()
} }
}; };
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr) => {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str, arg5: &str, arg6: &str) -> Self { pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
arg6: &str,
) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4).attr($attr5, arg5).attr($attr6, arg6)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5)
.attr($attr6, arg6),
)
.expect("should write to buf"); .expect("should write to buf");
self.close() self.close()
} }
}; };
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr) => {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str, arg5: &str, arg6: &str, arg7: &str) -> Self { pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
arg6: &str,
arg7: &str,
) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4).attr($attr5, arg5).attr($attr6, arg6).attr($attr7, arg7)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5)
.attr($attr6, arg6)
.attr($attr7, arg7),
)
.expect("should write to buf"); .expect("should write to buf");
self.close() self.close()
} }
}; };
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr, $attr8: expr) => { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr, $attr8: expr) => {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str, arg5: &str, arg6: &str, arg7: &str, arg8: &str) -> Self { pub(crate) fn $name(
mut self,
arg0: &str,
arg1: &str,
arg2: &str,
arg3: &str,
arg4: &str,
arg5: &str,
arg6: &str,
arg7: &str,
arg8: &str,
) -> Self {
self.writer self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4).attr($attr5, arg5).attr($attr6, arg6).attr($attr7, arg7).attr($attr8, arg8)) .write(
XmlEvent::start_element($el_name)
.attr($attr0, arg0)
.attr($attr1, arg1)
.attr($attr2, arg2)
.attr($attr3, arg3)
.attr($attr4, arg4)
.attr($attr5, arg5)
.attr($attr6, arg6)
.attr($attr7, arg7)
.attr($attr8, arg8),
)
.expect("should write to buf"); .expect("should write to buf");
self.close() self.close()
} }
@ -246,7 +554,13 @@ macro_rules! closed_w_with_type_el {
macro_rules! closed_border_el { macro_rules! closed_border_el {
($name: ident, $el_name: expr) => { ($name: ident, $el_name: expr) => {
pub(crate) fn $name(mut self, val: BorderType, size: usize, space: usize, color: &str) -> Self { pub(crate) fn $name(
mut self,
val: BorderType,
size: usize,
space: usize,
color: &str,
) -> Self {
self.writer self.writer
.write( .write(
XmlEvent::start_element($el_name) XmlEvent::start_element($el_name)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -21,7 +21,7 @@
<wp:anchor distT="0" distB="0" distL="0" distR="0" simplePos="0" allowOverlap="1" behindDoc="0" locked="0" layoutInCell="1" relativeHeight="1905000"> <wp:anchor distT="0" distB="0" distL="0" distR="0" simplePos="0" allowOverlap="1" behindDoc="0" locked="0" layoutInCell="1" relativeHeight="1905000">
<wp:simplePos x="0" y="0"/> <wp:simplePos x="0" y="0"/>
<wp:positionH relativeFrom="page"> <wp:positionH relativeFrom="page">
<wp:align>right</wp:align> <wp:posOffset>2014400</wp:posOffset>
</wp:positionH> </wp:positionH>
<wp:positionV relativeFrom="page"> <wp:positionV relativeFrom="page">
<wp:align>bottom</wp:align> <wp:align>bottom</wp:align>