From 5f042c691f3456cd7c601db782a3b5a54b861cfd Mon Sep 17 00:00:00 2001 From: Juan Jurado Date: Thu, 22 Oct 2026 16:45:39 -0600 Subject: [PATCH 1/3] M10: every paper size reaches the printer, from the dialog and doc_print (#3752) A CUPS job that names no paper gets the queue's PPD default (A4 on the reporter's Xerox queue), whatever the sheets were laid out on. Two gaps remained after #1583: - cups_media had no name for 13 of the 21 PAPERS sizes (A6, ARCH A-E1, ANSI C-E, A0-A2), so the Print dialog sent no media for them. They now use PWG 5101.1 names (the IANA-registered na_arch-e1_30x42in for ARCH E1), which carry their dimensions: CUPS feeds the driver's size of those dimensions whatever the driver calls it, and driverless IPP printers use them natively. Checked with cupsfilter against a synthetic PPD whose sizes use vendor keywords (ARCHD, AnsiD, A0...): each name produced its size's bounding box. The 8 sizes that already worked keep their PPD keywords. - doc_print to a printer (CLI run, MCP) sent no paper at all. It now resolves the paper to its PAPERS index and sends the same media option as the dialog, after the driver options. The job is built in spool_job so it can be tested without printing. print::media_option is the one place both get the option from. Both new tests were seen failing without the fix. The macOS tray half of #3752 (Auto Select instead of the PPD's default tray) is a craft-print change. --- ROADMAP.md | 1 + crates/automation/src/printing.rs | 111 ++++++++++++++++++++---------- crates/print/src/lib.rs | 50 ++++++++++---- crates/print/src/tests.rs | 28 ++++++++ crates/ui-egui/src/print_ui.rs | 2 +- parity/acrobat-features.toml | 4 +- 6 files changed, 145 insertions(+), 51 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 27c8e1b6bb..ac34f9ae00 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -190,6 +190,7 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md | 8 | 1.0 polish: performance, right-to-left, missing languages, keyboard-only (M14) | 55–95 | ## Progress log +- **2026-10-22 (M10, #3752 paper):** CUPS jobs ask for the chosen paper in every size. The 13 sizes the Print dialog sent no paper for (A6, A0–A2, ARCH, ANSI C–E) use PWG 5101.1 names, checked against a synthetic PPD with `cupsfilter`, and `doc_print` to a printer sends the paper too. The macOS tray half (Auto Select instead of the PPD's default tray) is a craft-print change that needs a pin bump here. Estimates unchanged. - **2026-10-22 (M14, macOS association recovery candidate):** Successful desktop open/save/sign can queue recovery of an existing per-file binding to the running PDFCraft bundle through NSWorkspace. Metadata-only watcher changes retain undo and avoid false overwrite prompts; real same-length/same-mtime edits remain protected. Rebased on 0.12.0 and reuses #3042's shared atomic metadata preservation; the bounded recovery parser does not narrow save limits. Prior native Preview TEST-signature and Finder workflows passed on macOS 27.0.1; other versions remain unqualified. Estimates unchanged. - **2026-10-13 (M7, free image rotation):** A selected page image has a rotate knob (Shift: 15 degree steps) and `image_edit` a `rotate_by` action; the angle is written as one undoable `cm`. Snapping to page edges while moving is in #1740; resize snapping is not done. Estimates unchanged. diff --git a/crates/automation/src/printing.rs b/crates/automation/src/printing.rs index 39cd45760e..e43c3c6e9f 100644 --- a/crates/automation/src/printing.rs +++ b/crates/automation/src/printing.rs @@ -26,6 +26,54 @@ fn bad(m: impl Into) -> ToolError { ToolError::InvalidArgs(m.into()) } +/// `doc_print`'s `paper`, by its name or a short form ("Letter", "ARCH D"), as its `PAPERS` +/// index and size; US Letter when none is given. +fn paper_named(name: Option<&str>) -> Result<(usize, (f64, f64))> { + let mut papers = PAPERS.iter().enumerate(); + let found = match name { + None => papers.next(), + Some(p) => papers.find(|(_, (n, _))| { + n.eq_ignore_ascii_case(p) + || n.replace("US ", "").eq_ignore_ascii_case(p) + || n.split(" (").next().is_some_and(|name| name.eq_ignore_ascii_case(p)) + }), + }; + found.map(|(index, (_, size))| (index, *size)).ok_or_else(|| { + bad(format!( + "unknown paper {:?}; choose one of {}", + name.unwrap_or_default(), + PAPERS.iter().map(|(name, _)| *name).collect::>().join(", ") + )) + }) +} + +/// The spooler job for `doc_print` to `printer`. It feeds the paper the PDF was laid out on +/// (`PAPERS[paper]`, as `media` after the driver's `options`) rather than the queue's default +/// paper, which a job naming none got (A4 under Letter sheets on the queue in #3752). +fn spool_job(a: &Args, printer: &str, title: String, duplex: Option, paper: usize) -> Result { + let options = match a.get("options") { + None => Vec::new(), + Some(Value::Object(m)) => m + .iter() + .map(|(k, v)| match v.as_str() { + Some(v) => Ok((k.clone(), v.to_string())), + None => Err(bad(format!("options.{k} must be a string (a choice from printer_options)"))), + }) + .collect::>>()?, + Some(_) => return Err(bad("options must be an object of option keys and choices from printer_options")), + }; + Ok(spool::Job { + printer: if printer == "default" { None } else { Some(printer.to_string()) }, + copies: a.opt_int("copies")?.unwrap_or(1).clamp(1, 999) as u32, + collate: a.opt_bool("collate")?.unwrap_or(true), + duplex, + scaling: spool::Scaling::Exact, + grayscale: a.opt_bool("grayscale")?.unwrap_or(false), + title, + options: options.into_iter().chain(print::media_option(paper)).collect(), + }) +} + impl Automation { pub(crate) fn printers(&self) -> Result { let list: Vec = spool::printers() @@ -125,20 +173,7 @@ impl Automation { "form-fields-only" => Content::FormFieldsOnly, c => return Err(bad(format!("unknown comments_forms {c:?}"))), }; - let paper = match a.opt_str("paper")? { - None => PAPERS[0].1, - Some(p) => PAPERS - .iter() - .find(|(n, _)| { - n.eq_ignore_ascii_case(p) - || n.replace("US ", "").eq_ignore_ascii_case(p) - || n.split(" (").next().is_some_and(|name| name.eq_ignore_ascii_case(p)) - }) - .map(|x| x.1) - .ok_or_else(|| { - bad(format!("unknown paper {p:?}; choose one of {}", PAPERS.iter().map(|(name, _)| *name).collect::>().join(", "))) - })?, - }; + let (paper_index, paper) = paper_named(a.opt_str("paper")?)?; // Print as image (Acrobat's Advanced Print Setup): pictures at `dpi`, grey when // `grayscale` is also asked for. let raster = if a.opt_bool("as_image")?.unwrap_or(false) { @@ -162,27 +197,7 @@ impl Automation { out["path"] = json!(path.to_string_lossy()); } (None, Some(printer)) => { - let name = self.doc(a)?.name.clone(); - let job = spool::Job { - printer: if printer == "default" { None } else { Some(printer.to_string()) }, - copies: a.opt_int("copies")?.unwrap_or(1).clamp(1, 999) as u32, - collate: a.opt_bool("collate")?.unwrap_or(true), - duplex, - scaling: spool::Scaling::Exact, - grayscale: a.opt_bool("grayscale")?.unwrap_or(false), - title: name, - options: match a.get("options") { - None => Vec::new(), - Some(Value::Object(m)) => m - .iter() - .map(|(k, v)| match v.as_str() { - Some(v) => Ok((k.clone(), v.to_string())), - None => Err(bad(format!("options.{k} must be a string (a choice from printer_options)"))), - }) - .collect::>>()?, - Some(_) => return Err(bad("options must be an object of option keys and choices from printer_options")), - }, - }; + let job = spool_job(a, printer, self.doc(a)?.name.clone(), duplex, paper_index)?; out["job"] = json!(spool::submit(&bytes, &job).map_err(|e| failed(e.to_string()))?); } _ => return Err(bad("pass either path (save the print-ready PDF) or printer (a name from printers, or \"default\")")), @@ -207,4 +222,30 @@ mod tests { assert!(duplex("long-edge", true).is_err()); assert!(duplex("sideways", false).is_err()); } + + /// #3752: `doc_print` to a printer sent no paper, so the queue's default paper stood in for + /// the one the sheets were laid out on (A4 under Letter sheets on the report's queue). + #[test] + fn printing_to_a_printer_feeds_the_laid_out_paper() { + let job = |args: Value, paper_name: Option<&str>| { + let (index, _) = paper_named(paper_name).unwrap(); + spool_job(&Args(&args), "Office", "a.pdf".into(), None, index).unwrap() + }; + let media = |m: &str| ("media".to_string(), m.to_string()); + // US Letter when no paper is asked for, after the driver's own options. + let letter = job(json!({ "options": { "InputSlot": "Tray3" } }), None); + assert_eq!(letter.options, [("InputSlot".to_string(), "Tray3".to_string()), media("Letter")]); + assert_eq!((letter.printer.as_deref(), letter.title.as_str()), (Some("Office"), "a.pdf")); + // Every paper, by its full name, goes out as its own media name. + for (i, (name, size)) in PAPERS.iter().enumerate() { + assert_eq!(paper_named(Some(name)).ok(), Some((i, *size)), "{name}"); + assert_eq!(job(json!({}), Some(name)).options, print::media_option(i).into_iter().collect::>(), "{name}"); + } + // Short forms find the same paper. + assert_eq!(job(json!({}), Some("letter")).options, [media("Letter")]); + assert_eq!(job(json!({}), Some("ARCH D")).options, [media("arch_d_24x36in")]); + assert!(matches!(paper_named(Some("Quarto")), Err(ToolError::InvalidArgs(m)) if m.contains("US Letter"))); + assert_eq!(spool_job(&Args(&json!({})), "default", String::new(), None, 0).ok().map(|j| j.printer), Some(None)); + assert!(spool_job(&Args(&json!({ "options": { "InputSlot": 3 } })), "Office", String::new(), None, 0).is_err()); + } } diff --git a/crates/print/src/lib.rs b/crates/print/src/lib.rs index 6839e5f6b0..80b7be27aa 100644 --- a/crates/print/src/lib.rs +++ b/crates/print/src/lib.rs @@ -307,20 +307,44 @@ pub const PAPERS: [(&str, (f64, f64)); 21] = [ pub const LABEL_PAPER: usize = 19; /// The CUPS media name for `PAPERS[index]`, so the spooler feeds the sheet the PDF was laid out -/// on rather than the queue's default (PPD keywords; `w288h432` is the usual 4×6 label, `Env10` -/// the US #10 envelope). +/// on rather than the queue's default; `None` only past the end of `PAPERS`. The common sizes +/// use their PPD keywords (`w288h432` is the usual 4×6 label, `Env10` the US #10 envelope). +/// The rest use PWG 5101.1 names (the IANA registry for ARCH E1), which carry their dimensions: +/// CUPS feeds the PPD size of those dimensions whatever the driver calls it (`ARCHD`, `AnsiD`), +/// and driverless IPP printers use these names themselves (#3752). pub fn cups_media(index: usize) -> Option<&'static str> { - match PAPERS.get(index)?.0 { - "US Letter" => Some("Letter"), - "US Legal" => Some("Legal"), - "Tabloid" => Some("Tabloid"), - "A3" => Some("A3"), - "A4" => Some("A4"), - "A5" => Some("A5"), - "US #10 Envelope (4.125 x 9.5 in)" => Some("Env10"), - _ if index == LABEL_PAPER => Some("w288h432"), - _ => None, - } + Some(match PAPERS.get(index)?.0 { + "US Letter" => "Letter", + "US Legal" => "Legal", + "Tabloid" => "Tabloid", + "A3" => "A3", + "A4" => "A4", + "A5" => "A5", + "A6" => "iso_a6_105x148mm", + "ARCH A (9 x 12 in)" => "arch_a_9x12in", + "ARCH B (12 x 18 in)" => "arch_b_12x18in", + "ARCH C (18 x 24 in)" => "arch_c_18x24in", + "ARCH D (24 x 36 in)" => "arch_d_24x36in", + "ARCH E1 (30 x 42 in)" => "na_arch-e1_30x42in", + "ARCH E (36 x 48 in)" => "arch_e_36x48in", + "ANSI C (17 x 22 in)" => "na_c_17x22in", + "ANSI D (22 x 34 in)" => "na_d_22x34in", + "ANSI E (34 x 44 in)" => "na_e_34x44in", + "A2" => "iso_a2_420x594mm", + "A1" => "iso_a1_594x841mm", + "A0" => "iso_a0_841x1189mm", + "US #10 Envelope (4.125 x 9.5 in)" => "Env10", + _ if index == LABEL_PAPER => "w288h432", + // A size added to PAPERS without a name here: its tests fail, and meanwhile the queue's + // paper stands, as it did for every size before #1583. + _ => return None, + }) +} + +/// The job option that feeds `PAPERS[index]` (`media`, see [`cups_media`]), for the Print +/// dialog's jobs and `doc_print`'s alike. +pub fn media_option(index: usize) -> Option<(String, String)> { + cups_media(index).map(|m| ("media".to_string(), m.to_string())) } /// Whether most of page `index`'s text runs bottom-to-top as the page displays (a label laid diff --git a/crates/print/src/tests.rs b/crates/print/src/tests.rs index 99634f1aa1..a17adef15f 100644 --- a/crates/print/src/tests.rs +++ b/crates/print/src/tests.rs @@ -674,6 +674,34 @@ fn paper_matching_accepts_rounded_metric_sizes_but_not_custom_or_invalid_sizes() } } +#[test] +fn every_paper_reaches_the_spooler_by_a_name_of_its_size() { + // #3752: 13 of the 21 sizes had no media name, so their jobs went out on the queue's default + // paper (A4 on the report's queue) whatever the sheets were laid out on. + let ppd_keywords = ["Letter", "Legal", "Tabloid", "A3", "A4", "A5", "w288h432", "Env10"]; + for (i, (name, (w, h))) in PAPERS.iter().enumerate() { + let media = cups_media(i).unwrap_or_else(|| panic!("{name} has no media name")); + assert_eq!(media_option(i), Some(("media".to_string(), media.to_string()))); + let args = lp_args(&Job { options: media_option(i).into_iter().collect(), ..Job::default() }); + assert!(args.contains(&format!("media={media}")), "{name}: lp is given it: {args:?}"); + if ppd_keywords.contains(&media) { + continue; + } + // The rest are PWG 5101.1 names, which end in their dimensions: CUPS feeds the driver's + // size of those dimensions, so they must be the paper's. + let dims = media.rsplit('_').next().unwrap_or_default(); + let (dims, points_per_unit) = match (dims.strip_suffix("mm"), dims.strip_suffix("in")) { + (Some(mm), _) => (mm, 72.0 / 25.4), + (_, Some(inches)) => (inches, 72.0), + _ => panic!("{name}: {media} is not a PWG name"), + }; + let (pw, ph) = dims.split_once('x').unwrap_or_else(|| panic!("{name}: {media} has no dimensions")); + let (pw, ph) = (pw.parse::().unwrap() * points_per_unit, ph.parse::().unwrap() * points_per_unit); + assert!((pw - w).abs() < 0.5 && (ph - h).abs() < 0.5, "{name}: {media} is {pw:.2} x {ph:.2} pt, not {w} x {h}"); + } + assert_eq!((cups_media(PAPERS.len()), media_option(PAPERS.len())), (None, None)); +} + #[test] fn us_number_10_envelope_is_offered_and_fed_by_name() { // 4.125 × 9.5 in (#2734). diff --git a/crates/ui-egui/src/print_ui.rs b/crates/ui-egui/src/print_ui.rs index cab6bfc236..d5d95c881b 100644 --- a/crates/ui-egui/src/print_ui.rs +++ b/crates/ui-egui/src/print_ui.rs @@ -240,7 +240,7 @@ impl PrintDraft { } .into_iter() // The sheet the PDF was laid out on, not the queue's default paper. - .chain(print::cups_media(self.paper).map(|m| ("media".to_string(), m.to_string()))) + .chain(print::media_option(self.paper)) .collect(), } } diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 45dda39822..fc56e5f4e4 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -7965,8 +7965,8 @@ milestone = "M10" status = "shipped" commands = ["print.dialog"] tools = ["doc_print", "printers"] -evidence = ["crates/ui-egui/tests/it/print.rs::paper_choice_survives_cancel_and_settings_restore", "crates/ui-egui/tests/it/print.rs::restored_paper_keeps_preview_and_saved_sheet_dimensions", "crates/ui-egui/tests/it/print.rs::print_dialog_lays_out_sheets_and_saves_a_pdf", "crates/engine/src/tests.rs::printing_lays_out_sheets_that_render", "crates/ui-egui/src/web_print.rs::a_job_draws_every_sheet_at_its_planned_resolution_then_builds_the_page", "crates/ui-egui/src/web_print.rs::the_print_page_turns_sideways_sheets_names_other_sizes_and_ends_without_a_blank_page"] -notes = "⌘P; settings and live sheet preview; on the web the same dialog prints through the browser's print dialog; last paper selection, including cancelled Print dialogs, persists by canonical name; this change does not alter persistence of other print preferences" +evidence = ["crates/ui-egui/tests/it/print.rs::paper_choice_survives_cancel_and_settings_restore", "crates/ui-egui/tests/it/print.rs::restored_paper_keeps_preview_and_saved_sheet_dimensions", "crates/ui-egui/tests/it/print.rs::print_dialog_lays_out_sheets_and_saves_a_pdf", "crates/engine/src/tests.rs::printing_lays_out_sheets_that_render", "crates/ui-egui/src/web_print.rs::a_job_draws_every_sheet_at_its_planned_resolution_then_builds_the_page", "crates/ui-egui/src/web_print.rs::the_print_page_turns_sideways_sheets_names_other_sizes_and_ends_without_a_blank_page", "crates/print/src/tests.rs::every_paper_reaches_the_spooler_by_a_name_of_its_size", "crates/automation/src/printing.rs::printing_to_a_printer_feeds_the_laid_out_paper"] +notes = "⌘P; settings and live sheet preview; on the web the same dialog prints through the browser's print dialog; last paper selection, including cancelled Print dialogs, persists by canonical name; this change does not alter persistence of other print preferences. CUPS jobs from the dialog and doc_print ask for the chosen paper (media) in every size: PPD keywords for the common ones, PWG 5101.1 names for A6, A0–A2, ARCH and ANSI C–E, checked against a synthetic PPD with cupsfilter, not on a physical large-format printer (#3752). On macOS jobs still take the PPD's default paper tray until craft-print sends Auto Select (#3752)" [[feature]] id = "print.printer-selection" From 75947139379cf3c1a00fd180d71b6f999e210134 Mon Sep 17 00:00:00 2001 From: Juan Jurado Date: Thu, 22 Oct 2026 18:24:54 -0600 Subject: [PATCH 2/3] M10: spell the ARCH media names as PWG 5101.1 does (#3752) ARCH A-E went out as arch_a_9x12in .. arch_e_36x48in; PWG 5101.1 names them na_arch-a_9x12in .. na_arch-e_36x48in (ARCH E1's IANA-registered na_arch-e1_30x42in already had the prefix). CUPS parses either from the dimensions, which is why the cupsfilter check passed, but a driverless printer may accept only the names it advertises. Re-checked the corrected names with cupsfilter against the synthetic PPD. The paper test now pins every size's exact name, and fails on the old spelling. Doc comments for doc_print and PrintDraft::job. Review: storytold/pdfcraft#4161 (CodeRabbit). --- crates/automation/src/printing.rs | 4 +++- crates/print/src/lib.rs | 17 ++++++++-------- crates/print/src/tests.rs | 34 +++++++++++++++++++++++++++++-- crates/ui-egui/src/print_ui.rs | 2 ++ 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/crates/automation/src/printing.rs b/crates/automation/src/printing.rs index e43c3c6e9f..111d27eecf 100644 --- a/crates/automation/src/printing.rs +++ b/crates/automation/src/printing.rs @@ -101,6 +101,8 @@ impl Automation { Ok(json!({ "printer": printer, "count": list.len(), "options": list })) } + /// `doc_print`: lay the document out with the Print dialog's options, then save the + /// print-ready PDF to `path` or send it to `printer` with the chosen paper. pub(crate) fn doc_print(&mut self, a: &Args) -> Result { let doc = self.doc(a)?; let (id, count) = (doc.id, doc.info.pages.len()); @@ -243,7 +245,7 @@ mod tests { } // Short forms find the same paper. assert_eq!(job(json!({}), Some("letter")).options, [media("Letter")]); - assert_eq!(job(json!({}), Some("ARCH D")).options, [media("arch_d_24x36in")]); + assert_eq!(job(json!({}), Some("ARCH D")).options, [media("na_arch-d_24x36in")]); assert!(matches!(paper_named(Some("Quarto")), Err(ToolError::InvalidArgs(m)) if m.contains("US Letter"))); assert_eq!(spool_job(&Args(&json!({})), "default", String::new(), None, 0).ok().map(|j| j.printer), Some(None)); assert!(spool_job(&Args(&json!({ "options": { "InputSlot": 3 } })), "Office", String::new(), None, 0).is_err()); diff --git a/crates/print/src/lib.rs b/crates/print/src/lib.rs index 80b7be27aa..75b6fdf1f4 100644 --- a/crates/print/src/lib.rs +++ b/crates/print/src/lib.rs @@ -309,9 +309,10 @@ pub const LABEL_PAPER: usize = 19; /// The CUPS media name for `PAPERS[index]`, so the spooler feeds the sheet the PDF was laid out /// on rather than the queue's default; `None` only past the end of `PAPERS`. The common sizes /// use their PPD keywords (`w288h432` is the usual 4×6 label, `Env10` the US #10 envelope). -/// The rest use PWG 5101.1 names (the IANA registry for ARCH E1), which carry their dimensions: -/// CUPS feeds the PPD size of those dimensions whatever the driver calls it (`ARCHD`, `AnsiD`), -/// and driverless IPP printers use these names themselves (#3752). +/// The rest use PWG 5101.1 names (for ARCH E1, which 5101.1 lacks, the IANA registry's), spelled +/// exactly: a driverless printer may take only the names it advertises. They carry their +/// dimensions, so CUPS feeds the PPD size of those dimensions whatever the driver calls it +/// (`ARCHD`, `AnsiD`) (#3752). pub fn cups_media(index: usize) -> Option<&'static str> { Some(match PAPERS.get(index)?.0 { "US Letter" => "Letter", @@ -321,12 +322,12 @@ pub fn cups_media(index: usize) -> Option<&'static str> { "A4" => "A4", "A5" => "A5", "A6" => "iso_a6_105x148mm", - "ARCH A (9 x 12 in)" => "arch_a_9x12in", - "ARCH B (12 x 18 in)" => "arch_b_12x18in", - "ARCH C (18 x 24 in)" => "arch_c_18x24in", - "ARCH D (24 x 36 in)" => "arch_d_24x36in", + "ARCH A (9 x 12 in)" => "na_arch-a_9x12in", + "ARCH B (12 x 18 in)" => "na_arch-b_12x18in", + "ARCH C (18 x 24 in)" => "na_arch-c_18x24in", + "ARCH D (24 x 36 in)" => "na_arch-d_24x36in", "ARCH E1 (30 x 42 in)" => "na_arch-e1_30x42in", - "ARCH E (36 x 48 in)" => "arch_e_36x48in", + "ARCH E (36 x 48 in)" => "na_arch-e_36x48in", "ANSI C (17 x 22 in)" => "na_c_17x22in", "ANSI D (22 x 34 in)" => "na_d_22x34in", "ANSI E (34 x 44 in)" => "na_e_34x44in", diff --git a/crates/print/src/tests.rs b/crates/print/src/tests.rs index a17adef15f..e7777fa1ac 100644 --- a/crates/print/src/tests.rs +++ b/crates/print/src/tests.rs @@ -674,10 +674,10 @@ fn paper_matching_accepts_rounded_metric_sizes_but_not_custom_or_invalid_sizes() } } +/// #3752: 13 of the 21 sizes had no media name, so their jobs went out on the queue's default +/// paper (A4 on the report's queue) whatever the sheets were laid out on. #[test] fn every_paper_reaches_the_spooler_by_a_name_of_its_size() { - // #3752: 13 of the 21 sizes had no media name, so their jobs went out on the queue's default - // paper (A4 on the report's queue) whatever the sheets were laid out on. let ppd_keywords = ["Letter", "Legal", "Tabloid", "A3", "A4", "A5", "w288h432", "Env10"]; for (i, (name, (w, h))) in PAPERS.iter().enumerate() { let media = cups_media(i).unwrap_or_else(|| panic!("{name} has no media name")); @@ -700,6 +700,36 @@ fn every_paper_reaches_the_spooler_by_a_name_of_its_size() { assert!((pw - w).abs() < 0.5 && (ph - h).abs() < 0.5, "{name}: {media} is {pw:.2} x {ph:.2} pt, not {w} x {h}"); } assert_eq!((cups_media(PAPERS.len()), media_option(PAPERS.len())), (None, None)); + // The names themselves, spelled as PWG 5101.1 has them: a driverless printer may take only the + // names it advertises, so one CUPS can merely parse (ARCH A was `arch_a_9x12in`) is not enough. + // ARCH E1 isn't in 5101.1; its name is the IANA registry's. + let names: Vec<(&str, &str)> = PAPERS.iter().enumerate().map(|(i, (name, _))| (*name, cups_media(i).unwrap_or_default())).collect(); + assert_eq!( + names, + [ + ("US Letter", "Letter"), + ("US Legal", "Legal"), + ("Tabloid", "Tabloid"), + ("A3", "A3"), + ("A4", "A4"), + ("A5", "A5"), + ("A6", "iso_a6_105x148mm"), + ("ARCH A (9 x 12 in)", "na_arch-a_9x12in"), + ("ARCH B (12 x 18 in)", "na_arch-b_12x18in"), + ("ARCH C (18 x 24 in)", "na_arch-c_18x24in"), + ("ARCH D (24 x 36 in)", "na_arch-d_24x36in"), + ("ARCH E1 (30 x 42 in)", "na_arch-e1_30x42in"), + ("ARCH E (36 x 48 in)", "na_arch-e_36x48in"), + ("ANSI C (17 x 22 in)", "na_c_17x22in"), + ("ANSI D (22 x 34 in)", "na_d_22x34in"), + ("ANSI E (34 x 44 in)", "na_e_34x44in"), + ("A2", "iso_a2_420x594mm"), + ("A1", "iso_a1_594x841mm"), + ("A0", "iso_a0_841x1189mm"), + ("4 x 6 in label (101.6 x 152.4 mm)", "w288h432"), + ("US #10 Envelope (4.125 x 9.5 in)", "Env10"), + ] + ); } #[test] diff --git a/crates/ui-egui/src/print_ui.rs b/crates/ui-egui/src/print_ui.rs index d5d95c881b..12a941b15d 100644 --- a/crates/ui-egui/src/print_ui.rs +++ b/crates/ui-egui/src/print_ui.rs @@ -223,6 +223,8 @@ impl PrintDraft { self.handling == Handling::Multiple && self.order == PageOrder::CutStack } + /// The spooler job for this print: the dialog's copies, two-sided and colour settings, the + /// driver options changed from the printer's defaults, and the chosen paper. pub fn job(&self, title: &str) -> spool::Job { spool::Job { printer: self.printer.clone(), From 635b42d9899a671b8e82d50033d970b16643c40f Mon Sep 17 00:00:00 2001 From: Juan Jurado Date: Thu, 22 Oct 2026 18:42:49 -0600 Subject: [PATCH 3/3] M10: ARCH E1 goes out as PWG 5101.1's na_wide-format_30x42in (#3752) 30 x 42 in is `na_wide-format_30x42in` in PWG 5101.1-2023 and the IANA IPP registry (checked against both). `na_arch-e1_30x42in` was asked for on the IPP list in 2021 but never registered. CUPS maps the new name to the PPD's 30 x 42 in size (cupsfilter, synthetic PPD), and the paper test pins it and fails on the old name. Doc comments for bad, printers and two paper tests, for the review's docstring check. Review: storytold/pdfcraft#4161 (CodeRabbit). --- crates/automation/src/printing.rs | 3 +++ crates/print/src/lib.rs | 10 +++++----- crates/print/src/tests.rs | 10 +++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/automation/src/printing.rs b/crates/automation/src/printing.rs index 111d27eecf..74e7328140 100644 --- a/crates/automation/src/printing.rs +++ b/crates/automation/src/printing.rs @@ -22,6 +22,7 @@ fn duplex(value: &str, cut_stack: bool) -> Result> { }) } +/// An invalid-arguments error saying `m`. fn bad(m: impl Into) -> ToolError { ToolError::InvalidArgs(m.into()) } @@ -75,6 +76,8 @@ fn spool_job(a: &Args, printer: &str, title: String, duplex: Option Result { let list: Vec = spool::printers() .into_iter() diff --git a/crates/print/src/lib.rs b/crates/print/src/lib.rs index 75b6fdf1f4..d85e766f14 100644 --- a/crates/print/src/lib.rs +++ b/crates/print/src/lib.rs @@ -309,10 +309,10 @@ pub const LABEL_PAPER: usize = 19; /// The CUPS media name for `PAPERS[index]`, so the spooler feeds the sheet the PDF was laid out /// on rather than the queue's default; `None` only past the end of `PAPERS`. The common sizes /// use their PPD keywords (`w288h432` is the usual 4×6 label, `Env10` the US #10 envelope). -/// The rest use PWG 5101.1 names (for ARCH E1, which 5101.1 lacks, the IANA registry's), spelled -/// exactly: a driverless printer may take only the names it advertises. They carry their -/// dimensions, so CUPS feeds the PPD size of those dimensions whatever the driver calls it -/// (`ARCHD`, `AnsiD`) (#3752). +/// The rest use PWG 5101.1 names (ARCH E1 is its `wide-format` size), spelled exactly as the +/// spec and the IANA registry have them: a driverless printer may take only the names it +/// advertises. They carry their dimensions, so CUPS feeds the PPD size of those dimensions +/// whatever the driver calls it (`ARCHD`, `AnsiD`) (#3752). pub fn cups_media(index: usize) -> Option<&'static str> { Some(match PAPERS.get(index)?.0 { "US Letter" => "Letter", @@ -326,7 +326,7 @@ pub fn cups_media(index: usize) -> Option<&'static str> { "ARCH B (12 x 18 in)" => "na_arch-b_12x18in", "ARCH C (18 x 24 in)" => "na_arch-c_18x24in", "ARCH D (24 x 36 in)" => "na_arch-d_24x36in", - "ARCH E1 (30 x 42 in)" => "na_arch-e1_30x42in", + "ARCH E1 (30 x 42 in)" => "na_wide-format_30x42in", "ARCH E (36 x 48 in)" => "na_arch-e_36x48in", "ANSI C (17 x 22 in)" => "na_c_17x22in", "ANSI D (22 x 34 in)" => "na_d_22x34in", diff --git a/crates/print/src/tests.rs b/crates/print/src/tests.rs index e7777fa1ac..d93bdf745b 100644 --- a/crates/print/src/tests.rs +++ b/crates/print/src/tests.rs @@ -661,6 +661,8 @@ fn architectural_sheets_preserve_full_scale() { assert!(fit[0].placed[0].matrix.0[0] < 1.0, "Fit adds margins and must not masquerade as full scale"); } +/// A sheet matches a preset either way round and rounded to whole points, but not half a point off; +/// empty, negative, infinite, NaN and custom sizes match none. #[test] fn paper_matching_accepts_rounded_metric_sizes_but_not_custom_or_invalid_sizes() { for (i, (_, (w, h))) in PAPERS.iter().enumerate() { @@ -702,7 +704,8 @@ fn every_paper_reaches_the_spooler_by_a_name_of_its_size() { assert_eq!((cups_media(PAPERS.len()), media_option(PAPERS.len())), (None, None)); // The names themselves, spelled as PWG 5101.1 has them: a driverless printer may take only the // names it advertises, so one CUPS can merely parse (ARCH A was `arch_a_9x12in`) is not enough. - // ARCH E1 isn't in 5101.1; its name is the IANA registry's. + // ARCH E1 is 5101.1's `wide-format` size: `na_arch-e1_30x42in` was asked for once and never + // registered. let names: Vec<(&str, &str)> = PAPERS.iter().enumerate().map(|(i, (name, _))| (*name, cups_media(i).unwrap_or_default())).collect(); assert_eq!( names, @@ -718,7 +721,7 @@ fn every_paper_reaches_the_spooler_by_a_name_of_its_size() { ("ARCH B (12 x 18 in)", "na_arch-b_12x18in"), ("ARCH C (18 x 24 in)", "na_arch-c_18x24in"), ("ARCH D (24 x 36 in)", "na_arch-d_24x36in"), - ("ARCH E1 (30 x 42 in)", "na_arch-e1_30x42in"), + ("ARCH E1 (30 x 42 in)", "na_wide-format_30x42in"), ("ARCH E (36 x 48 in)", "na_arch-e_36x48in"), ("ANSI C (17 x 22 in)", "na_c_17x22in"), ("ANSI D (22 x 34 in)", "na_d_22x34in"), @@ -732,9 +735,10 @@ fn every_paper_reaches_the_spooler_by_a_name_of_its_size() { ); } +/// #2734: the US #10 envelope (4.125 × 9.5 in) is offered, fed by its PPD name and laid out at +/// its own size. #[test] fn us_number_10_envelope_is_offered_and_fed_by_name() { - // 4.125 × 9.5 in (#2734). let index = matching_paper((684.0, 297.0)).unwrap(); assert_eq!(PAPERS[index].0, "US #10 Envelope (4.125 x 9.5 in)"); assert_eq!(PAPERS[index].1, (297.0, 684.0));