Skip to content

Fix watermark not being gray, and fix watermark tests#351

Merged
norbusan merged 2 commits into
masterfrom
watermark-fix-gray-color
Jul 19, 2026
Merged

Fix watermark not being gray, and fix watermark tests#351
norbusan merged 2 commits into
masterfrom
watermark-fix-gray-color

Conversation

@norbusan

Copy link
Copy Markdown
Collaborator

The rewrite of the watermark code from pymupdf to pdf_oxide broke
watermark color due to insufficiencies of the pdf_oxide library.

Fix the color by injecting the color code, add unittests for the
watermark color.

Fix also other failing watermark tests.

norbusan added 2 commits July 19, 2026 10:29
pdf_oxide's inline_color() lays down the watermark glyphs but emits no
fill-color operator, so the text rendered in the default black instead of
the requested #808080 gray. Setting the color on the composite side (rg
before the Do that draws the XObject) does not help either: pdf_oxide's
renderer ignores fill color inherited into a Form XObject.

Inject a "r g b rg" operator at the start of the overlay's own content
stream so the color is intrinsic to the watermark page and renders
identically in every viewer. pikepdf's save is deterministic, so output
stays reproducible.

Add regression tests asserting the default stamp renders as #808080 gray
(not black) and that a caller-supplied fcolor is honored.
The watermark is composited as a rotated (90 deg) Form XObject. pdf_oxide's
to_plain_text()/extract_text() drop rotated-XObject spans during reading-
order assembly (they collapse to zero spans), so the text-presence check
always saw an empty string and every TestCustomFont case failed. This broke
when the watermark switched from pymupdf to pdf_oxide.

Reconstruct the watermark string with extract_chars() instead, which
recovers every glyph via the font's ToUnicode CMap, ordering the chars
bottom-to-top (ascending origin_y) the way the vertical watermark reads.
@norbusan
norbusan merged commit 13915ed into master Jul 19, 2026
1 check passed
@norbusan
norbusan deleted the watermark-fix-gray-color branch July 19, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant