diff options
author | Simon Steiner <ssteiner@apache.org> | 2022-09-01 10:00:43 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2022-09-01 10:00:43 +0000 |
commit | 02656ec73867455a217091cb60f6c8c1f25caa59 (patch) | |
tree | 5cc322e7502753792fb917e4d3f6676d27265cf3 /fop-core/src/test | |
parent | c974d14e5c8c1fc8fb2b869939613ded4d46745d (diff) | |
download | xmlgraphics-fop-02656ec73867455a217091cb60f6c8c1f25caa59.tar.gz xmlgraphics-fop-02656ec73867455a217091cb60f6c8c1f25caa59.zip |
FOP-3091: Add transparency color support for PDF CMYK
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1903804 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core/src/test')
-rw-r--r-- | fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java | 14 | ||||
-rw-r--r-- | fop-core/src/test/java/org/apache/fop/util/ColorUtilTestCase.java | 8 |
2 files changed, 19 insertions, 3 deletions
diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java index 9a1872f5f..7b5d34bdc 100644 --- a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java @@ -48,6 +48,8 @@ import static org.mockito.Mockito.when; import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageInfo; +import org.apache.xmlgraphics.java2d.color.ColorSpaces; +import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactory; @@ -474,6 +476,12 @@ public class PDFPainterTestCase { @Test public void testAlphaColor() throws Exception { + fillColor(new Color(0, 0, 0, 102), "0 g\n"); + Color deviceColor = new Color(ColorSpaces.getDeviceCMYKColorSpace(), new float[4], 0.4f); + fillColor(new ColorWithAlternatives(0, 0, 0, 102, new Color[]{deviceColor}), "0 0 0 0 k\n"); + } + + private void fillColor(Color color, String cmd) throws Exception { FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); foUserAgent = fopFactory.newFOUserAgent(); PDFDocumentHandler pdfDocumentHandler = new PDFDocumentHandler(new IFContext(foUserAgent)); @@ -481,7 +489,7 @@ public class PDFPainterTestCase { pdfDocumentHandler.startDocument(); pdfDocumentHandler.startPage(0, "", "", new Dimension()); PDFPainter pdfPainter = new PDFPainter(pdfDocumentHandler, null); - pdfPainter.fillRect(new Rectangle(10, 10), new Color(0, 0, 0, 128)); + pdfPainter.fillRect(new Rectangle(10, 10), color); PDFFilterList filters = pdfPainter.generator.getStream().getFilterList(); filters.setDisableAllFilters(true); ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -491,7 +499,7 @@ public class PDFPainterTestCase { + "q\n" + "1 0 0 -1 0 0 cm\n" + "/GS1 gs\n" - + "0 g\n" + + cmd + "0 0 0.01 0.01 re f\n" + "\n" + "endstream", bos.toString()); @@ -499,7 +507,7 @@ public class PDFPainterTestCase { pdfDocumentHandler.getCurrentPage().getGStates().iterator().next().output(bos); Assert.assertEquals(bos.toString(), "<<\n" + "/Type /ExtGState\n" - + "/ca 0.5019608\n" + + "/ca 0.4\n" + "/CA 1.0\n" + ">>"); } diff --git a/fop-core/src/test/java/org/apache/fop/util/ColorUtilTestCase.java b/fop-core/src/test/java/org/apache/fop/util/ColorUtilTestCase.java index 095d3a806..4a530257e 100644 --- a/fop-core/src/test/java/org/apache/fop/util/ColorUtilTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/util/ColorUtilTestCase.java @@ -336,4 +336,12 @@ public class ColorUtilTestCase { assertEquals(colSpec, ColorUtil.colorToString(colActual)); } + + @Test + public void testAlphaColor() throws Exception { + String colSpec = "fop-rgb-icc(0.6,0.6,0.4,#alpha,0.4,#CMYK,,0.0,0.0,0.2,0.4)"; + ColorWithAlternatives colActual2 = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec); + assertEquals(colActual2.getAlternativeColors()[0].getAlpha(), 102); + assertEquals(ColorUtil.colorToString(colActual2), colSpec); + } } |