From: Jeremias Maerki Date: Sat, 26 Feb 2011 09:36:23 +0000 (+0000) Subject: Fix for a potential NPE when painting vector graphics with non-sRGB colors. X-Git-Tag: fop-1_1rc1old~270 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aba70fb7a13ef2b5407d99e64096019c62d61df1;p=xmlgraphics-fop.git Fix for a potential NPE when painting vector graphics with non-sRGB colors. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1074810 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java b/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java index 4d473bb7c..87e8f5475 100644 --- a/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java +++ b/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.InputStream; import org.apache.commons.io.IOUtils; + import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil; /** @@ -34,6 +35,7 @@ public class PDFICCBasedColorSpace extends PDFObject implements PDFColorSpace { private PDFICCStream iccStream; private String explicitName; + private int numComponents; /** * Constructs a the ICCBased color space with an explicit name (ex. "DefaultRGB"). @@ -43,6 +45,7 @@ public class PDFICCBasedColorSpace extends PDFObject implements PDFColorSpace { public PDFICCBasedColorSpace(String explicitName, PDFICCStream iccStream) { this.explicitName = explicitName; this.iccStream = iccStream; + this.numComponents = iccStream.getICCProfile().getNumComponents(); } /** @@ -60,7 +63,7 @@ public class PDFICCBasedColorSpace extends PDFObject implements PDFColorSpace { /** {@inheritDoc} */ public int getNumComponents() { - return iccStream.getICCProfile().getNumComponents(); + return this.numComponents; } /** {@inheritDoc} */ @@ -93,6 +96,7 @@ public class PDFICCBasedColorSpace extends PDFObject implements PDFColorSpace { } /** {@inheritDoc} */ + @Override protected String toPDFString() { StringBuffer sb = new StringBuffer(64); sb.append(getObjectID()); diff --git a/src/java/org/apache/fop/pdf/PDFICCStream.java b/src/java/org/apache/fop/pdf/PDFICCStream.java index b70ed017a..9002fcc94 100644 --- a/src/java/org/apache/fop/pdf/PDFICCStream.java +++ b/src/java/org/apache/fop/pdf/PDFICCStream.java @@ -49,7 +49,11 @@ public class PDFICCStream extends PDFStream { pdfColorSpace = alt; } - /** @return the ICC profile */ + /** + * Returns the associated ICC profile. Note that this will return null once the + * ICC stream has been written to the PDF file. + * @return the ICC profile (or null if the stream has already been written) + */ public ICC_Profile getICCProfile() { return this.cp; } @@ -59,6 +63,7 @@ public class PDFICCStream extends PDFStream { * byte arrays around so much * {@inheritDoc} */ + @Override protected int output(java.io.OutputStream stream) throws java.io.IOException { int length = super.output(stream); @@ -67,11 +72,13 @@ public class PDFICCStream extends PDFStream { } /** {@inheritDoc} */ + @Override protected void outputRawStreamData(OutputStream out) throws IOException { cp.write(out); } /** {@inheritDoc} */ + @Override protected void populateStreamDict(Object lengthEntry) { put("N", cp.getNumComponents()); if (pdfColorSpace != null) {