mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Print: the printable area turns with the paper (#7782)
#7847 added Portrait and Landscape to the Windows Print dialog. A turn took the settings and the paper from file.print.page but kept the portrait printable area, so Scale to Fit Media refused the turned sheet. It now takes the area from the same answer, or drops it. The engine reads the driver's area through settings_for_layout, the same turn print_windows makes, so a landscape layout on portrait settings fits the landscape area. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
6ec3a9d80b
commit
f3ede6136b
3 files changed
+40
-3
No files matched your search
@@ -640,10 +640,11 @@ fn with_driver_printable(p: &Value) -> Value {
|
||||
|
||||
fn driver_printable(p: &Value) -> Option<Value> {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -806,6 +806,11 @@ fn take_turned_page(f: &mut Map<String, Value>, 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)]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user