From a4c53f706f433415c0fed8d0b2c210f3af109065 Mon Sep 17 00:00:00 2001 From: Marco Arnulfo <103679419+marcoarnulfo@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:55:39 +0200 Subject: [PATCH] fix(ui): Current page prints the viewed page, not a page labelled with its number (#1308) (#1411) The Print dialog turned Current page into the range "N" for the page on screen, and ranges read numbers as page labels first. In a document labelled i, ii, iii, 1, 2, viewing the first page printed the fourth, whose label is "1". Current page is now passed as a position, the way Selected pages is, through print::select_listed. A typed range still reads labels first. Adds print_ui::tests::current_page_is_the_viewed_page_not_a_label, which fails before this change. --- crates/ui-egui/src/print_ui.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/print_ui.rs b/crates/ui-egui/src/print_ui.rs index 129dd080..5b086495 100644 --- a/crates/ui-egui/src/print_ui.rs +++ b/crates/ui-egui/src/print_ui.rs @@ -129,15 +129,15 @@ impl PrintDraft { return Err("Cut and stack needs Two-sided: Off. Print single-sided sheets.".into()); } let range = match self.which { - Which::All | Which::Selected => None, - Which::Current => Some(self.current_page.saturating_add(1).to_string()), + Which::All | Which::Selected | Which::Current => None, Which::Range => Some(self.range.clone()), }; - let pages = if self.which == Which::Selected { - // Positions, not a typed range: a range would read numbers as page labels first. - print::select_listed(count, &self.selected, self.subset, self.reverse) - } else { - print::select_pages(count, range.as_deref(), labels, self.subset, self.reverse) + // Selected and Current are positions, not a typed range: a range would read numbers as + // page labels first. + let pages = match self.which { + Which::Selected => print::select_listed(count, &self.selected, self.subset, self.reverse), + Which::Current => print::select_listed(count, &[self.current_page], self.subset, self.reverse), + Which::All | Which::Range => print::select_pages(count, range.as_deref(), labels, self.subset, self.reverse), } // What the person got wrong about what to print is said in their language: the engine hands // the wording over whole and the page numbers apart from it. @@ -1037,6 +1037,19 @@ mod tests { assert_eq!(PrintDraft::default().job("report.pdf").duplex, Some(spool::Duplex::Off)); } + /// Issue #1308: Current page is the page on screen, even when a later page is labelled with + /// its number. A typed range still reads labels first. + #[test] + fn current_page_is_the_viewed_page_not_a_label() { + let labels: Vec = ["i", "ii", "iii", "1", "2"].map(String::from).to_vec(); + for (current, want) in [(0, vec![0]), (1, vec![1]), (3, vec![3])] { + let d = PrintDraft { which: Which::Current, current_page: current, ..PrintDraft::default() }; + assert_eq!(d.settings(5, &labels).map(|s| s.pages), Ok(want), "viewing page {}", current + 1); + } + let typed = PrintDraft { which: Which::Range, range: "1".into(), ..PrintDraft::default() }; + assert_eq!(typed.settings(5, &labels).map(|s| s.pages), Ok(vec![3])); + } + #[test] fn print_preview_rasters_stay_within_the_texture_limit() { // Actual size on a 14,400 pt (200 in) page would ask for a raster far past any texture.