From 280584cc72c3d9c7ce56d4d3824cc62211cc2303 Mon Sep 17 00:00:00 2001 From: Hasan Date: Mon, 2 Nov 2026 18:27:08 +0500 Subject: [PATCH 1/2] M3: a snapshot keeps its resolution when zoomed out (#5716) A snapshot was drawn at the zoom on screen, so one taken with the page zoomed out came out too coarse to read. It is now drawn at 300 ppi, or at the zoom if that is finer, or as fine as the renderer draws in one tile: it stops at 4096 pixels a side and cuts a larger area short, which 300 ppi would reach on any area over about 983 pt a side. --- ROADMAP.md | 1 + crates/ui-egui/src/canvas/zoom_snap.rs | 51 ++++++++++++++++++++-- crates/ui-egui/tests/it/viewer.rs | 59 ++++++++++++++++++++++++++ docs/roadmap.md | 1 + parity/acrobat-features.toml | 4 +- 5 files changed, 111 insertions(+), 5 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index cf8cacb73e..7596bd5d3b 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -243,6 +243,7 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md - **2026-11-02 (M10, #5743):** macOS print jobs name their title and owner (`com.apple.print.JobInfo.PMJobName`, `PMJobOwner`), as the system print dialog does, because a Kyocera filter crashes on a job without them. Checked by a test and through `doc_print` against a stand-in `lp`; not yet on a physical printer. +- **2026-11-02 (M3, #5716):** A snapshot is drawn at 300 ppi, or at the zoom if that is finer, so one taken zoomed out stays readable. A choice of resolution and a selection that stays active remain. - **2026-11-02 (M14, #5737, #5460):** Preferences can turn off the update check at start. It stays on by default, and Help ▸ Check for updates still asks. - **2026-11-01 (M7, #5657):** Header/footer, watermark and background additions and replacements stage the complete call before committing. Synthetic later-page failures preserve exact incremental bytes, object count, dirty state and allocation cursor; success controls retain other marks and shared/inherited resources. Estimates unchanged. diff --git a/crates/ui-egui/src/canvas/zoom_snap.rs b/crates/ui-egui/src/canvas/zoom_snap.rs index a422907b89..a23f85a6a8 100644 --- a/crates/ui-egui/src/canvas/zoom_snap.rs +++ b/crates/ui-egui/src/canvas/zoom_snap.rs @@ -120,13 +120,13 @@ impl PdfCraftApp { Ok(()) } - /// Render `view_rect` (page view points) of `page` at the current zoom and copy it to the - /// clipboard (and keep it in `last_snapshot`). + /// Render `view_rect` (page view points) of `page` and copy it to the clipboard (and keep it + /// in `last_snapshot`), at the current zoom or [`SNAPSHOT_MIN_SCALE`] if that is finer. pub fn snapshot(&mut self, index: usize, page: usize, view_rect: [f32; 4]) -> Result<(u32, u32), String> { let view = &self.views[index]; let doc = self.session.get(view.id).ok_or("no document")?; let ppp = self.ctx.as_ref().map_or(2.0, |c| c.pixels_per_point()); - let scale = (view.zoom * ppp).clamp(0.5, 8.0); + let scale = snapshot_scale((view.zoom * ppp).clamp(0.5, 8.0), view_rect[2] - view_rect[0], view_rect[3] - view_rect[1]); let tile = Tile { x: (view_rect[0] * scale).floor().max(0.0) as u32, y: (view_rect[1] * scale).floor().max(0.0) as u32, @@ -153,6 +153,20 @@ impl PdfCraftApp { } } +/// The fewest pixels per point a snapshot is drawn at: 300 ppi, so what it copies stays readable +/// however far the page is zoomed out (#5716). +const SNAPSHOT_MIN_SCALE: f32 = 300.0 / 72.0; + +/// The longest side a snapshot has, in pixels: the renderer draws at most 4096 a side in one tile +/// and cuts a larger area short, and this leaves room for rounding up. +const SNAPSHOT_MAX_SIDE: f32 = 4095.0; + +/// The pixels per point to draw a `width` × `height` point area at, given the `on_screen` scale: +/// the finer of that and the minimum, or as fine as the renderer can draw the whole area. +fn snapshot_scale(on_screen: f32, width: f32, height: f32) -> f32 { + on_screen.max(SNAPSHOT_MIN_SCALE).min(SNAPSHOT_MAX_SIDE / width.max(height).max(1.0)).max(0.01) +} + /// The normalised bounds [u0, v0, u1, v1] of the pixels that aren't (near) white, if any. pub(crate) fn ink_bounds(w: usize, h: usize, rgba: &[u8]) -> Option<[f32; 4]> { if w == 0 || h == 0 || rgba.len() < w * h * 4 { @@ -175,6 +189,37 @@ pub(crate) fn ink_bounds(w: usize, h: usize, rgba: &[u8]) -> Option<[f32; 4]> { #[cfg(test)] mod tests { + use super::{SNAPSHOT_MAX_SIDE, SNAPSHOT_MIN_SCALE, snapshot_scale}; + + #[test] + fn a_snapshot_is_drawn_at_the_finer_of_the_zoom_and_the_minimum() { + assert_eq!(snapshot_scale(0.5, 100.0, 100.0), SNAPSHOT_MIN_SCALE, "zoomed out"); + assert_eq!(snapshot_scale(SNAPSHOT_MIN_SCALE, 100.0, 100.0), SNAPSHOT_MIN_SCALE); + assert_eq!(snapshot_scale(8.0, 100.0, 100.0), 8.0, "zoomed in further, it keeps the detail on screen"); + } + + #[test] + fn a_snapshot_stays_within_what_the_renderer_draws_at_once() { + // Past 983 pt a side, 300 ppi is more than one tile holds. + for (on_screen, w, h) in [(1.0, 2384.0, 3370.0), (1.0, 3370.0, 100.0), (8.0, 1000.0, 1000.0), (8.0, 14_400.0, 14_400.0)] { + let scale = snapshot_scale(on_screen, w, h); + let side = (w * scale).ceil().max((h * scale).ceil()); + assert!(side <= SNAPSHOT_MAX_SIDE + 1.0, "{on_screen} on {w} × {h}: {side} pixels"); + } + } + + #[test] + fn a_snapshot_of_no_area_is_drawn_at_the_minimum() { + assert_eq!(snapshot_scale(1.0, 0.0, 0.0), SNAPSHOT_MIN_SCALE); + } + + #[test] + fn a_snapshot_scale_survives_numbers_that_are_not() { + for scale in [snapshot_scale(f32::NAN, 5000.0, 5000.0), snapshot_scale(1.0, f32::NAN, 100.0), snapshot_scale(1.0, f32::INFINITY, 100.0)] { + assert!(scale.is_finite() && scale > 0.0, "{scale}"); + } + } + #[test] fn ink_bounds_finds_the_marked_area() { let (w, h) = (10, 20); diff --git a/crates/ui-egui/tests/it/viewer.rs b/crates/ui-egui/tests/it/viewer.rs index d383582915..7ab88d5888 100644 --- a/crates/ui-egui/tests/it/viewer.rs +++ b/crates/ui-egui/tests/it/viewer.rs @@ -968,6 +968,65 @@ fn marquee_zoom_and_snapshot() { assert!(after > before * 2.0, "{before} → {after}"); } +/// #5716: what a snapshot holds doesn't depend on how far the page is zoomed out. +#[test] +fn a_snapshot_keeps_its_resolution_when_zoomed_out() { + let mut h = harness(); + let i = h.state().active.unwrap(); + h.state_mut().system_clipboard = false; + let mut sizes = Vec::new(); + for zoom in ["25", "100"] { + h.state_mut().set_option("zoom", zoom).unwrap(); + h.run_steps(2); + // The text line of the page, as a marquee would give it. + sizes.push(h.state_mut().snapshot(i, 0, [15.0, 125.0, 180.0, 160.0]).expect("a snapshot")); + } + assert_eq!(sizes[0], sizes[1], "the same pixels at either zoom"); + assert_eq!(sizes[0], (688, 146), "165 × 35 pt at 300 ppi"); + let (_, _, px) = h.state().last_snapshot.clone().expect("a snapshot"); + assert!(px.as_chunks::<4>().0.iter().any(|p| p[0] < 100), "the text is in it"); + + // Zoomed in past the minimum, a snapshot still has what the screen shows. + h.state_mut().set_option("zoom", "800").unwrap(); + h.run_steps(2); + let (w, _) = h.state_mut().snapshot(i, 0, [15.0, 125.0, 180.0, 160.0]).expect("a snapshot"); + assert!(w > sizes[0].0, "{w}"); +} + +/// #5716: at 300 ppi this page is more than the renderer draws in one tile, which would cut off +/// the side the snapshot was taken for. A 2000 pt square with a black mark in its far corner. +#[test] +fn a_snapshot_of_a_large_page_reaches_its_far_corner() { + let stream = "0 0 0 rg 1900 0 100 100 re f"; + let pdf = format!( + "%PDF-1.7 +1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj +2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj +3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 2000 2000] /Contents 4 0 R >> endobj +4 0 obj << /Length {} >> stream +{stream} +endstream endobj +trailer << /Root 1 0 R >> +%%EOF", + stream.len() + ); + let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(move |_cc| { + let mut app = PdfCraftApp::new(); + app.set_option("language", "en").unwrap(); + app.open_bytes("large.pdf", None, pdf.into_bytes()).unwrap(); + app.system_clipboard = false; + app + }); + h.run_steps(4); + let i = h.state().active.unwrap(); + let (w, hgt) = h.state_mut().snapshot(i, 0, [0.0, 0.0, 2000.0, 2000.0]).expect("a snapshot"); + assert!(w <= 4096 && hgt <= 4096 && w == hgt, "{w} × {hgt}"); + let (_, _, px) = h.state().last_snapshot.clone().expect("a snapshot"); + let at = |x: u32, y: u32| px[((y * w + x) * 4) as usize]; + assert!(at(w * 98 / 100, hgt * 98 / 100) < 100, "the mark in the far corner is in it"); + assert!(at(w / 2, hgt / 2) > 200, "and the page around it is white"); +} + #[test] fn fit_visible_zooms_to_the_content_width() { let mut h = harness(); diff --git a/docs/roadmap.md b/docs/roadmap.md index a7f4a86b7e..92573aa0bb 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -314,6 +314,7 @@ Estimates unchanged. | 2026-11-03 | patch | M5 #5850 review: indirect typewriter intent and composer edits preserve outer whitespace; movement regression commits by outside click; estimates unchanged. | | 2026-11-03 | patch | M5 #5850: Enter adds Fill & Sign line breaks; outside clicks commit, Escape cancels, and saved multiline appearances retain their text and height; estimates unchanged. | | 2026-11-02 | patch | M10 #5743: macOS print jobs carry the job name and owner some vendors' filters need; not yet checked on a physical printer | +| 2026-11-02 | patch | M3 #5716: a snapshot keeps its resolution when zoomed out; a choice of resolution remains | | 2026-11-02 | patch | M14 #5737, #5460: Preferences turns off the update check at start, on by default | | 2026-11-01 | patch | M7 #5657: header/footer, watermark and background operations commit all selected pages together; later-page errors preserve marks, content, shared/inherited resources and pending edits; estimates unchanged. | | 2026-10-31 | patch | #1577: reconcile optional page shadows with current viewer/organizer and settings modules; CI validation pending. | diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 5cb6e1c56a..34d65d88e0 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -1586,8 +1586,8 @@ milestone = "M3" status = "shipped" commands = ["edit.snapshot"] tools = ["page_render"] -evidence = ["crates/ui-egui/tests/it/viewer.rs::marquee_zoom_and_snapshot"] -notes = "copies the area at the current zoom to the clipboard as an image" +evidence = ["crates/ui-egui/tests/it/viewer.rs::marquee_zoom_and_snapshot", "crates/ui-egui/tests/it/viewer.rs::a_snapshot_keeps_its_resolution_when_zoomed_out", "crates/ui-egui/src/canvas/zoom_snap.rs::a_snapshot_is_drawn_at_the_finer_of_the_zoom_and_the_minimum", "crates/ui-egui/src/canvas/zoom_snap.rs::a_snapshot_stays_within_what_the_renderer_draws_at_once", "crates/ui-egui/tests/it/viewer.rs::a_snapshot_of_a_large_page_reaches_its_far_corner"] +notes = "copies the area to the clipboard as an image, at 300 ppi or the current zoom if that is finer (#5716), or as fine as the renderer draws in one tile (4096 pixels a side), drawn while the app waits. Missing: a choice of resolution, and a selection that stays active to copy later" [[feature]] id = "view.copy-image" From 7380241724f49d41c17b9871bacf8cee175af43d Mon Sep 17 00:00:00 2001 From: Hasan Date: Mon, 2 Nov 2026 21:30:30 +0500 Subject: [PATCH 2/2] M3: a snapshot uses the scale the page is drawn at (#5716) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review of #5761: the scale came from zoom × device pixels, without the 96/72 the viewer draws at, and was capped at 8, so a snapshot zoomed in held fewer pixels than the screen showed: 417 against 534 for 100 pt at 400%. It now takes the viewer's own render scale, and the tile limit is what stops it. The roadmap entry says when 300 ppi can't be reached. --- ROADMAP.md | 2 +- crates/ui-egui/src/canvas/zoom_snap.rs | 2 +- crates/ui-egui/tests/it/viewer.rs | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 7596bd5d3b..84dfb3f489 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -243,7 +243,7 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md - **2026-11-02 (M10, #5743):** macOS print jobs name their title and owner (`com.apple.print.JobInfo.PMJobName`, `PMJobOwner`), as the system print dialog does, because a Kyocera filter crashes on a job without them. Checked by a test and through `doc_print` against a stand-in `lp`; not yet on a physical printer. -- **2026-11-02 (M3, #5716):** A snapshot is drawn at 300 ppi, or at the zoom if that is finer, so one taken zoomed out stays readable. A choice of resolution and a selection that stays active remain. +- **2026-11-02 (M3, #5716):** A snapshot is drawn at 300 ppi, or at the zoom if that is finer, so one taken zoomed out stays readable; an area too large for one 4096-pixel tile comes out as fine as a tile allows (about 147 ppi for 2000 pt). A choice of resolution and a selection that stays active remain. - **2026-11-02 (M14, #5737, #5460):** Preferences can turn off the update check at start. It stays on by default, and Help ▸ Check for updates still asks. - **2026-11-01 (M7, #5657):** Header/footer, watermark and background additions and replacements stage the complete call before committing. Synthetic later-page failures preserve exact incremental bytes, object count, dirty state and allocation cursor; success controls retain other marks and shared/inherited resources. Estimates unchanged. diff --git a/crates/ui-egui/src/canvas/zoom_snap.rs b/crates/ui-egui/src/canvas/zoom_snap.rs index a23f85a6a8..93e0b13210 100644 --- a/crates/ui-egui/src/canvas/zoom_snap.rs +++ b/crates/ui-egui/src/canvas/zoom_snap.rs @@ -126,7 +126,7 @@ impl PdfCraftApp { let view = &self.views[index]; let doc = self.session.get(view.id).ok_or("no document")?; let ppp = self.ctx.as_ref().map_or(2.0, |c| c.pixels_per_point()); - let scale = snapshot_scale((view.zoom * ppp).clamp(0.5, 8.0), view_rect[2] - view_rect[0], view_rect[3] - view_rect[1]); + let scale = snapshot_scale(view.render_scale(ppp), view_rect[2] - view_rect[0], view_rect[3] - view_rect[1]); let tile = Tile { x: (view_rect[0] * scale).floor().max(0.0) as u32, y: (view_rect[1] * scale).floor().max(0.0) as u32, diff --git a/crates/ui-egui/tests/it/viewer.rs b/crates/ui-egui/tests/it/viewer.rs index 7ab88d5888..f2c812ce78 100644 --- a/crates/ui-egui/tests/it/viewer.rs +++ b/crates/ui-egui/tests/it/viewer.rs @@ -986,11 +986,15 @@ fn a_snapshot_keeps_its_resolution_when_zoomed_out() { let (_, _, px) = h.state().last_snapshot.clone().expect("a snapshot"); assert!(px.as_chunks::<4>().0.iter().any(|p| p[0] < 100), "the text is in it"); - // Zoomed in past the minimum, a snapshot still has what the screen shows. - h.state_mut().set_option("zoom", "800").unwrap(); - h.run_steps(2); - let (w, _) = h.state_mut().snapshot(i, 0, [15.0, 125.0, 180.0, 160.0]).expect("a snapshot"); - assert!(w > sizes[0].0, "{w}"); + // Zoomed in past the minimum, a snapshot has every pixel the screen shows, however far. + let ppp = h.ctx.pixels_per_point(); + for zoom in [400.0_f32, 1600.0] { + h.state_mut().set_option("zoom", &zoom.to_string()).unwrap(); + h.run_steps(2); + let (w, _) = h.state_mut().snapshot(i, 0, [15.0, 125.0, 180.0, 160.0]).expect("a snapshot"); + let on_screen = (165.0 * zoom / 100.0 * pdfcraft_ui_egui::canvas::PT * ppp).ceil() as u32; + assert!(w.abs_diff(on_screen) <= 1, "{w} pixels at {zoom}%, {on_screen} on screen"); + } } /// #5716: at 300 ppi this page is more than the renderer draws in one tile, which would cut off