Skip to content

PDFBOX-6077: Add regression tests for stencil-mask pattern fills - #492

Draft
valerybokov wants to merge 3 commits into
apache:trunkfrom
valerybokov:fix-image-masks-tests
Draft

PDFBOX-6077: Add regression tests for stencil-mask pattern fills#492
valerybokov wants to merge 3 commits into
apache:trunkfrom
valerybokov:fix-image-masks-tests

Conversation

@valerybokov

Copy link
Copy Markdown

Summary

Adds regression tests for the two bugs fixed on the fix-image-masks branch (from which this branch is built): a stencil-mask image filled with a pattern, where either the pattern itself has gaps (e.g. between tiles) or a soft mask is applied to the pattern (#491).

What's added

  • pom.xml — two download-maven-plugin entries fetching the JIRA-attached test PDFs into target/pdfs, following the project's existing convention for issue-specific fixtures (SHA-512-pinned download, same pattern as the neighboring PDFBOX-4831 entry):
    • PDFBOX-6077-example.pdf (the originally reported file)
    • PDFBOX-5842-reduced.pdf (the related file a naive fix for the first bug alone regresses)
  • TestQuality.java — two new tests:
    • testPDFBox6077: renders example.pdf and asserts a pixel in a gap between the tiling pattern's tiles is white (0xFFFFFFFF), not opaque black. Confirmed this fails on pre-fix code (expected: <-1> but was: <-16777216>).
    • testPDFBox5842: renders PDFBOX-5842-reduced.pdf and asserts a pixel inside the soft-masked pattern's map-marker icon isn't blank white — guards against the soft-mask fix regressing (which an earlier, discarded fix attempt did).

This is a rough draft of the tests, as the POM file will likely need to be modified.


Per https://www.apache.org/legal/generative-tooling.html: portions of this PR were produced with assistance from Claude Code (Anthropic), based on a bug from PDFBOX Issue Tracker (6077).

I've reviewed the generated code and test, verified the test fails against the pre-fix implementation and passes against the fix, and confirm to the best of my knowledge that the output does not include any third-party copyrighted material and is compatible with the Apache License 2.0.

valerybokov and others added 3 commits July 27, 2026 18:09
A stencil image filled with a pattern draws the paint and the mask into
separate scratch images and then combines them. The combine step
unconditionally overwrote the paint's alpha with the mask's alpha, so any
pixel the pattern itself never painted into (e.g. the gaps between tiles
of a tiling pattern) turned opaque black instead of staying transparent.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
A soft mask's Paint/PaintContext looks up its backing raster using
absolute page-device pixel coordinates, fixed when the soft mask group
was rendered. The stencil-mask-with-pattern code renders into an
isolated scratch image rather than directly onto the page graphics, so
those coordinates no longer lined up and the soft mask silently applied
zero alpha everywhere, making the pattern disappear.

Unwrap the soft mask, fill the scratch image with its plain underlying
paint instead, and apply the soft mask's own alpha afterwards by
directly looking up its backing raster through a per-pixel device
transform, rather than relying on the Paint/PaintContext machinery that
assumed it was rendering onto the real page raster.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Downloads the two JIRA-attached PDFs exercising the alpha-combine and
soft-mask fixes, and asserts on specific pixels that distinguish the
fixed rendering from each bug: a gap between a tiling pattern's tiles
that must stay transparent, and a soft-masked pattern's icon that must
still be visible when used as a stencil mask fill.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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