From 934d83405cd5af745c96a9ade0099e817d6967b3 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 12 Oct 2026 13:56:54 +0700 Subject: [PATCH] Part of #1286: constant alpha masks are drawn white, so the page shows where soft masks are read by luminosity A CMYK page with transparency is drawn through an alpha soft mask that covers the page (a non-isolated group). Its cover was black: opaque as alpha, but nothing shows in a reader that takes the mask's luminosity. A white cover is the same mask either way. --- crates/pdf/src/export.rs | 3 ++- crates/pdf/src/tests_cmykblend.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/pdf/src/export.rs b/crates/pdf/src/export.rs index 15a1e213..990fc3cb 100644 --- a/crates/pdf/src/export.rs +++ b/crates/pdf/src/export.rs @@ -605,10 +605,11 @@ fn cover(s: &mut Surface, page: Rect, level: u8, opacity: f32) { /// An alpha mask of constant `alpha` over the page. A group drawn through it is a transparency /// group of that opacity that, unlike the writer's opacity groups, is not isolated. +/// The cover is white, so a reader that takes every soft mask as a luminosity mask shows the same. fn constant_mask(s: &mut Surface, page: Rect, alpha: f32) -> krilla::mask::Mask { let mut sb = s.stream_builder(); let mut ms = sb.surface(); - cover(&mut ms, page, 0, alpha); + cover(&mut ms, page, 255, alpha); ms.finish(); krilla::mask::Mask::new(sb.finish(), krilla::mask::MaskType::Alpha) } diff --git a/crates/pdf/src/tests_cmykblend.rs b/crates/pdf/src/tests_cmykblend.rs index f76d9081..03fcad84 100644 --- a/crates/pdf/src/tests_cmykblend.rs +++ b/crates/pdf/src/tests_cmykblend.rs @@ -76,3 +76,12 @@ fn soft_mask_groups_keep_screen_luminance() { // The page's group blends in CMYK; the mask's group measures luminance in RGB. assert!(t.contains("/CS/DeviceCMYK") && t.contains("/S/Luminosity") && t.contains("/CS/DeviceRGB"), "{t}"); } + +#[test] +fn constant_alpha_masks_are_white() { + // #1286: a black cover hides the whole page in readers that take the mask's luminosity. + for grouped in [true, false] { + let t = text(&doc(ColorMode::Cmyk, grouped)); + assert!(t.contains("/S/Alpha") && t.contains("111rg") && !t.contains("000rg"), "grouped {grouped}: {t}"); + } +}