//! #1379: an ODT file with several page styles and a column section converts to DOCX with one //! `w:sectPr` per section. The ODT is original and synthetic, built from ODF 1.3: paragraphs //! whose automatic styles name a master page (`style:master-page-name`), one restarting page //! numbering (`style:page-number`), and a two-column `text:section`. use wordcraft_engine::io; const NS: &str = r#"xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0""#; fn odt() -> Vec { let styles = format!( r#" "# ); let content = format!( r#" Annual summaryOpening text of the first part. Volumes table AB Column text one.Column text two. Closing wordsLast line. "# ); let mut z = craft_zip::Writer::new(); for (name, data) in [("mimetype", "application/vnd.oasis.opendocument.text"), ("content.xml", &content), ("styles.xml", &styles)] { z.add(name, data.as_bytes(), craft_zip::Compression::Stored).unwrap(); } z.finish().unwrap() } fn document_xml(docx: &[u8]) -> String { let mut zip = craft_zip::Archive::open(docx, craft_zip::Limits { max_entries: 10_000, max_total_bytes: 64 << 20 }).unwrap(); String::from_utf8(zip.read("word/document.xml", 16 << 20).unwrap().unwrap()).unwrap() } #[test] fn odt_sections_convert_to_one_docx_section_each() { let doc = io::open_bytes("sections.odt", &odt()).unwrap(); assert_eq!(doc.sections().len(), 4); let xml = document_xml(&io::save_bytes("sections.docx", &doc).unwrap()); let secs: Vec<&str> = xml.split("").next().unwrap_or("")).collect(); assert_eq!(secs.len(), 4, "{xml}"); let orient: Vec = secs.iter().map(|s| s.contains(r#"w:orient="landscape""#)).collect(); assert_eq!(orient, [false, true, true, false]); // A4 both ways. assert!(secs[0].contains(r#"w:w="11906""#) && secs[0].contains(r#"w:h="16838""#), "{}", secs[0]); assert!(secs[1].contains(r#"w:w="16838""#) && secs[1].contains(r#"w:h="11906""#), "{}", secs[1]); // Section 3: continuous, two columns with a line between; the others one column. assert!(secs[2].contains(r#" = secs.iter().map(|s| s.contains(r#"w:start="1""#)).collect(); assert_eq!(restarts, [false, true, false, true]); }