diff --git a/crates/engine/src/print_cmds.rs b/crates/engine/src/print_cmds.rs index c06cd4e1bc..fd458cfe33 100644 --- a/crates/engine/src/print_cmds.rs +++ b/crates/engine/src/print_cmds.rs @@ -640,10 +640,11 @@ fn with_driver_printable(p: &Value) -> Value { fn driver_printable(p: &Value) -> Option { let printer = printer_name(p).ok()?; - let pg = craft_print::rgb::page(&printer, printer_settings(p).ok()?.as_ref()).ok()?; - // Only for the paper the driver is set to: a print laid out on another paper keeps the - // fixed margin (and `print_windows` refuses it), as before. let (pw, ph) = paper(p, "file.print").ok()?; + // The page `print_windows` prints on, turned as it turns it for the layout's orientation. + let (_, pg) = settings_for_layout(&printer, printer_settings(p).ok()?, (pw, ph)).ok()?; + // Only for the paper the driver is set to, either way round: a print laid out on another + // paper keeps the fixed margin (and `print_windows` refuses it), as before. if (pg.paper.0 - pw).abs() > 2.0 || (pg.paper.1 - ph).abs() > 2.0 { return None; } diff --git a/crates/ui-egui/src/file_ui.rs b/crates/ui-egui/src/file_ui.rs index 6fcacd2ee8..00f8033eba 100644 --- a/crates/ui-egui/src/file_ui.rs +++ b/crates/ui-egui/src/file_ui.rs @@ -806,6 +806,11 @@ fn take_turned_page(f: &mut Map, r: &Value) { }; f.insert("printerSettings".into(), json!(settings)); f.insert("paper".into(), json!([w, h])); + // The printable area turns with the paper; left portrait, it wouldn't fit the turned sheet. + match r.get("printable").filter(|v| v.as_array().is_some_and(|a| a.len() == 4 && a.iter().all(Value::is_number))) { + Some(area) => f.insert("printable".into(), area.clone()), + None => f.remove("printable"), + }; f.insert("orientation".into(), json!("portrait")); f.remove("__pageError"); } @@ -1668,6 +1673,32 @@ mod tests { assert!(f.get("__pageError").is_some(), "{partial}"); } } + + /// #7782: the driver's printable area turns with the paper. Left portrait on a landscape + /// sheet, Scale to Fit Media refused the print instead of fitting it. + #[test] + fn a_turn_takes_the_printable_area_with_the_paper() { + let (mut app, ctx) = app(); + crate::menus::invoke(&mut app, &ctx, "file.new", json!({"width": 500, "height": 1000})).unwrap(); + let doc = app.session.active().unwrap().doc.clone(); + let mut f = Map::new(); + f.insert("scaleToFit".into(), json!(true)); + f.insert("dryRun".into(), json!(false)); + f.insert("printerSettings".into(), json!("old")); + f.insert("paper".into(), json!([842.29, 1191.14])); + f.insert("printable".into(), json!([12.0, 12.0, 818.29, 1167.14])); + f.insert("orientation".into(), json!("portrait")); + take_turned_page(&mut f, &json!({"printerSettings": "new", "paper": [1191.14, 842.29], "printable": [12.0, 12.0, 1167.14, 818.29]})); + let l = photocraft_engine::print_cmds::layout(&doc, &print_params(&f), "file.print"); + assert_eq!(l.map(|l| l.paper).map_err(|e| e.to_string()), Ok((1191.14, 842.29))); + assert_eq!(f.get("printable"), Some(&json!([12.0, 12.0, 1167.14, 818.29]))); + // An answer without a usable area drops the old one: the fixed margin, not a stale area. + for area in [Value::Null, json!([12.0, 12.0, 818.29]), json!("x")] { + f.insert("printable".into(), json!([12.0, 12.0, 1167.14, 818.29])); + take_turned_page(&mut f, &json!({"printerSettings": "newer", "paper": [842.29, 1191.14], "printable": area})); + assert!(f.get("printable").is_none(), "{area}"); + } + } } #[cfg(test)] diff --git a/docs/printing.md b/docs/printing.md index 399944d57d..63f2ad3c5d 100644 --- a/docs/printing.md +++ b/docs/printing.md @@ -49,6 +49,11 @@ whose layout is the driver's paper the other way round (a landscape layout, port turns the settings to the layout before printing, rather than stopping with "the driver paper or orientation differs"; another paper is still refused. +Scale to Fit Media fills the printable area the driver reports for that page (`printable` in +`file.print.page`), so borderless paper prints edge to edge (#7782). The area turns with the +paper, and a print sent to a Windows printer reads it from the driver itself. Without a driver +page (CUPS, IPP, a PDF or a preview) it fits the paper less an 18 pt margin, as before. + ## Results `file.print` returns `sent`, `backend` (`lp`, `windows`, `ipp`, `portal`), `spooler` (where the