DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
rustfmt
moppeeere8b27c91f116
diff --git a/crates/engine/src/cmd/package/tests.rs b/crates/engine/src/cmd/package/tests.rsindex 124ea19c4..4d6513425 100644--- a/crates/engine/src/cmd/package/tests.rs+++ b/crates/engine/src/cmd/package/tests.rs@@ -25,57 +25,57 @@ fn relocated_packages_rebind_embedded_image_links_on_open() {std::fs::remove_dir_all(dir).unwrap();}- /// `pdf` takes file.exportPdf's options (a PDF preset's): a PDF/X-4 package PDF; `true` is the- /// default PDF, and bad options are refused.- #[test]- fn package_pdf_takes_export_options() {- let nonce = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();- let dir = std::env::temp_dir().join(format!("dc-package-pdf-options-{}-{nonce}", std::process::id()));- let mut s = Session::new();- s.execute("file.new", &json!({"title": "Options", "width": 72, "height": 72})).unwrap();- let x4 = dir.join("x4");- s.execute("file.package", &json!({"dir": x4.to_string_lossy(), "idml": false, "pdf": {"standard": "x4"}})).unwrap();- let has = |path: &std::path::Path, what: &[u8]| std::fs::read(path).unwrap().windows(what.len()).any(|w| w == what);- assert!(has(&x4.join("Options.pdf"), b"GTS_PDFX"));- let plain = dir.join("plain");- s.execute("file.package", &json!({"dir": plain.to_string_lossy(), "idml": false, "pdf": true})).unwrap();- assert!(!has(&plain.join("Options.pdf"), b"GTS_PDFX"));- // Refused before anything is written: bad options, a bad flattener or view option, and a- // `pdf` that is neither a switch nor options.- for bad in [- json!({"standard": "nope"}),- json!({"flatten": "extreme"}),- json!({"pageLayout": "spiral"}),- json!({"view": "zoomed"}),- json!("print"),- json!(3),- ] {- let out = dir.join("bad");- assert!(s.execute("file.package", &json!({"dir": out.to_string_lossy(), "pdf": bad})).is_err(), "{bad}");- assert!(!out.exists(), "{bad}: bad options write nothing");- }- std::fs::remove_dir_all(dir).unwrap();+/// `pdf` takes file.exportPdf's options (a PDF preset's): a PDF/X-4 package PDF; `true` is the+/// default PDF, and bad options are refused.+#[test]+fn package_pdf_takes_export_options() {+ let nonce = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();+ let dir = std::env::temp_dir().join(format!("dc-package-pdf-options-{}-{nonce}", std::process::id()));+ let mut s = Session::new();+ s.execute("file.new", &json!({"title": "Options", "width": 72, "height": 72})).unwrap();+ let x4 = dir.join("x4");+ s.execute("file.package", &json!({"dir": x4.to_string_lossy(), "idml": false, "pdf": {"standard": "x4"}})).unwrap();+ let has = |path: &std::path::Path, what: &[u8]| std::fs::read(path).unwrap().windows(what.len()).any(|w| w == what);+ assert!(has(&x4.join("Options.pdf"), b"GTS_PDFX"));+ let plain = dir.join("plain");+ s.execute("file.package", &json!({"dir": plain.to_string_lossy(), "idml": false, "pdf": true})).unwrap();+ assert!(!has(&plain.join("Options.pdf"), b"GTS_PDFX"));+ // Refused before anything is written: bad options, a bad flattener or view option, and a+ // `pdf` that is neither a switch nor options.+ for bad in [+ json!({"standard": "nope"}),+ json!({"flatten": "extreme"}),+ json!({"pageLayout": "spiral"}),+ json!({"view": "zoomed"}),+ json!("print"),+ json!(3),+ ] {+ let out = dir.join("bad");+ assert!(s.execute("file.package", &json!({"dir": out.to_string_lossy(), "pdf": bad})).is_err(), "{bad}");+ assert!(!out.exists(), "{bad}: bad options write nothing");}+ std::fs::remove_dir_all(dir).unwrap();+}- /// A preset that flattens transparency (Screen and Email's `flatten: low`) gives the packaged- /// PDF the flattening `file.exportPdf` does.- #[test]- fn the_packaged_pdf_is_flattened_as_export_flattens_it() {- let nonce = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();- let dir = std::env::temp_dir().join(format!("dc-package-pdf-flatten-{}-{nonce}", std::process::id()));- let mut s = Session::new();- s.execute("file.new", &json!({"title": "Flat", "width": 144, "height": 144})).unwrap();- let id = s.execute("frame.create", &json!({"rect": [10, 10, 100, 100], "content": "unassigned"})).unwrap()["id"].clone();- s.execute("object.fill", &json!({"ids": [id], "swatch": "[Black]"})).unwrap();- s.execute("object.opacity", &json!({"ids": [id], "opacity": 0.5})).unwrap();- let exported = super::super::base64_decode(s.execute("file.exportPdf", &json!({"flatten": "low"})).unwrap()["base64"].as_str().unwrap());- s.execute("file.package", &json!({"dir": dir.to_string_lossy(), "idml": false, "pdf": {"flatten": "low"}})).unwrap();- let packaged = std::fs::read(dir.join("Flat.pdf")).unwrap();- let images = |pdf: &[u8]| pdf.windows(b"/Subtype/Image".len()).filter(|w| *w == b"/Subtype/Image").count();- assert!(images(&exported) > 0, "the export rasterises the transparent object");- assert_eq!(images(&packaged), images(&exported), "so does the package");- std::fs::remove_dir_all(dir).unwrap();- }+/// A preset that flattens transparency (Screen and Email's `flatten: low`) gives the packaged+/// PDF the flattening `file.exportPdf` does.+#[test]+fn the_packaged_pdf_is_flattened_as_export_flattens_it() {+ let nonce = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();+ let dir = std::env::temp_dir().join(format!("dc-package-pdf-flatten-{}-{nonce}", std::process::id()));+ let mut s = Session::new();+ s.execute("file.new", &json!({"title": "Flat", "width": 144, "height": 144})).unwrap();+ let id = s.execute("frame.create", &json!({"rect": [10, 10, 100, 100], "content": "unassigned"})).unwrap()["id"].clone();+ s.execute("object.fill", &json!({"ids": [id], "swatch": "[Black]"})).unwrap();+ s.execute("object.opacity", &json!({"ids": [id], "opacity": 0.5})).unwrap();+ let exported = super::super::base64_decode(s.execute("file.exportPdf", &json!({"flatten": "low"})).unwrap()["base64"].as_str().unwrap());+ s.execute("file.package", &json!({"dir": dir.to_string_lossy(), "idml": false, "pdf": {"flatten": "low"}})).unwrap();+ let packaged = std::fs::read(dir.join("Flat.pdf")).unwrap();+ let images = |pdf: &[u8]| pdf.windows(b"/Subtype/Image".len()).filter(|w| *w == b"/Subtype/Image").count();+ assert!(images(&exported) > 0, "the export rasterises the transparent object");+ assert_eq!(images(&packaged), images(&exported), "so does the package");+ std::fs::remove_dir_all(dir).unwrap();+}/// A per-placement PDF layer choice cannot travel in an IDML copy that links its files, so the/// report says the copies differ instead of leaving it to be discovered.@@ -221,7 +221,7 @@ fn package_writes_document_links_and_report() {assert!(out.join("Links").join("logo.svg").exists());let report = std::fs::read_to_string(out.join("Instructions.txt")).unwrap();assert!(report.contains("Print on matte.") && report.contains("logo.svg"), "{report}");- assert!(report.find("Print on matte.") < report.find("Package report:"), "the instructions come first: {report}");+ assert!(report.find("Print on matte.") < report.find("Package report:"), "the instructions come first: {report}");assert!(report.contains("Preflight:"), "{report}");// The packaged document links to its Links folder.let doc_file = files.iter().find(|f| f.ends_with(".designcraft")).unwrap();