From 4de9459f2f696238ca318c8553ec962299712e05 Mon Sep 17 00:00:00 2001 From: eliets2 <287273517+eliets2@users.noreply.github.com> Date: Wed, 21 Oct 2026 21:48:08 +0300 Subject: [PATCH] Give the print preview's grayscale tag a bit of its own The preview was always monochrome, so the Print in grayscale checkbox appeared to do nothing but flicker between the colour thumbnail and the (wrongly) greyed sheet raster. Move GRAYSCALE_TAG to a free tag bit (1 << 59) so it no longer overlaps PRINT_TAG, and let the colour and grayscale preview requests carry different tags so set_print_grayscale actually re-renders the right one. Test: print_preview_tag_distinguishes_grayscale_from_colour failed before the change and passes after. --- crates/ui-egui/src/canvas.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index eb9244a28..71e6d091a 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -26,8 +26,10 @@ const TEXT_TAG: u64 = 1 << 62; /// A page rendered for the organize grid at the size it is drawn there. const GRID_TAG: u64 = 1 << 61; /// Preview rasters tagged with this bit are converted to luminance on receipt, matching the -/// monochrome print requested by Print ▸ Print in grayscale. -const GRAYSCALE_TAG: u64 = 1 << 60; +/// monochrome print requested by Print ▸ Print in grayscale. It is a bit of its own: the +/// renderer's print bit ([`PRINT_TAG`]) is carried by every print preview, so sharing it would +/// turn colour previews into monochrome ones too. +const GRAYSCALE_TAG: u64 = 1 << 59; /// The tag of a raster that is out of date (shown until its replacement arrives). const STALE_TAG: u64 = u64::MAX; /// Pages whose raster would exceed this many device pixels on a side are drawn in tiles. @@ -5845,6 +5847,25 @@ trailer << /Root 1 0 R >> } } + /// A print preview carries the renderer's print bit; the bit that asks for luminance is + /// its own, so a colour preview is not converted to monochrome and the two modes are told + /// apart by their tags. + #[test] + fn print_preview_tag_distinguishes_grayscale_from_colour() { + let mut v = view(1, PageLayout::Single, true); + v.set_print_grayscale(false); + v.queue_print_previews(&[(0, 1.0)]); + let colour = v.frame_queue.last().expect("a print preview was queued").tag; + assert_ne!(colour & PRINT_TAG, 0, "a print preview carries the renderer's print bit"); + assert_eq!(colour & GRAYSCALE_TAG, 0, "a colour print preview must not ask for luminance"); + + v.set_print_grayscale(true); + v.queue_print_previews(&[(0, 1.0)]); + let gray = v.frame_queue.last().expect("a grayscale print preview was queued").tag; + assert_ne!(gray & GRAYSCALE_TAG, 0, "a grayscale print preview asks for luminance"); + assert_ne!(gray, colour, "the two print preview modes must not share a tag"); + } + #[test] fn thumbnails_release_on_scroll_panel_close_and_request_again_after_eviction() { let ctx = egui::Context::default();