fix(pdf): BEHIND_CONTENT watermark opacity no longer bleeds into page content#159
Merged
Conversation
… content The watermark renderer set its low-alpha graphics state inside a prepended content stream without a save/restore pair. PDFBox's resetContext flag only isolates APPEND streams, so the alpha constant leaked into the original page stream and washed out every element on the page. Wrap the watermark drawing in q/Q. Regression test renders a solid shape under a BEHIND_CONTENT watermark and asserts the fill samples at full strength while the watermark keeps its own low-alpha ExtGState.
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.
Problem
A
BEHIND_CONTENTwatermark renders through a PREPEND content stream. The renderer set the watermark opacity via ExtGState there without aq/Qpair — and PDFBox'sresetContextflag only isolates APPEND streams. The low alpha constant leaked into the original page stream, washing out the entire page (everything rendered at the watermark's opacity, except elements that set their own alpha).Since
DocumentWatermarkdefaults tolayer = BEHIND_CONTENT, every document using a default watermark was affected. Found while verifying the feature-catalog render: the whole page was ghosted except the translucency demo chips.Fix
PdfWatermarkRenderer.applynow wraps the watermark drawing insaveGraphicsState()/restoreGraphicsState().Tests
PdfWatermarkStateIsolationTest: renders a solid navy shape under aBEHIND_CONTENTwatermark at opacity 0.05, asserts the shape centre samples at full strength (pixel check) and the watermark still carries its low-alpha ExtGState. Verified the test fails on the unfixed renderer and passes with the fix.