Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Print: restore the winsafe dependency, the DLL check and its tests lost in merges (#5884)

Higgs32584eeeeb13f0ea1
diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml
index fb3bc3fbe..6b710eab9 100644
--- a/crates/engine/Cargo.toml
+++ b/crates/engine/Cargo.toml
@@ -47,6 +47,9 @@ tempfile = "3"
# file is that file (std's `MetadataExt::file_index` is unstable).
[target.'cfg(windows)'.dependencies]
same-file = "1"
+# `file.print` loads Windows.Data.Pdf.dll before calling into it (#5884): the safe binding
+# ui-egui and craft-print already use, pinned to the same version.
+winsafe = { version = "=0.0.29", default-features = false, features = ["kernel"] }
# Printing on Unix: an IPP client for CUPS (pure Rust); the web build cannot print.
[target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "windows")))'.dependencies]
diff --git a/crates/engine/src/print_cmds.rs b/crates/engine/src/print_cmds.rs
index 9d8419541..e657a6052 100644
--- a/crates/engine/src/print_cmds.rs
+++ b/crates/engine/src/print_cmds.rs
@@ -90,6 +90,7 @@ fn spool_job(spooler: Option<&Spooler>, job: &PrintJob, lp: &craft_print::Job) -
return app(sp);
}
if let Some(name) = system_spooler() {
+ require_windows_pdf()?;
return craft_print::submit(&job.pdf, lp).map(|m| (m, name.to_string())).map_err(other);
}
}
diff --git a/crates/engine/src/print_cmds/tests.rs b/crates/engine/src/print_cmds/tests.rs
index c54dddf6f..2b0f71bc1 100644
--- a/crates/engine/src/print_cmds/tests.rs
+++ b/crates/engine/src/print_cmds/tests.rs
@@ -772,3 +772,29 @@ mod cups {
assert_eq!(jobs, 2, "both prints reached the fake CUPS");
}
}
+
+#[cfg(target_os = "windows")]
+#[test]
+fn windows_pdf_component_is_detected_by_loading_its_dll() {
+ // #5884: a Windows image without a loadable Windows.Data.Pdf.dll reports an error instead of
+ // aborting at the delay-load stub.
+ let dir = tempfile::tempdir().unwrap();
+ let dll = windows_pdf_dll(dir.path());
+ assert!(!windows_pdf_loads(&dll));
+ // Present but not loadable counts as missing.
+ std::fs::create_dir(dir.path().join("System32")).unwrap();
+ std::fs::write(&dll, b"MZ").unwrap();
+ assert!(!windows_pdf_loads(&dll));
+ let root = std::env::var_os("SystemRoot").unwrap();
+ let system = windows_pdf_dll(std::path::Path::new(&root));
+ if system.is_file() {
+ assert!(windows_pdf_loads(&system));
+ assert!(require_windows_pdf().is_ok());
+ }
+}
+
+#[cfg(not(target_os = "windows"))]
+#[test]
+fn the_windows_pdf_check_is_a_no_op_elsewhere() {
+ assert!(require_windows_pdf().is_ok());
+}