diff --git a/pdfbox/pom.xml b/pdfbox/pom.xml
index ed7396f4a25..340dd3328c1 100644
--- a/pdfbox/pom.xml
+++ b/pdfbox/pom.xml
@@ -994,6 +994,45 @@
2ee83beb6658792c6b963010462515ff1187aafe64930c1a7465dc26e86ab5236dc98cb006986e5fcd60876bedef7f00e4e1cb86bbf590bba000a00187af0ee3
+
+ PDFBOX-6077-1
+ generate-test-resources
+
+ wget
+
+
+ https://issues.apache.org/jira/secure/attachment/13078553/example.pdf
+ ${project.build.directory}/pdfs
+ PDFBOX-6077-example.pdf
+ f4faaa68062073ffdfd48119563f1e1a6eff6d9a063188dc2ec59ccc747277fcaa6139936cebf2f3f7b1b99b80ca13934fb4568658a169e0bf25bf4e748de101
+
+
+
+ PDFBOX-6077-2
+ generate-test-resources
+
+ wget
+
+
+ https://issues.apache.org/jira/secure/attachment/13078557/PDFBOX-5842-reduced.pdf
+ ${project.build.directory}/pdfs
+ PDFBOX-5842-reduced.pdf
+ c66b13230d343d6b0a2de81680f5d1ae7f8d92713acbc453ff36fe085831fa89127e0428d297e7494b87fc932ca8a721744db1fe79a41cc5c3cf7d631fc209fc
+
+
+
+ PDFBOX-5403
+ generate-test-resources
+
+ wget
+
+
+ https://issues.apache.org/jira/secure/attachment/13041734/bad+rendering.pdf
+ ${project.build.directory}/pdfs
+ PDFBOX-5403-bad-rendering.pdf
+ 0d7160a4af04bf2f785bf4155f69876da4b7ff7a196e7eda1eb904c02c35aa03c31041d9339fda90322cb58bde16b87bae8460c617bfe5b8dc0670ddab102f62
+
+
diff --git a/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java b/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
index 8a9b18cc277..af18a07ebbc 100644
--- a/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
+++ b/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
@@ -56,4 +56,74 @@ void testPDFBox4831() throws IOException
ValidateXImage.checkIdent(extractedImage, renderedImage);
}
}
+
+ /**
+ * PDFBOX-6077: a stencil mask filled with a pattern must not paint the gaps between the
+ * pattern's own tiles as opaque black. Before the fix, the stencil mask's alpha overwrote
+ * the pattern paint's own alpha instead of being combined with it, so any pixel the pattern
+ * didn't itself draw into turned solid black instead of staying transparent.
+ *
+ * @throws IOException
+ */
+ @Test
+ void testPDFBox6077() throws IOException
+ {
+ File file = new File(TARGET_PDF_DIR, "PDFBOX-6077-example.pdf");
+ try (PDDocument doc = Loader.loadPDF(file))
+ {
+ PDFRenderer renderer = new PDFRenderer(doc);
+ BufferedImage renderedImage = renderer.renderImageWithDPI(0, 100);
+ // a gap between the tiling pattern's own painted tiles, which must stay transparent
+ // (i.e. show the white page background) instead of turning opaque black
+ Assertions.assertEquals(0xFFFFFFFF, renderedImage.getRGB(280, 23));
+ }
+ }
+
+ /**
+ * PDFBOX-6077: a soft mask applied to a pattern that is used as a stencil mask fill must
+ * still be visible. Such a pattern is rendered into a separate scratch image rather than
+ * directly onto the page, and the soft mask's own alpha lookup is keyed to absolute
+ * page-device pixel coordinates, so a naive implementation renders it as fully transparent.
+ *
+ * @throws IOException
+ */
+ @Test
+ void testPDFBox5842() throws IOException
+ {
+ File file = new File(TARGET_PDF_DIR, "PDFBOX-5842-reduced.pdf");
+ try (PDDocument doc = Loader.loadPDF(file))
+ {
+ PDFRenderer renderer = new PDFRenderer(doc);
+ BufferedImage renderedImage = renderer.renderImageWithDPI(0, 100);
+ // a pixel within the soft-masked pattern's map marker icon; if the soft mask's alpha
+ // lookup is broken, this whole region renders as blank white instead
+ Assertions.assertNotEquals(0xFFFFFFFF, renderedImage.getRGB(267, 1329));
+ }
+ }
+
+ /**
+ * PDFBOX-5403: a stencil mask filled with a pattern repeated many times over a large area
+ * (e.g. one tiling-pattern-filled image per line of text) must not show a hairline seam
+ * between the pattern's own tiles as a visible gap. Combining the mask's alpha with the
+ * pattern's own alpha (see testPDFBox6077) can expose such a seam as a light gray line
+ * cutting through otherwise-solid text, if it isn't first smoothed over.
+ *
+ * @throws IOException
+ */
+ @Test
+ void testPDFBox5403() throws IOException
+ {
+ File file = new File(TARGET_PDF_DIR, "PDFBOX-5403-bad-rendering.pdf");
+ try (PDDocument doc = Loader.loadPDF(file))
+ {
+ PDFRenderer renderer = new PDFRenderer(doc);
+ BufferedImage renderedImage = renderer.renderImageWithDPI(2, 100);
+ // a pixel within a line of text rendered via a pattern-filled stencil mask; a
+ // hairline tile-boundary seam previously showed through as a washed-out gray streak
+ int rgb = renderedImage.getRGB(159, 115);
+ int red = (rgb >> 16) & 0xFF;
+ Assertions.assertTrue(red < 100,
+ "expected a dark text pixel but was too light: " + Integer.toHexString(rgb));
+ }
+ }
}