//! #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`. #![cfg(not(target_arch = "wasm32"))] use std::io::{Read, Write}; 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 = zip::ZipWriter::new(std::io::Cursor::new(Vec::new())); let o = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored); for (name, data) in [("mimetype", "application/vnd.oasis.opendocument.text"), ("content.xml", &content), ("styles.xml", &styles)] { z.start_file(name, o).unwrap(); z.write_all(data.as_bytes()).unwrap(); } z.finish().unwrap().into_inner() } fn document_xml(docx: &[u8]) -> String { let mut zip = zip::ZipArchive::new(std::io::Cursor::new(docx)).unwrap(); let mut xml = String::new(); zip.by_name("word/document.xml").unwrap().read_to_string(&mut xml).unwrap(); xml } #[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]); }