Fix watermark not being gray, and fix watermark tests#351
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.