Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

M10: spell the ARCH media names as PWG 5101.1 does (#3752)

Juan Jurado75947139379c
diff --git a/crates/automation/src/printing.rs b/crates/automation/src/printing.rs
index e43c3c6e9..111d27eec 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<Value> {
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 80b7be27a..75b6fdf1f 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 a17adef15..e7777fa1a 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 d5d95c881..12a941b15 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(),