From 69aedcb9d22ec14eab91eb77c9c10fa2f700d20c Mon Sep 17 00:00:00 2001 From: bokuweb Date: Wed, 3 Jun 2020 03:27:04 +0900 Subject: [PATCH] Support floating image (#75) * feat: Support floating image * chore: update README * fix: lint error --- README.md | 3 +- docx-core/examples/image_floating.rs | 23 + .../examples/{image.rs => image_inline.rs} | 0 docx-core/src/documents/elements/drawing.rs | 42 +- docx-core/src/documents/elements/pic.rs | 47 +- docx-core/src/documents/elements/run.rs | 20 +- docx-core/src/xml_builder/drawing.rs | 33 +- docx-core/src/xml_builder/macros.rs | 422 +++++++++++++++--- .../snapshots/lib__reader__read_textbox.snap | 2 +- .../tests/snapshots/reader__read_textbox.snap | 2 +- .../word/document.xml | 2 +- 11 files changed, 527 insertions(+), 69 deletions(-) create mode 100644 docx-core/examples/image_floating.rs rename docx-core/examples/{image.rs => image_inline.rs} (100%) diff --git a/README.md b/README.md index 77b983f..8f2e958 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ writeFileSync("hello.docx", buf); - [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) - [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) ## Features @@ -100,7 +101,7 @@ writeFileSync("hello.docx", buf); - [ ] Header - [ ] Footer - [x] Comment -- [ ] Image +- [x] Image - [x] Style - [x] Table - [x] HIstory diff --git a/docx-core/examples/image_floating.rs b/docx-core/examples/image_floating.rs new file mode 100644 index 0000000..9078af4 --- /dev/null +++ b/docx-core/examples/image_floating.rs @@ -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(()) +} diff --git a/docx-core/examples/image.rs b/docx-core/examples/image_inline.rs similarity index 100% rename from docx-core/examples/image.rs rename to docx-core/examples/image_inline.rs diff --git a/docx-core/src/documents/elements/drawing.rs b/docx-core/src/documents/elements/drawing.rs index dc17037..7a66360 100644 --- a/docx-core/src/documents/elements/drawing.rs +++ b/docx-core/src/documents/elements/drawing.rs @@ -8,6 +8,8 @@ use crate::xml_builder::*; #[derive(Debug, Clone, Serialize, PartialEq)] pub struct Drawing { pub position_type: DrawingPositionType, + pub position_h: DrawingPosition, + pub position_v: DrawingPosition, pub data: Option, // TODO: Old definition, remove later pub children: Vec, @@ -56,6 +58,7 @@ impl Drawing { Default::default() } + // TODO: Remove later pub fn add_anchor(mut self, a: WpAnchor) -> Drawing { self.children.push(DrawingChild::WpAnchor(a)); self @@ -65,6 +68,21 @@ impl Drawing { self.data = Some(DrawingData::Pic(pic)); 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 { @@ -77,12 +95,14 @@ impl Default for Drawing { dist_r: 0, }, data: None, + position_v: DrawingPosition::Offset(0), + position_h: DrawingPosition::Offset(0), children: vec![], } } } -impl BuildXML for Drawing { +impl BuildXML for Box { fn build(&self) -> Vec { let b = XMLBuilder::new(); let mut b = b.open_drawing(); @@ -90,7 +110,21 @@ impl BuildXML for Drawing { if let DrawingPositionType::Inline { .. } = self.position_type { b = b.open_wp_inline("0", "0", "0", "0") } 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 { Some(DrawingData::Pic(p)) => { @@ -101,6 +135,7 @@ impl BuildXML for Drawing { // One inch equates to 914400 EMUs and a centimeter is 360000 .wp_extent(&w, &h) .wp_effect_extent("0", "0", "0", "0") + .wrap_none() .wp_doc_pr("1", "Figure") .open_wp_c_nv_graphic_frame_pr() .a_graphic_frame_locks( @@ -135,13 +170,14 @@ mod tests { let mut img = std::fs::File::open("../images/cat_min.jpg").unwrap(); let mut buf = Vec::new(); 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!( str::from_utf8(&d).unwrap(), r#" + diff --git a/docx-core/src/documents/elements/pic.rs b/docx-core/src/documents/elements/pic.rs index 8945dbb..2d1fcfc 100644 --- a/docx-core/src/documents/elements/pic.rs +++ b/docx-core/src/documents/elements/pic.rs @@ -1,15 +1,33 @@ +use super::*; use image::*; use serde::Serialize; use crate::documents::*; 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)] #[serde(rename_all = "camelCase")] pub struct Pic { pub id: usize, pub image: Vec, pub size: (u32, u32), + pub position_type: DrawingPositionType, + pub position_h: DrawingPosition, + pub position_v: DrawingPosition, } impl Pic { @@ -21,13 +39,40 @@ impl Pic { dimg .write_to(&mut image, ImageFormat::Png) .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 { self.size = (w_px, h_px); 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 { diff --git a/docx-core/src/documents/elements/run.rs b/docx-core/src/documents/elements/run.rs index ad32cec..d6e3a14 100644 --- a/docx-core/src/documents/elements/run.rs +++ b/docx-core/src/documents/elements/run.rs @@ -29,7 +29,7 @@ pub enum RunChild { DeleteText(DeleteText), Tab(Tab), Break(Break), - Drawing(Drawing), + Drawing(Box), } impl Serialize for RunChild { @@ -95,14 +95,26 @@ impl Run { } pub fn add_image(mut self, pic: Pic) -> Run { - self.children - .push(RunChild::Drawing(Drawing::new().pic(pic))); + 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 + .push(RunChild::Drawing(Box::new(Drawing::new().pic(pic)))); + } self } // TODO: Remove later pub fn add_drawing(mut self, d: Drawing) -> Run { - self.children.push(RunChild::Drawing(d)); + self.children.push(RunChild::Drawing(Box::new(d))); self } diff --git a/docx-core/src/xml_builder/drawing.rs b/docx-core/src/xml_builder/drawing.rs index d56a046..0bea377 100644 --- a/docx-core/src/xml_builder/drawing.rs +++ b/docx-core/src/xml_builder/drawing.rs @@ -2,9 +2,30 @@ use super::XMLBuilder; use super::XmlEvent; impl XMLBuilder { - open!(open_wp_inline, "wp:inline", "distT", "distB", "distL", "distR"); - // TODO: Add some parameters - open!(open_wp_anchor, "wp:inline", "distT", "distB", "distL", "distR"); + open!( + open_wp_inline, + "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_data, "a:graphicData", "uri"); @@ -18,4 +39,10 @@ impl XMLBuilder { "xmlns:a", "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"); } diff --git a/docx-core/src/xml_builder/macros.rs b/docx-core/src/xml_builder/macros.rs index 16af9c0..1ecbbcb 100644 --- a/docx-core/src/xml_builder/macros.rs +++ b/docx-core/src/xml_builder/macros.rs @@ -19,7 +19,11 @@ macro_rules! open { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr) => { pub(crate) fn $name(mut self, arg0: &str, arg1: &str) -> Self { 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"); self } @@ -27,7 +31,12 @@ macro_rules! open { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr) => { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str) -> Self { 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"); self } @@ -35,15 +44,210 @@ macro_rules! open { ($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 { 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"); self } }; ($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 - .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"); self } @@ -63,9 +267,7 @@ macro_rules! open_with_attrs { val = &attr.1; e = e.attr(key, val); } - self.writer - .write(e) - .expect("should write to buf"); + self.writer.write(e).expect("should write to buf"); self } }; @@ -78,9 +280,7 @@ macro_rules! closed_with_child { self.writer .write(XmlEvent::start_element($el_name)) .expect("should write to buf"); - self.writer - .write(child) - .expect("should write to buf"); + self.writer.write(child).expect("should write to buf"); self.close() } }; @@ -89,31 +289,34 @@ macro_rules! closed_with_child { self.writer .write(XmlEvent::start_element($el_name).attr($attr0, arg0)) .expect("should write to buf"); - self.writer - .write(child) - .expect("should write to buf"); + self.writer.write(child).expect("should write to buf"); self.close() } }; ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr) => { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, child: &str) -> Self { self.writer - .write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1)) - .expect("should write to buf"); - self.writer - .write(child) + .write( + XmlEvent::start_element($el_name) + .attr($attr0, arg0) + .attr($attr1, arg1), + ) .expect("should write to buf"); + self.writer.write(child).expect("should write to buf"); self.close() } }; ($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 { self.writer - .write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2)) - .expect("should write to buf"); - self.writer - .write(child) + .write( + XmlEvent::start_element($el_name) + .attr($attr0, arg0) + .attr($attr1, arg1) + .attr($attr2, arg2), + ) .expect("should write to buf"); + self.writer.write(child).expect("should write to buf"); self.close() } }; @@ -140,7 +343,11 @@ macro_rules! closed { #[allow(dead_code)] pub(crate) fn $name(mut self, arg0: &str, arg1: &str) -> Self { 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"); self.close() } @@ -148,7 +355,12 @@ macro_rules! closed { ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr) => { pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str) -> Self { 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"); self.close() } @@ -156,50 +368,146 @@ macro_rules! closed { ($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 { 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"); self.close() } }; ($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 - .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.close() } }; ($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 - .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"); self.close() } }; ($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: 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) -> Self { + 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)) + .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.close() } }; ($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)] - 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 - .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"); 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) => { #[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 - .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"); self.close() } @@ -232,31 +540,37 @@ macro_rules! closed_with_usize { macro_rules! closed_w_with_type_el { ($name: ident, $el_name: expr) => { pub(crate) fn $name(mut self, w: i32, t: WidthType) -> Self { - self.writer - .write( - XmlEvent::start_element($el_name) - .attr("w:w", &format!("{}", w)) - .attr("w:type", &t.to_string()), - ) - .expect(EXPECT_MESSAGE); - self.close() + self.writer + .write( + XmlEvent::start_element($el_name) + .attr("w:w", &format!("{}", w)) + .attr("w:type", &t.to_string()), + ) + .expect(EXPECT_MESSAGE); + self.close() } }; } macro_rules! closed_border_el { ($name: ident, $el_name: expr) => { - pub(crate) fn $name(mut self, val: BorderType, size: usize, space: usize, color: &str) -> Self { - self.writer - .write( - XmlEvent::start_element($el_name) - .attr("w:val", &val.to_string()) - .attr("w:sz", &format!("{}", size)) - .attr("w:space", &format!("{}", space)) - .attr("w:color", color), - ) - .expect(EXPECT_MESSAGE); - self.close() + pub(crate) fn $name( + mut self, + val: BorderType, + size: usize, + space: usize, + color: &str, + ) -> Self { + self.writer + .write( + XmlEvent::start_element($el_name) + .attr("w:val", &val.to_string()) + .attr("w:sz", &format!("{}", size)) + .attr("w:space", &format!("{}", space)) + .attr("w:color", color), + ) + .expect(EXPECT_MESSAGE); + self.close() } }; } diff --git a/docx-core/tests/snapshots/lib__reader__read_textbox.snap b/docx-core/tests/snapshots/lib__reader__read_textbox.snap index f87df27..5b9276a 100644 --- a/docx-core/tests/snapshots/lib__reader__read_textbox.snap +++ b/docx-core/tests/snapshots/lib__reader__read_textbox.snap @@ -2,4 +2,4 @@ source: docx-core/tests/reader.rs expression: "&json" --- -"{\n \"contentType\": {\n \"types\": {\n \"/_rels/.rels\": \"application/vnd.openxmlformats-package.relationships+xml\",\n \"/docProps/app.xml\": \"application/vnd.openxmlformats-officedocument.extended-properties+xml\",\n \"/docProps/core.xml\": \"application/vnd.openxmlformats-package.core-properties+xml\",\n \"/word/_rels/document.xml.rels\": \"application/vnd.openxmlformats-package.relationships+xml\",\n \"/word/comments.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml\",\n \"/word/document.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml\",\n \"/word/fontTable.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml\",\n \"/word/numbering.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml\",\n \"/word/settings.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml\",\n \"/word/styles.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml\"\n }\n },\n \"rels\": {\n \"rels\": [\n [\n \"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\",\n \"rId1\",\n \"docProps/core.xml\"\n ],\n [\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties\",\n \"rId2\",\n \"docProps/app.xml\"\n ],\n [\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\",\n \"rId3\",\n \"word/document.xml\"\n ]\n ]\n },\n \"documentRels\": {\n \"hasComments\": false,\n \"hasNumberings\": false,\n \"imageIds\": []\n },\n \"docProps\": {\n \"app\": {},\n \"core\": {\n \"config\": {\n \"created\": null,\n \"creator\": null,\n \"description\": null,\n \"language\": null,\n \"lastModifiedBy\": null,\n \"modified\": null,\n \"revision\": null,\n \"subject\": null,\n \"title\": null\n }\n }\n },\n \"styles\": {\n \"docDefaults\": {\n \"runPropertyDefault\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n }\n }\n },\n \"styles\": [\n {\n \"styleId\": \"a\",\n \"name\": \"Normal\",\n \"styleType\": \"paragraph\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": \"both\",\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a0\",\n \"name\": \"Default Paragraph Font\",\n \"styleType\": \"character\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a1\",\n \"name\": \"Normal Table\",\n \"styleType\": \"table\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a2\",\n \"name\": \"No List\",\n \"styleType\": \"numbering\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n }\n ]\n },\n \"document\": {\n \"children\": [\n {\n \"type\": \"paragraph\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"drawing\",\n \"data\": {\n \"position_type\": {\n \"Inline\": {\n \"dist_t\": 0,\n \"dist_b\": 0,\n \"dist_l\": 0,\n \"dist_r\": 0\n }\n },\n \"data\": null,\n \"children\": [\n {\n \"type\": \"anchor\",\n \"data\": {\n \"children\": [\n {\n \"children\": [\n {\n \"dataType\": \"wpShape\",\n \"children\": [\n {\n \"type\": \"shape\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"textbox\",\n \"data\": {\n \"children\": [\n {\n \"children\": [\n {\n \"type\": \"paragraph\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"text\",\n \"data\": {\n \"preserveSpace\": true,\n \"text\": \"H\"\n }\n }\n ]\n }\n },\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"text\",\n \"data\": {\n \"preserveSpace\": true,\n \"text\": \"ello\"\n }\n }\n ]\n }\n }\n ],\n \"property\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n },\n \"hasNumbering\": false,\n \"attrs\": []\n }\n }\n ],\n \"has_numbering\": false\n }\n ],\n \"hasNumbering\": false\n }\n }\n ]\n }\n }\n ]\n }\n ]\n }\n ]\n }\n }\n ]\n }\n }\n ]\n }\n }\n ],\n \"property\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n },\n \"hasNumbering\": false,\n \"attrs\": []\n }\n }\n ],\n \"sectionProperty\": {\n \"pageSize\": {\n \"w\": 11906,\n \"h\": 16838\n },\n \"pageMargin\": {\n \"top\": 1985,\n \"left\": 1701,\n \"bottom\": 1701,\n \"right\": 1701,\n \"header\": 851,\n \"footer\": 992,\n \"gutter\": 0\n },\n \"columns\": 425,\n \"documentGrid\": 360\n },\n \"hasNumbering\": false\n },\n \"comments\": {\n \"comments\": []\n },\n \"numberings\": {\n \"abstractNums\": [],\n \"numberings\": []\n },\n \"settings\": {\n \"defaultTabStop\": 709,\n \"zoom\": 100\n },\n \"fontTable\": {},\n \"media\": []\n}" +"{\n \"contentType\": {\n \"types\": {\n \"/_rels/.rels\": \"application/vnd.openxmlformats-package.relationships+xml\",\n \"/docProps/app.xml\": \"application/vnd.openxmlformats-officedocument.extended-properties+xml\",\n \"/docProps/core.xml\": \"application/vnd.openxmlformats-package.core-properties+xml\",\n \"/word/_rels/document.xml.rels\": \"application/vnd.openxmlformats-package.relationships+xml\",\n \"/word/comments.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml\",\n \"/word/document.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml\",\n \"/word/fontTable.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml\",\n \"/word/numbering.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml\",\n \"/word/settings.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml\",\n \"/word/styles.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml\"\n }\n },\n \"rels\": {\n \"rels\": [\n [\n \"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\",\n \"rId1\",\n \"docProps/core.xml\"\n ],\n [\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties\",\n \"rId2\",\n \"docProps/app.xml\"\n ],\n [\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\",\n \"rId3\",\n \"word/document.xml\"\n ]\n ]\n },\n \"documentRels\": {\n \"hasComments\": false,\n \"hasNumberings\": false,\n \"imageIds\": []\n },\n \"docProps\": {\n \"app\": {},\n \"core\": {\n \"config\": {\n \"created\": null,\n \"creator\": null,\n \"description\": null,\n \"language\": null,\n \"lastModifiedBy\": null,\n \"modified\": null,\n \"revision\": null,\n \"subject\": null,\n \"title\": null\n }\n }\n },\n \"styles\": {\n \"docDefaults\": {\n \"runPropertyDefault\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n }\n }\n },\n \"styles\": [\n {\n \"styleId\": \"a\",\n \"name\": \"Normal\",\n \"styleType\": \"paragraph\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": \"both\",\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a0\",\n \"name\": \"Default Paragraph Font\",\n \"styleType\": \"character\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a1\",\n \"name\": \"Normal Table\",\n \"styleType\": \"table\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a2\",\n \"name\": \"No List\",\n \"styleType\": \"numbering\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n }\n ]\n },\n \"document\": {\n \"children\": [\n {\n \"type\": \"paragraph\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"drawing\",\n \"data\": {\n \"position_type\": {\n \"Inline\": {\n \"dist_t\": 0,\n \"dist_b\": 0,\n \"dist_l\": 0,\n \"dist_r\": 0\n }\n },\n \"position_h\": {\n \"Offset\": 0\n },\n \"position_v\": {\n \"Offset\": 0\n },\n \"data\": null,\n \"children\": [\n {\n \"type\": \"anchor\",\n \"data\": {\n \"children\": [\n {\n \"children\": [\n {\n \"dataType\": \"wpShape\",\n \"children\": [\n {\n \"type\": \"shape\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"textbox\",\n \"data\": {\n \"children\": [\n {\n \"children\": [\n {\n \"type\": \"paragraph\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"text\",\n \"data\": {\n \"preserveSpace\": true,\n \"text\": \"H\"\n }\n }\n ]\n }\n },\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"text\",\n \"data\": {\n \"preserveSpace\": true,\n \"text\": \"ello\"\n }\n }\n ]\n }\n }\n ],\n \"property\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n },\n \"hasNumbering\": false,\n \"attrs\": []\n }\n }\n ],\n \"has_numbering\": false\n }\n ],\n \"hasNumbering\": false\n }\n }\n ]\n }\n }\n ]\n }\n ]\n }\n ]\n }\n }\n ]\n }\n }\n ]\n }\n }\n ],\n \"property\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n },\n \"hasNumbering\": false,\n \"attrs\": []\n }\n }\n ],\n \"sectionProperty\": {\n \"pageSize\": {\n \"w\": 11906,\n \"h\": 16838\n },\n \"pageMargin\": {\n \"top\": 1985,\n \"left\": 1701,\n \"bottom\": 1701,\n \"right\": 1701,\n \"header\": 851,\n \"footer\": 992,\n \"gutter\": 0\n },\n \"columns\": 425,\n \"documentGrid\": 360\n },\n \"hasNumbering\": false\n },\n \"comments\": {\n \"comments\": []\n },\n \"numberings\": {\n \"abstractNums\": [],\n \"numberings\": []\n },\n \"settings\": {\n \"defaultTabStop\": 709,\n \"zoom\": 100\n },\n \"fontTable\": {},\n \"media\": []\n}" diff --git a/docx-core/tests/snapshots/reader__read_textbox.snap b/docx-core/tests/snapshots/reader__read_textbox.snap index f87df27..5b9276a 100644 --- a/docx-core/tests/snapshots/reader__read_textbox.snap +++ b/docx-core/tests/snapshots/reader__read_textbox.snap @@ -2,4 +2,4 @@ source: docx-core/tests/reader.rs expression: "&json" --- -"{\n \"contentType\": {\n \"types\": {\n \"/_rels/.rels\": \"application/vnd.openxmlformats-package.relationships+xml\",\n \"/docProps/app.xml\": \"application/vnd.openxmlformats-officedocument.extended-properties+xml\",\n \"/docProps/core.xml\": \"application/vnd.openxmlformats-package.core-properties+xml\",\n \"/word/_rels/document.xml.rels\": \"application/vnd.openxmlformats-package.relationships+xml\",\n \"/word/comments.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml\",\n \"/word/document.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml\",\n \"/word/fontTable.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml\",\n \"/word/numbering.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml\",\n \"/word/settings.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml\",\n \"/word/styles.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml\"\n }\n },\n \"rels\": {\n \"rels\": [\n [\n \"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\",\n \"rId1\",\n \"docProps/core.xml\"\n ],\n [\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties\",\n \"rId2\",\n \"docProps/app.xml\"\n ],\n [\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\",\n \"rId3\",\n \"word/document.xml\"\n ]\n ]\n },\n \"documentRels\": {\n \"hasComments\": false,\n \"hasNumberings\": false,\n \"imageIds\": []\n },\n \"docProps\": {\n \"app\": {},\n \"core\": {\n \"config\": {\n \"created\": null,\n \"creator\": null,\n \"description\": null,\n \"language\": null,\n \"lastModifiedBy\": null,\n \"modified\": null,\n \"revision\": null,\n \"subject\": null,\n \"title\": null\n }\n }\n },\n \"styles\": {\n \"docDefaults\": {\n \"runPropertyDefault\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n }\n }\n },\n \"styles\": [\n {\n \"styleId\": \"a\",\n \"name\": \"Normal\",\n \"styleType\": \"paragraph\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": \"both\",\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a0\",\n \"name\": \"Default Paragraph Font\",\n \"styleType\": \"character\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a1\",\n \"name\": \"Normal Table\",\n \"styleType\": \"table\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a2\",\n \"name\": \"No List\",\n \"styleType\": \"numbering\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n }\n ]\n },\n \"document\": {\n \"children\": [\n {\n \"type\": \"paragraph\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"drawing\",\n \"data\": {\n \"position_type\": {\n \"Inline\": {\n \"dist_t\": 0,\n \"dist_b\": 0,\n \"dist_l\": 0,\n \"dist_r\": 0\n }\n },\n \"data\": null,\n \"children\": [\n {\n \"type\": \"anchor\",\n \"data\": {\n \"children\": [\n {\n \"children\": [\n {\n \"dataType\": \"wpShape\",\n \"children\": [\n {\n \"type\": \"shape\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"textbox\",\n \"data\": {\n \"children\": [\n {\n \"children\": [\n {\n \"type\": \"paragraph\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"text\",\n \"data\": {\n \"preserveSpace\": true,\n \"text\": \"H\"\n }\n }\n ]\n }\n },\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"text\",\n \"data\": {\n \"preserveSpace\": true,\n \"text\": \"ello\"\n }\n }\n ]\n }\n }\n ],\n \"property\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n },\n \"hasNumbering\": false,\n \"attrs\": []\n }\n }\n ],\n \"has_numbering\": false\n }\n ],\n \"hasNumbering\": false\n }\n }\n ]\n }\n }\n ]\n }\n ]\n }\n ]\n }\n }\n ]\n }\n }\n ]\n }\n }\n ],\n \"property\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n },\n \"hasNumbering\": false,\n \"attrs\": []\n }\n }\n ],\n \"sectionProperty\": {\n \"pageSize\": {\n \"w\": 11906,\n \"h\": 16838\n },\n \"pageMargin\": {\n \"top\": 1985,\n \"left\": 1701,\n \"bottom\": 1701,\n \"right\": 1701,\n \"header\": 851,\n \"footer\": 992,\n \"gutter\": 0\n },\n \"columns\": 425,\n \"documentGrid\": 360\n },\n \"hasNumbering\": false\n },\n \"comments\": {\n \"comments\": []\n },\n \"numberings\": {\n \"abstractNums\": [],\n \"numberings\": []\n },\n \"settings\": {\n \"defaultTabStop\": 709,\n \"zoom\": 100\n },\n \"fontTable\": {},\n \"media\": []\n}" +"{\n \"contentType\": {\n \"types\": {\n \"/_rels/.rels\": \"application/vnd.openxmlformats-package.relationships+xml\",\n \"/docProps/app.xml\": \"application/vnd.openxmlformats-officedocument.extended-properties+xml\",\n \"/docProps/core.xml\": \"application/vnd.openxmlformats-package.core-properties+xml\",\n \"/word/_rels/document.xml.rels\": \"application/vnd.openxmlformats-package.relationships+xml\",\n \"/word/comments.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml\",\n \"/word/document.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml\",\n \"/word/fontTable.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml\",\n \"/word/numbering.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml\",\n \"/word/settings.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml\",\n \"/word/styles.xml\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml\"\n }\n },\n \"rels\": {\n \"rels\": [\n [\n \"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\",\n \"rId1\",\n \"docProps/core.xml\"\n ],\n [\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties\",\n \"rId2\",\n \"docProps/app.xml\"\n ],\n [\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\",\n \"rId3\",\n \"word/document.xml\"\n ]\n ]\n },\n \"documentRels\": {\n \"hasComments\": false,\n \"hasNumberings\": false,\n \"imageIds\": []\n },\n \"docProps\": {\n \"app\": {},\n \"core\": {\n \"config\": {\n \"created\": null,\n \"creator\": null,\n \"description\": null,\n \"language\": null,\n \"lastModifiedBy\": null,\n \"modified\": null,\n \"revision\": null,\n \"subject\": null,\n \"title\": null\n }\n }\n },\n \"styles\": {\n \"docDefaults\": {\n \"runPropertyDefault\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n }\n }\n },\n \"styles\": [\n {\n \"styleId\": \"a\",\n \"name\": \"Normal\",\n \"styleType\": \"paragraph\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": \"both\",\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a0\",\n \"name\": \"Default Paragraph Font\",\n \"styleType\": \"character\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a1\",\n \"name\": \"Normal Table\",\n \"styleType\": \"table\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n },\n {\n \"styleId\": \"a2\",\n \"name\": \"No List\",\n \"styleType\": \"numbering\",\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"paragraphProperty\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n }\n }\n ]\n },\n \"document\": {\n \"children\": [\n {\n \"type\": \"paragraph\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"drawing\",\n \"data\": {\n \"position_type\": {\n \"Inline\": {\n \"dist_t\": 0,\n \"dist_b\": 0,\n \"dist_l\": 0,\n \"dist_r\": 0\n }\n },\n \"position_h\": {\n \"Offset\": 0\n },\n \"position_v\": {\n \"Offset\": 0\n },\n \"data\": null,\n \"children\": [\n {\n \"type\": \"anchor\",\n \"data\": {\n \"children\": [\n {\n \"children\": [\n {\n \"dataType\": \"wpShape\",\n \"children\": [\n {\n \"type\": \"shape\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"textbox\",\n \"data\": {\n \"children\": [\n {\n \"children\": [\n {\n \"type\": \"paragraph\",\n \"data\": {\n \"children\": [\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"text\",\n \"data\": {\n \"preserveSpace\": true,\n \"text\": \"H\"\n }\n }\n ]\n }\n },\n {\n \"type\": \"run\",\n \"data\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"children\": [\n {\n \"type\": \"text\",\n \"data\": {\n \"preserveSpace\": true,\n \"text\": \"ello\"\n }\n }\n ]\n }\n }\n ],\n \"property\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n },\n \"hasNumbering\": false,\n \"attrs\": []\n }\n }\n ],\n \"has_numbering\": false\n }\n ],\n \"hasNumbering\": false\n }\n }\n ]\n }\n }\n ]\n }\n ]\n }\n ]\n }\n }\n ]\n }\n }\n ]\n }\n }\n ],\n \"property\": {\n \"runProperty\": {\n \"sz\": null,\n \"szCs\": null,\n \"color\": null,\n \"highlight\": null,\n \"underline\": null,\n \"bold\": null,\n \"boldCs\": null,\n \"italic\": null,\n \"italicCs\": null,\n \"vanish\": null\n },\n \"style\": null,\n \"numberingProperty\": null,\n \"alignment\": null,\n \"indent\": null\n },\n \"hasNumbering\": false,\n \"attrs\": []\n }\n }\n ],\n \"sectionProperty\": {\n \"pageSize\": {\n \"w\": 11906,\n \"h\": 16838\n },\n \"pageMargin\": {\n \"top\": 1985,\n \"left\": 1701,\n \"bottom\": 1701,\n \"right\": 1701,\n \"header\": 851,\n \"footer\": 992,\n \"gutter\": 0\n },\n \"columns\": 425,\n \"documentGrid\": 360\n },\n \"hasNumbering\": false\n },\n \"comments\": {\n \"comments\": []\n },\n \"numberings\": {\n \"abstractNums\": [],\n \"numberings\": []\n },\n \"settings\": {\n \"defaultTabStop\": 709,\n \"zoom\": 100\n },\n \"fontTable\": {},\n \"media\": []\n}" diff --git a/fixtures/image_node_docx_relative/word/document.xml b/fixtures/image_node_docx_relative/word/document.xml index c9d76ec..ceafb8f 100644 --- a/fixtures/image_node_docx_relative/word/document.xml +++ b/fixtures/image_node_docx_relative/word/document.xml @@ -21,7 +21,7 @@ - right + 2014400 bottom