From b16cd326593703c2964a98d48e967973cfb8530a Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Tue, 10 Nov 2026 20:03:14 +0100 Subject: [PATCH] Print: a printer's remembered paper wins over its driver's default paper (#6906) #5861 (#6100) reads the chosen printer's papers and default paper in the background, and the default replaces the dialog's paper unless it was chosen in the dialog (paper_overridden). The paper a printer's setup restores (#2001, #6779) didn't count as chosen, so on Windows the driver's default replaced it each time the dialog opened: an office printer last printed on A3 came back on A4. apply_setup now marks the paper it restores as chosen. A test drives the dialog with a printer remembered on A3 whose driver's default is A4. --- .../ui-egui/src/workflows/print_ui/draft.rs | 3 ++ crates/ui-egui/tests/it/print.rs | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/crates/ui-egui/src/workflows/print_ui/draft.rs b/crates/ui-egui/src/workflows/print_ui/draft.rs index ced55e7a25..2b661426a6 100644 --- a/crates/ui-egui/src/workflows/print_ui/draft.rs +++ b/crates/ui-egui/src/workflows/print_ui/draft.rs @@ -421,6 +421,9 @@ impl PrintDraft { } else { self.paper = paper; } + // The paper this printer was last printed on is a choice, as one made in the dialog: + // the driver's default paper, read in the background (#5861), must not replace it. + self.paper_overridden = true; } self.sheet = 0; } diff --git a/crates/ui-egui/tests/it/print.rs b/crates/ui-egui/tests/it/print.rs index ca8c8b5592..87d77a7eaa 100644 --- a/crates/ui-egui/tests/it/print.rs +++ b/crates/ui-egui/tests/it/print.rs @@ -1221,6 +1221,34 @@ fn cached_papers_apply_immediately_and_refresh_in_background() { assert_eq!(calls.load(Ordering::SeqCst), 2); } +/// #2001 with #5861: a printer keeps the paper it was last printed on (A3 here) when its driver's +/// default paper (A4) arrives from the background read afterwards; before, the default replaced +/// the remembered paper each time the dialog opened. +#[test] +fn a_printers_remembered_paper_wins_over_its_drivers_default() { + use pdfcraft_engine::print::{SizeMode, spool}; + use pdfcraft_ui_egui::PrinterSetup; + use std::sync::Arc; + + let mut h = harness(); + h.state_mut().printer_source = + Some(Arc::new(|| vec![spool::Printer { name: "Office".into(), default: true, two_sided: None, description: String::new() }])); + h.state_mut().printer_papers_source = Some(Arc::new(|_| vec![("A4".into(), (595.28, 841.89)), ("A3".into(), (841.89, 1190.55))])); + h.state_mut().default_paper_source = Some(Arc::new(|_| Some(("A4".into(), (595.28, 841.89))))); + let setup = PrinterSetup { paper: "A3".into(), size: SizeMode::Fit, custom_scale: 100.0, duplex: None }; + h.state_mut().print_draft.setups = vec![("Office".into(), setup)]; + + assert!(h.state_mut().execute("print.dialog")); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10); + while (h.state().print_draft.printers_loading || h.state().print_draft.papers_loading.is_some()) && std::time::Instant::now() < deadline { + h.run_steps(1); + std::thread::sleep(std::time::Duration::from_millis(5)); + } + h.run_steps(4); + assert_eq!(h.state().print_draft.printer.as_deref(), Some("Office")); + assert_eq!(h.state().print_draft.paper_name(), "A3", "the remembered paper, not the driver's default"); +} + #[test] fn uncached_printer_switch_resets_driver_papers_to_standard_presets() { use pdfcraft_engine::print::spool;