Files
pdfcraft/crates
ad27770a23 fix(ui): the watermark and background previews show a file's picture (#2817) (#8679)
* fix(ui): the watermark and background previews show a file's picture (#2817)

The Add Watermark and Add Background dialogs previewed a mark taken
from a file (an image, or a page of a PDF) as a grey frame with the
file name, so its size, offset, turn and opacity could not be judged
before OK. The preview now draws the picture itself, where OK puts it.

The engine's new mark_picture brings the file in the way OK does
(mark_source: an image turned upright by its EXIF orientation, a PDF
page as an upright form), draws it alone on a page of its shape and
renders it small, once on white paper and once over black, so its own
transparency survives. The dialog renders it on a worker thread, keeps
it in the draft as a texture keyed by the file and the page, and shows
the frame with the file name until it arrives or when the file can't
be drawn. It is laid out as picture() in pdfcraft-edit lays it out:
fitted to the page at the scale, centred plus the offset, turned, at
the opacity. A watermark on top is drawn over the page. A background,
or a watermark behind the page, shows where the page is white: the
page's picture is multiplied by the picture, averaged over a fine
grid, as a background colour already tints it.

Item 14 of #2817.

* deps: ctutils 0.4.5 for RUSTSEC-2026-0385

* parity: evidence paths where main moved the tests (tests/it/)

* style: cargo fmt after the merge

* engine: the picture sheet's black background has no backdrop to replace (main's new Background field)

* engine: the mark-picture tests encode their PNGs with craft-image-codecs, as the engine does since main dropped the png crate

* fix(ui): a file background previews nowhere the page's own backdrop hides it

The colour tint already left out pages that keep their backdrop: a scan, or a
white backdrop with Replace unticked. The picture did not, so the preview
showed a background OK would not. backdrop_hides is now the one test both use,
and such a page previews with no picture at all.

The new test fails with the check removed ("page 1 keeps its backdrop").

Raised by CodeRabbit on #3024.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ui): a mark from a file is clipped at the page edge in the preview

OK crops a watermark or background at the page edge, but the preview drew it
under the pane's clip, so a scaled, offset or turned mark ran past the page
into the pane. It is now drawn with the clip narrowed to the page.

The test uses the landscape page, where the pane is taller than the page, and
fails with the clip removed.

Raised by CodeRabbit on #3024.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ui): a picture behind the page shows only where the page paints nothing

The watermark and background previews drew a file's picture behind the
page by tinting the page picture with it, so the page's own colours were
multiplied by the picture: an opaque blue box over a red picture previewed
black, though after OK it stays blue.

The preview now paints white paper, the picture, then the page rendered
on a transparent sheet (Document::pages_on_glass), which is clear only
where the page paints nothing. The sheet drops the marks an Update
replaces and, for a background with Replace ticked, the white backdrops
OK replaces. Until the sheet is rendered nothing is drawn behind the
page. The per-cell averaging grid the tint needed goes.

a_picture_behind_the_page_is_covered_where_the_page_paints reads what
the preview's meshes show at the box: with the old preview it fails
(#00_00_00_FF, black). the_pages_on_glass_are_clear_only_where_they_paint_nothing
fails with the sheet rendered opaque (alpha 255 on bare paper).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ui): render a page sheet only at a positive, finite scale

A zero, negative or non-finite preview scale no longer reaches
render_page: glass_scale refuses it and the picture behind the page
is simply not drawn. The engine gains a test that pages_on_glass with
replace_backdrops takes a page's own white backdrop away.

Revert proof: with glass_scale returning Some for every scale,
a_sheet_is_rendered_only_at_a_positive_finite_scale fails (Some(0)
for 0.0); with replace_backdrops ignored,
the_pages_on_glass_lose_the_white_backdrop_a_background_replaces
fails (alpha 255 on bare paper).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(ui): read mesh triangles with as_chunks

Clippy on the CI toolchain rejects chunks_exact with a constant size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ui): show the file name while a picture's page sheet is missing

A picture placed behind the page draws on the page's transparent sheet.
While that sheet renders, or when it can't be rendered, the preview fell
back to Layer::Hidden and drew nothing, the same as a mark the page's own
backdrop hides. The user saw no sign of the picture they had chosen.

file_layer now returns None when the sheet is missing, so the overlay
takes its name-frame arm. A picture the backdrop hides is still not drawn,
and asks for no sheet. The sheet is rendered only when there is a picture.

Test: a_picture_behind_a_page_whose_sheet_is_missing_shows_the_file_name_frame.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Format marks_ui.rs after the merge with main

rustfmt joins the overlay() signature onto one line (the merge with main left it split).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SqmHYx8FiWM5PcsoiErgp9

---------

Co-authored-by: Guillem Hermida <[email protected]>
Co-authored-by: KenM76 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-12-04 14:23:37 +01:00
..
2026-11-26 23:00:01 +07:00