Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions pdfbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,45 @@
<sha512>2ee83beb6658792c6b963010462515ff1187aafe64930c1a7465dc26e86ab5236dc98cb006986e5fcd60876bedef7f00e4e1cb86bbf590bba000a00187af0ee3</sha512>
</configuration>
</execution>
<execution>
<id>PDFBOX-6077-1</id>
<phase>generate-test-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://issues.apache.org/jira/secure/attachment/13078553/example.pdf</url>
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
<outputFileName>PDFBOX-6077-example.pdf</outputFileName>
<sha512>f4faaa68062073ffdfd48119563f1e1a6eff6d9a063188dc2ec59ccc747277fcaa6139936cebf2f3f7b1b99b80ca13934fb4568658a169e0bf25bf4e748de101</sha512>
</configuration>
</execution>
<execution>
<id>PDFBOX-6077-2</id>
<phase>generate-test-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://issues.apache.org/jira/secure/attachment/13078557/PDFBOX-5842-reduced.pdf</url>
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
<outputFileName>PDFBOX-5842-reduced.pdf</outputFileName>
<sha512>c66b13230d343d6b0a2de81680f5d1ae7f8d92713acbc453ff36fe085831fa89127e0428d297e7494b87fc932ca8a721744db1fe79a41cc5c3cf7d631fc209fc</sha512>
</configuration>
</execution>
<execution>
<id>PDFBOX-5403</id>
<phase>generate-test-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://issues.apache.org/jira/secure/attachment/13041734/bad+rendering.pdf</url>
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
<outputFileName>PDFBOX-5403-bad-rendering.pdf</outputFileName>
<sha512>0d7160a4af04bf2f785bf4155f69876da4b7ff7a196e7eda1eb904c02c35aa03c31041d9339fda90322cb58bde16b87bae8460c617bfe5b8dc0670ddab102f62</sha512>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
70 changes: 70 additions & 0 deletions pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}