mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-18 10:09:20 +00:00
This commit is contained in:
1 parent
04062a047e
commit
3e48317ae3
12 files changed
+224
-25
No files matched your search
@@ -134,6 +134,18 @@ impl Automation {
|
||||
"shrink" => Layout::Size(SizeMode::Shrink),
|
||||
"custom" => Layout::Size(SizeMode::Custom(a.opt_num("scale")?.ok_or_else(|| bad("custom needs scale (percent)"))?)),
|
||||
"multiple" => {
|
||||
// Custom pages per sheet: `cols` across by `rows` down, both or neither.
|
||||
let grid = match (a.opt_int("cols")?, a.opt_int("rows")?) {
|
||||
(None, None) => None,
|
||||
(Some(cols), Some(rows)) => {
|
||||
if a.opt_int("per_sheet")?.is_some() {
|
||||
return Err(bad("give per_sheet, or cols and rows, not both"));
|
||||
}
|
||||
let grid = usize::try_from(cols).ok().zip(usize::try_from(rows).ok()).and_then(|(cols, rows)| Layout::grid(cols, rows));
|
||||
Some(grid.ok_or_else(|| bad(format!("cols and rows must each be 1 to {}", print::MAX_GRID)))?)
|
||||
}
|
||||
_ => return Err(bad("a custom grid needs both cols and rows")),
|
||||
};
|
||||
let per = a.opt_int("per_sheet")?.unwrap_or(2).clamp(1, 256) as usize;
|
||||
let order = match a.opt_str("order")?.unwrap_or("horizontal") {
|
||||
"horizontal" => PageOrder::Horizontal,
|
||||
@@ -143,14 +155,15 @@ impl Automation {
|
||||
"cut-stack" => PageOrder::CutStack,
|
||||
o => return Err(bad(format!("unknown order {o:?}"))),
|
||||
};
|
||||
match Layout::multiple(per) {
|
||||
Layout::Multiple { cols, rows, per_sheet, .. } => Layout::Multiple {
|
||||
match grid.unwrap_or_else(|| Layout::multiple(per)) {
|
||||
Layout::Multiple { cols, rows, per_sheet, custom, .. } => Layout::Multiple {
|
||||
cols,
|
||||
rows,
|
||||
per_sheet,
|
||||
order,
|
||||
border: a.opt_bool("border")?.unwrap_or(false),
|
||||
auto_rotate: a.opt_bool("auto_rotate")?.unwrap_or(true),
|
||||
custom,
|
||||
},
|
||||
l => l,
|
||||
}
|
||||
@@ -172,6 +185,9 @@ impl Automation {
|
||||
l => return Err(bad(format!("unknown layout {l:?}"))),
|
||||
};
|
||||
let duplex = job_duplex(a.opt_str("duplex")?.unwrap_or("off"), &layout)?;
|
||||
if (a.opt_int("cols")?.is_some() || a.opt_int("rows")?.is_some()) && !matches!(layout, Layout::Multiple { .. }) {
|
||||
return Err(bad("cols and rows need layout multiple"));
|
||||
}
|
||||
if a.opt_str("order")? == Some("cut-stack") && !matches!(layout, Layout::Multiple { .. }) {
|
||||
return Err(bad("cut-stack order needs layout multiple"));
|
||||
}
|
||||
|
||||
@@ -707,7 +707,7 @@ pub fn tools() -> Vec<ToolDef> {
|
||||
t(
|
||||
"doc_print",
|
||||
"Print",
|
||||
"Print with Acrobat's Print dialog options, or save the print-ready PDF. pages: a range such as \"1-3, 6, 9-\" (page labels allowed; default all); subset odd/even (by page number, as Acrobat counts them: pages 2, 7-10 with even prints 2, 8 and 10, not every second page of the range); reverse. layout: fit (default), actual, shrink, custom (scale %), multiple (per_sheet 2/4/6/9/16, order, border, auto_rotate; cut-stack order arranges single-sided sheets for cutting into piles and stacking left to right, top to bottom, keeping sheet order within each pile; duplex must be off), booklet (booklet_subset both/front/back, binding left/right; a booklet sets two-sided itself, as Acrobat does: both flips on the short edge, front or back prints one-sided), poster (scale %, overlap pt, cut_marks). orientation auto/portrait/landscape; comments_forms document / document-and-markups (default) / document-and-stamps / form-fields-only; paper Letter/Legal/Tabloid, ARCH A/B/C/D/E1/E, ANSI C/D/E, A0/A1/A2/A3/A4/A5/A6, or US #10 Envelope (short names or full preset labels); use layout actual for 100% in the print-ready PDF; printer drivers may still substitute paper or scale. Then path (save) or printer (a name or \"default\") with copies, collate, duplex off/long-edge/short-edge, grayscale, and options (driver options from printer_options, CUPS).",
|
||||
"Print with Acrobat's Print dialog options, or save the print-ready PDF. pages: a range such as \"1-3, 6, 9-\" (page labels allowed; default all); subset odd/even (by page number, as Acrobat counts them: pages 2, 7-10 with even prints 2, 8 and 10, not every second page of the range); reverse. layout: fit (default), actual, shrink, custom (scale %), multiple (per_sheet 2/4/6/9/16, which turns the sheet to suit the grid, or a custom grid of cols across by rows down, each 1-99, on the sheet as oriented (auto prints portrait); order, border, auto_rotate; cut-stack order arranges single-sided sheets for cutting into piles and stacking left to right, top to bottom, keeping sheet order within each pile; duplex must be off), booklet (booklet_subset both/front/back, binding left/right; a booklet sets two-sided itself, as Acrobat does: both flips on the short edge, front or back prints one-sided), poster (scale %, overlap pt, cut_marks). orientation auto/portrait/landscape; comments_forms document / document-and-markups (default) / document-and-stamps / form-fields-only; paper Letter/Legal/Tabloid, ARCH A/B/C/D/E1/E, ANSI C/D/E, A0/A1/A2/A3/A4/A5/A6, or US #10 Envelope (short names or full preset labels); use layout actual for 100% in the print-ready PDF; printer drivers may still substitute paper or scale. Then path (save) or printer (a name or \"default\") with copies, collate, duplex off/long-edge/short-edge, grayscale, and options (driver options from printer_options, CUPS).",
|
||||
)
|
||||
.with(schema(
|
||||
json!({
|
||||
@@ -718,6 +718,8 @@ pub fn tools() -> Vec<ToolDef> {
|
||||
"layout": { "type": "string", "enum": ["fit", "actual", "shrink", "custom", "multiple", "booklet", "poster"] },
|
||||
"scale": { "type": "number", "exclusiveMinimum": 0 },
|
||||
"per_sheet": { "type": "integer", "minimum": 1, "maximum": 256 },
|
||||
"cols": { "type": "integer", "minimum": 1, "maximum": 99, "description": "Custom pages per sheet: columns across the sheet; give rows too, and no per_sheet." },
|
||||
"rows": { "type": "integer", "minimum": 1, "maximum": 99, "description": "Custom pages per sheet: rows down the sheet; give cols too, and no per_sheet." },
|
||||
"order": { "type": "string", "enum": ["horizontal", "horizontal-reversed", "vertical", "vertical-reversed", "cut-stack"] },
|
||||
"border": { "type": "boolean" },
|
||||
"auto_rotate": { "type": "boolean" },
|
||||
|
||||
@@ -8915,6 +8915,49 @@ fn cut_stack_printing_through_tools() {
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_pages_per_sheet_prints_the_grid_as_given() {
|
||||
// Two narrow pages side by side on portrait A4: 2 columns by 1 row (#6551).
|
||||
let dir = workdir("custom-grid");
|
||||
std::fs::write(dir.join("narrow.pdf"), fixture(4)).unwrap();
|
||||
let mut a = auto(&dir);
|
||||
let doc = ok(&mut a, "doc_open", json!({"path": "narrow.pdf"}))["doc"].as_u64().unwrap();
|
||||
for orientation in ["auto", "portrait"] {
|
||||
let r = ok(
|
||||
&mut a,
|
||||
"doc_print",
|
||||
json!({"doc": doc, "layout": "multiple", "cols": 2, "rows": 1, "paper": "A4", "orientation": orientation, "path": "grid.pdf"}),
|
||||
);
|
||||
assert_eq!(r["sheets"], 2, "{orientation}");
|
||||
let printed = ok(&mut a, "doc_open", json!({"path": "grid.pdf"}))["doc"].as_u64().unwrap();
|
||||
let info = ok(&mut a, "doc_info", json!({"doc": printed}));
|
||||
let sheet = &info["pages"][0];
|
||||
assert!(sheet["width"].as_f64().unwrap() < sheet["height"].as_f64().unwrap(), "portrait sheet with {orientation}: {sheet}");
|
||||
// Side by side: the second page level with the first, to its right.
|
||||
let rows = ok(&mut a, "text_extract", json!({"doc": printed, "rect": [0, 0, 600, 850]}));
|
||||
let rows: Vec<&str> = rows["pages"].as_array().unwrap().iter().map(|p| p["text"].as_str().unwrap().trim()).collect();
|
||||
assert_eq!(rows, ["Page 1 Page 2", "Page 3 Page 4"], "{orientation}");
|
||||
ok(&mut a, "doc_close", json!({"doc": printed}));
|
||||
}
|
||||
for bad in [
|
||||
json!({"cols": 2}),
|
||||
json!({"rows": 1}),
|
||||
json!({"cols": 0, "rows": 1}),
|
||||
json!({"cols": 2, "rows": 100}),
|
||||
json!({"cols": -1, "rows": 2}),
|
||||
json!({"cols": 2, "rows": 1, "per_sheet": 2}),
|
||||
json!({"cols": 2, "rows": 1, "layout": "fit"}),
|
||||
] {
|
||||
let mut args = json!({"doc": doc, "layout": "multiple", "path": "refused.pdf"});
|
||||
for (k, v) in bad.as_object().unwrap() {
|
||||
args[k] = v.clone();
|
||||
}
|
||||
assert!(matches!(a.call("doc_print", &args), Err(ToolError::InvalidArgs(_))), "{bad}");
|
||||
}
|
||||
assert!(!dir.join("refused.pdf").exists());
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn measurements_calibrate_draw_save_reopen_and_export() {
|
||||
let dir = workdir("measurements");
|
||||
|
||||
@@ -13,7 +13,10 @@ spool::submit(&pdf, &spool::Job { printer: None, copies: 2, ..Default::default()
|
||||
- **Size**: fit (to the sheet minus an 18 pt margin), actual size, shrink oversized, custom %;
|
||||
centred; auto orientation turns the sheet for landscape pages.
|
||||
- **Multiple**: 2/4/6/9/16 (or any n) pages per sheet, horizontal/vertical (reversed) order,
|
||||
page borders, auto-rotation of pages that don't match the cell.
|
||||
page borders, auto-rotation of pages that don't match the cell. With auto orientation a
|
||||
predefined count turns the sheet to suit its grid (2 per sheet prints side by side on
|
||||
landscape). A custom grid (`Layout::grid`, `doc_print` `cols`/`rows`, 1-99 each) is laid
|
||||
out across and down the sheet as given and doesn't turn it: auto prints portrait.
|
||||
- **Cut and stack** (Multiple's page order): consecutive pages in each cell's pile,
|
||||
with aligned cut marks in the gutters. For example, 10 pages at 4 per sheet give
|
||||
`[1, 4, 7, 10]`, `[2, 5, 8, blank]`, `[3, 6, 9, blank]`. Print single-sided,
|
||||
|
||||
@@ -37,7 +37,7 @@ pub use error::{PrintError, WORDINGS, Words, in_english};
|
||||
use imposition::{PAGES_LISTED, appearance, appearance_matrix, decoded_contents, page_form, prints};
|
||||
pub use imposition::{impose, keep_printed, sheet_pages};
|
||||
pub use settings::{
|
||||
Binding, BookletSubset, Content, Crop, LABEL_PAPER, Layout, Orientation, PAPERS, PageOrder, Raster, Settings, SizeMode, booklet_duplex,
|
||||
Binding, BookletSubset, Content, Crop, LABEL_PAPER, Layout, MAX_GRID, Orientation, PAPERS, PageOrder, Raster, Settings, SizeMode, booklet_duplex,
|
||||
cups_media, media_option,
|
||||
};
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -69,6 +69,11 @@ pub enum Layout {
|
||||
order: PageOrder,
|
||||
border: bool,
|
||||
auto_rotate: bool,
|
||||
/// A custom grid (the Print dialog's Custom pages per sheet): `cols` across and `rows`
|
||||
/// down the sheet whatever its orientation, which is not picked for the grid, so Auto
|
||||
/// prints portrait. A predefined count (`false`, [`Layout::multiple`]) is a grid on a
|
||||
/// portrait sheet that turns to landscape when that suits it.
|
||||
custom: bool,
|
||||
},
|
||||
Booklet {
|
||||
subset: BookletSubset,
|
||||
@@ -107,10 +112,24 @@ impl Layout {
|
||||
(c, n.div_ceil(c).max(1))
|
||||
}
|
||||
};
|
||||
Layout::Multiple { cols, rows, per_sheet: per_sheet.max(1), order: PageOrder::Horizontal, border: false, auto_rotate: true }
|
||||
Layout::Multiple { cols, rows, per_sheet: per_sheet.max(1), order: PageOrder::Horizontal, border: false, auto_rotate: true, custom: false }
|
||||
}
|
||||
|
||||
/// A custom grid of `cols` across by `rows` down, each 1 to [`MAX_GRID`]; every cell holds a
|
||||
/// page. `None` for a count outside that.
|
||||
pub fn grid(cols: usize, rows: usize) -> Option<Layout> {
|
||||
if !(1..=MAX_GRID).contains(&cols) || !(1..=MAX_GRID).contains(&rows) {
|
||||
return None;
|
||||
}
|
||||
// At most 99 × 99, so this cannot overflow.
|
||||
let per_sheet = cols.checked_mul(rows)?;
|
||||
Some(Layout::Multiple { cols, rows, per_sheet, order: PageOrder::Horizontal, border: false, auto_rotate: true, custom: true })
|
||||
}
|
||||
}
|
||||
|
||||
/// The most columns, or rows, a custom pages-per-sheet grid can have.
|
||||
pub const MAX_GRID: usize = 99;
|
||||
|
||||
/// Acrobat's Comments & Forms choices.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub enum Content {
|
||||
|
||||
@@ -164,8 +164,10 @@ pub fn layout(sizes: &[(f64, f64)], settings: &Settings) -> Result<Vec<Sheet>, P
|
||||
Layout::Label { flip } => {
|
||||
sheets.extend(layout_labels(sizes, &pages, paper, settings.orientation, settings, flip));
|
||||
}
|
||||
Layout::Multiple { cols, rows, per_sheet, order, border, auto_rotate } => {
|
||||
let cells = cols.checked_mul(rows).filter(|&n| n > 0 && n <= 256);
|
||||
Layout::Multiple { cols, rows, per_sheet, order, border, auto_rotate, custom } => {
|
||||
// A predefined count has at most 16 × 16 cells; a custom grid up to 99 each way.
|
||||
let fits = if custom { cols <= crate::MAX_GRID && rows <= crate::MAX_GRID } else { cols.checked_mul(rows).is_some_and(|n| n <= 256) };
|
||||
let cells = cols.checked_mul(rows).filter(|&n| n > 0 && fits);
|
||||
let Some(cells) = cells else {
|
||||
return Err(PrintError::Invalid("invalid number of pages per sheet".into()));
|
||||
};
|
||||
@@ -177,7 +179,10 @@ pub fn layout(sizes: &[(f64, f64)], settings: &Settings) -> Result<Vec<Sheet>, P
|
||||
// A grid with more columns than rows wants a landscape sheet, and the reverse.
|
||||
let first = pages.first().and_then(|&p| sizes.get(p)).copied().ok_or(PrintError::NoPages)?;
|
||||
let page_landscape = first.0 > first.1;
|
||||
let (gc, gr, sheet_landscape) = if cols == rows {
|
||||
let (gc, gr, sheet_landscape) = if custom {
|
||||
// A custom grid is laid out as given, on the sheet as chosen (Auto: portrait).
|
||||
(cols, rows, false)
|
||||
} else if cols == rows {
|
||||
(cols, rows, page_landscape)
|
||||
} else if settings.orientation == Orientation::Landscape || (settings.orientation == Orientation::Auto && cols < rows) {
|
||||
// 2 per sheet (1 × 2 on portrait) prints side by side on landscape paper.
|
||||
|
||||
@@ -159,7 +159,10 @@ fn multiple_pages_per_sheet() {
|
||||
// Vertical order and borders.
|
||||
let v = layout(
|
||||
&sizes,
|
||||
&settings(vec![0, 1, 2], Layout::Multiple { cols: 2, rows: 2, per_sheet: 4, order: PageOrder::Vertical, border: true, auto_rotate: false }),
|
||||
&settings(
|
||||
vec![0, 1, 2],
|
||||
Layout::Multiple { cols: 2, rows: 2, per_sheet: 4, order: PageOrder::Vertical, border: true, auto_rotate: false, custom: false },
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(close(v[0].placed[1].matrix.0[4], v[0].placed[0].matrix.0[4]) && v[0].placed[1].matrix.0[5] < v[0].placed[0].matrix.0[5]);
|
||||
@@ -183,10 +186,11 @@ fn custom_pages_per_sheet_never_overfill_the_grid() {
|
||||
assert_eq!(pages(4), [vec![0, 1, 2, 3], vec![4, 5, 6]]);
|
||||
assert_eq!(pages(2), [vec![0, 1], vec![2, 3], vec![4, 5], vec![6]]);
|
||||
// Cut-stack piles take the requested count too.
|
||||
let stacked = Layout::Multiple { cols: 2, rows: 2, per_sheet: 3, order: PageOrder::CutStack, border: false, auto_rotate: false };
|
||||
let stacked = Layout::Multiple { cols: 2, rows: 2, per_sheet: 3, order: PageOrder::CutStack, border: false, auto_rotate: false, custom: false };
|
||||
assert_eq!(sheet_pages(&layout(&sizes, &settings((0..7).collect(), stacked)).unwrap()), [vec![0, 3, 6], vec![1, 4], vec![2, 5]]);
|
||||
// A count larger than the grid is capped by the grid; no pages per sheet is refused.
|
||||
let grid = |per_sheet| Layout::Multiple { cols: 2, rows: 1, per_sheet, order: PageOrder::Horizontal, border: false, auto_rotate: false };
|
||||
let grid =
|
||||
|per_sheet| Layout::Multiple { cols: 2, rows: 1, per_sheet, order: PageOrder::Horizontal, border: false, auto_rotate: false, custom: false };
|
||||
assert_eq!(sheet_pages(&layout(&sizes[..3], &settings(vec![0, 1, 2], grid(9))).unwrap()), [vec![0, 1], vec![2]]);
|
||||
assert!(matches!(layout(&sizes, &settings(vec![0], grid(0))), Err(PrintError::Invalid(_))));
|
||||
// The imposed PDF has one page per sheet.
|
||||
@@ -194,6 +198,34 @@ fn custom_pages_per_sheet_never_overfill_the_grid() {
|
||||
assert_eq!(pdfcraft_model::pages(&Document::open(Arc::new(out)).unwrap()).len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_custom_grid_is_laid_out_as_given_on_the_chosen_sheet() {
|
||||
// Columns across and rows down whatever the sheet, which isn't turned for the grid (#6551).
|
||||
let sizes = vec![(200.0, 300.0); 4];
|
||||
let at = |sheet: &Sheet, k: usize| (sheet.placed[k].matrix.0[4], sheet.placed[k].matrix.0[5]);
|
||||
let grid = |cols, rows| Layout::grid(cols, rows).unwrap();
|
||||
for (orientation, size) in
|
||||
[(Orientation::Auto, (612.0, 792.0)), (Orientation::Portrait, (612.0, 792.0)), (Orientation::Landscape, (792.0, 612.0))]
|
||||
{
|
||||
let s = |layout| Settings { orientation, ..settings((0..4).collect(), layout) };
|
||||
let across = layout(&sizes, &s(grid(2, 1))).unwrap();
|
||||
assert_eq!((across.len(), across[0].size), (2, size), "{orientation:?}");
|
||||
assert!(at(&across[0], 1).0 > at(&across[0], 0).0 && close(at(&across[0], 1).1, at(&across[0], 0).1), "side by side, {orientation:?}");
|
||||
let down = layout(&sizes, &s(grid(1, 2))).unwrap();
|
||||
assert_eq!(down[0].size, size, "{orientation:?}");
|
||||
assert!(close(at(&down[0], 1).0, at(&down[0], 0).0) && at(&down[0], 1).1 < at(&down[0], 0).1, "stacked, {orientation:?}");
|
||||
let three = layout(&sizes, &s(grid(3, 1))).unwrap();
|
||||
assert_eq!(sheet_pages(&three), [vec![0, 1, 2], vec![3]]);
|
||||
}
|
||||
// 1 to 99 each way, and a grid too fine for the paper is refused, not drawn.
|
||||
assert!(Layout::grid(0, 1).is_none() && Layout::grid(1, 0).is_none() && Layout::grid(100, 1).is_none() && Layout::grid(1, usize::MAX).is_none());
|
||||
assert_eq!(layout(&sizes, &settings(vec![0], grid(17, 17))).unwrap()[0].placed.len(), 1);
|
||||
assert!(matches!(layout(&sizes, &settings(vec![0], grid(99, 99))), Err(PrintError::Invalid(_))));
|
||||
let hostile =
|
||||
Layout::Multiple { cols: 100, rows: 1, per_sheet: 1, order: PageOrder::Horizontal, border: false, auto_rotate: false, custom: true };
|
||||
assert!(matches!(layout(&sizes, &settings(vec![0], hostile)), Err(PrintError::Invalid(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn imposing_lists_the_pages_once() {
|
||||
let n = 150;
|
||||
@@ -450,7 +482,15 @@ fn driverless_printers_join_the_list_without_a_queue() {
|
||||
}
|
||||
|
||||
fn cut_stack(cols: usize, rows: usize) -> Layout {
|
||||
Layout::Multiple { cols, rows, per_sheet: cols.saturating_mul(rows), order: PageOrder::CutStack, border: false, auto_rotate: false }
|
||||
Layout::Multiple {
|
||||
cols,
|
||||
rows,
|
||||
per_sheet: cols.saturating_mul(rows),
|
||||
order: PageOrder::CutStack,
|
||||
border: false,
|
||||
auto_rotate: false,
|
||||
custom: false,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -503,7 +543,7 @@ fn cutting_and_stacking_recovers_every_selected_page() {
|
||||
fn multiple_rejects_hostile_grids_without_panicking() {
|
||||
let sizes = [(200.0, 300.0)];
|
||||
for (cols, rows) in [(usize::MAX, 2), (2, usize::MAX), (0, 2), (1, 0), (257, 1)] {
|
||||
let mode = Layout::Multiple { cols, rows, per_sheet: 1, order: PageOrder::Horizontal, border: false, auto_rotate: false };
|
||||
let mode = Layout::Multiple { cols, rows, per_sheet: 1, order: PageOrder::Horizontal, border: false, auto_rotate: false, custom: false };
|
||||
assert!(matches!(layout(&sizes, &settings(vec![0], mode)), Err(PrintError::Invalid(_))));
|
||||
}
|
||||
let tiny = Settings { paper: (72.0, 72.0), ..settings(vec![0], cut_stack(16, 16)) };
|
||||
|
||||
@@ -337,15 +337,13 @@ pub(crate) fn body(
|
||||
});
|
||||
}
|
||||
Handling::Multiple => {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tl!("Pages per sheet:"));
|
||||
combo(ui, "per-sheet", tl!("Pages per sheet:"), &mut d.per_sheet, &[(2, "2"), (4, "4"), (6, "6"), (9, "9"), (16, "16")], 60.0);
|
||||
let page_order = |ui: &mut egui::Ui, order: &mut PageOrder| {
|
||||
ui.label(tl!("Page order:"));
|
||||
combo(
|
||||
ui,
|
||||
"order",
|
||||
tl!("Page order:"),
|
||||
&mut d.order,
|
||||
order,
|
||||
&[
|
||||
(PageOrder::Horizontal, tl!("Horizontal")),
|
||||
(PageOrder::HorizontalReversed, tl!("Horizontal reversed")),
|
||||
@@ -355,7 +353,34 @@ pub(crate) fn body(
|
||||
],
|
||||
150.0,
|
||||
);
|
||||
};
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tl!("Pages per sheet:"));
|
||||
// `None` is Custom: columns by rows, typed in.
|
||||
let mut per_sheet = (!d.custom_grid).then_some(d.per_sheet);
|
||||
combo(
|
||||
ui,
|
||||
"per-sheet",
|
||||
tl!("Pages per sheet:"),
|
||||
&mut per_sheet,
|
||||
&[(Some(2), "2"), (Some(4), "4"), (Some(6), "6"), (Some(9), "9"), (Some(16), "16"), (None, tl!("Custom"))],
|
||||
70.0,
|
||||
);
|
||||
d.custom_grid = per_sheet.is_none();
|
||||
if let Some(n) = per_sheet {
|
||||
d.per_sheet = n;
|
||||
page_order(ui, &mut d.order);
|
||||
} else {
|
||||
let max = print::MAX_GRID;
|
||||
ui.add(egui::DragValue::new(&mut d.cols).range(1..=max)).accessible_name(tl!("Columns"));
|
||||
ui.label(tl!("by"));
|
||||
ui.add(egui::DragValue::new(&mut d.rows).range(1..=max)).accessible_name(tl!("Rows"));
|
||||
}
|
||||
});
|
||||
if d.custom_grid {
|
||||
// The grid's fields take the room the page order had.
|
||||
ui.horizontal(|ui| page_order(ui, &mut d.order));
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(widgets::checkbox(&mut d.border, tl!("Print page border")));
|
||||
ui.add(widgets::checkbox(&mut d.auto_rotate, tl!("Auto-rotate pages")));
|
||||
|
||||
@@ -45,6 +45,10 @@ pub struct PrintDraft {
|
||||
pub size: SizeMode,
|
||||
pub custom_scale: f64,
|
||||
pub per_sheet: usize,
|
||||
/// Pages per sheet: Custom, `cols` across by `rows` down instead of `per_sheet`.
|
||||
pub custom_grid: bool,
|
||||
pub cols: usize,
|
||||
pub rows: usize,
|
||||
pub order: PageOrder,
|
||||
pub border: bool,
|
||||
pub auto_rotate: bool,
|
||||
@@ -106,6 +110,9 @@ impl Default for PrintDraft {
|
||||
size: SizeMode::Fit,
|
||||
custom_scale: 100.0,
|
||||
per_sheet: 2,
|
||||
custom_grid: false,
|
||||
cols: 2,
|
||||
rows: 1,
|
||||
order: PageOrder::Horizontal,
|
||||
border: false,
|
||||
auto_rotate: true,
|
||||
@@ -180,12 +187,19 @@ impl PrintDraft {
|
||||
SizeMode::Custom(_) => SizeMode::Custom(self.custom_scale),
|
||||
m => m,
|
||||
}),
|
||||
Handling::Multiple => match Layout::multiple(self.per_sheet) {
|
||||
Layout::Multiple { cols, rows, per_sheet, .. } => {
|
||||
Layout::Multiple { cols, rows, per_sheet, order: self.order, border: self.border, auto_rotate: self.auto_rotate }
|
||||
Handling::Multiple => {
|
||||
let grid = if self.custom_grid {
|
||||
Layout::grid(self.cols, self.rows).ok_or_else(|| tl!("Columns and rows must each be 1 to 99.").to_string())?
|
||||
} else {
|
||||
Layout::multiple(self.per_sheet)
|
||||
};
|
||||
match grid {
|
||||
Layout::Multiple { cols, rows, per_sheet, custom, .. } => {
|
||||
Layout::Multiple { cols, rows, per_sheet, order: self.order, border: self.border, auto_rotate: self.auto_rotate, custom }
|
||||
}
|
||||
other => other,
|
||||
}
|
||||
other => other,
|
||||
},
|
||||
}
|
||||
Handling::Booklet => Layout::Booklet { subset: self.booklet_subset, binding: self.binding },
|
||||
Handling::Poster => Layout::Poster { scale: self.poster_scale, overlap: self.overlap, cut_marks: self.cut_marks },
|
||||
Handling::Label => Layout::Label { flip: self.label_flip },
|
||||
|
||||
@@ -215,6 +215,38 @@ fn cut_stack_dialog_previews_saves_and_refuses_duplex() {
|
||||
let _ = std::fs::remove_file(out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_pages_per_sheet_takes_columns_by_rows() {
|
||||
use pdfcraft_engine::print::{Layout, PageOrder};
|
||||
let mut h = harness();
|
||||
let bytes = h.state().session.create_blank(200.0, 300.0, 4).unwrap();
|
||||
h.state_mut().open_bytes("narrow.pdf", None, bytes.as_ref().clone()).unwrap();
|
||||
h.state_mut().execute("print.dialog");
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Multiple").click();
|
||||
h.run_steps(2);
|
||||
assert!(h.query_by_label("Columns").is_none(), "a predefined count has no grid fields");
|
||||
h.get_by_role_and_label(Role::ComboBox, "Pages per sheet:").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Custom").click();
|
||||
h.run_steps(2);
|
||||
// Two number fields, columns by rows, with 2 by 1 to start.
|
||||
assert_eq!(h.get_by_label("Columns").value().as_deref(), Some("2"));
|
||||
assert_eq!(h.get_by_label("Rows").value().as_deref(), Some("1"));
|
||||
h.get_by_label("by");
|
||||
let d = &h.state().print_draft;
|
||||
assert!(d.custom_grid);
|
||||
let layout = d.settings(4, &[]).unwrap().layout;
|
||||
assert_eq!(
|
||||
layout,
|
||||
Layout::Multiple { cols: 2, rows: 1, per_sheet: 2, order: PageOrder::Horizontal, border: false, auto_rotate: true, custom: true }
|
||||
);
|
||||
h.get_by_label("Sheet 1 of 2");
|
||||
// A count outside 1 to 99 (set through the control channel) is explained, not drawn.
|
||||
h.state_mut().print_draft.rows = 0;
|
||||
assert!(h.state().print_draft.settings(4, &[]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_save_as_pdf_keeps_the_dialog_open() {
|
||||
let mut h = harness();
|
||||
|
||||
@@ -8273,8 +8273,8 @@ milestone = "M10"
|
||||
status = "shipped"
|
||||
commands = ["print.dialog"]
|
||||
tools = ["doc_print"]
|
||||
evidence = ["crates/print/src/tests.rs::multiple_pages_per_sheet", "crates/automation/tests/it/automation.rs::printing_through_tools", "crates/print/src/tests.rs::cut_stack_keeps_piles_in_order_and_blanks_in_place", "crates/print/src/tests.rs::cutting_and_stacking_recovers_every_selected_page", "crates/automation/tests/it/automation.rs::cut_stack_printing_through_tools", "crates/ui-egui/tests/it/print.rs::cut_stack_dialog_previews_saves_and_refuses_duplex"]
|
||||
notes = "2/4/6/9/16, four sequential orders, borders, auto-rotate; also single-sided cut-and-stack order with aligned gutter cut marks, blank padding and range/reverse support (an extension, not an Acrobat parity claim). Duplex cut-and-stack is refused."
|
||||
evidence = ["crates/print/src/tests.rs::multiple_pages_per_sheet", "crates/automation/tests/it/automation.rs::printing_through_tools", "crates/print/src/tests.rs::cut_stack_keeps_piles_in_order_and_blanks_in_place", "crates/print/src/tests.rs::cutting_and_stacking_recovers_every_selected_page", "crates/automation/tests/it/automation.rs::cut_stack_printing_through_tools", "crates/ui-egui/tests/it/print.rs::cut_stack_dialog_previews_saves_and_refuses_duplex", "crates/print/src/tests.rs::a_custom_grid_is_laid_out_as_given_on_the_chosen_sheet", "crates/automation/tests/it/automation.rs::custom_pages_per_sheet_prints_the_grid_as_given", "crates/ui-egui/tests/it/print.rs::custom_pages_per_sheet_takes_columns_by_rows"]
|
||||
notes = "2/4/6/9/16 (the sheet turns to suit the grid with Auto orientation) or Custom columns by rows, 1-99 each, laid out across and down the sheet as oriented (Auto prints portrait; doc_print cols/rows); four sequential orders, borders, auto-rotate; also single-sided cut-and-stack order with aligned gutter cut marks, blank padding and range/reverse support (an extension, not an Acrobat parity claim). Duplex cut-and-stack is refused."
|
||||
|
||||
[[feature]]
|
||||
id = "print.booklet"
|
||||
|
||||
Reference in new issue
Block a user