Author: ssteiner
Date: Thu Jul  6 14:39:11 2017
New Revision: 1801064

URL: http://svn.apache.org/viewvc?rev=1801064&view=rev
Log:
FOP-2719: PDF to PS NPE when encode param not set

Added:
    
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PSPDFGraphics2DTestCase.java
   (with props)
Modified:
    
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java

Modified: 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java?rev=1801064&r1=1801063&r2=1801064&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
 Thu Jul  6 14:39:11 2017
@@ -173,7 +173,7 @@ public class PSPDFGraphics2D extends PSG
         }
     }
 
-    private static Function getFunction(PDFunction f) throws IOException {
+    protected static Function getFunction(PDFunction f) throws IOException {
         if (f instanceof PDFunctionType3) {
             PDFunctionType3 sourceFT3 = (PDFunctionType3) f;
             float[] bounds = sourceFT3.getBounds().toFloatArray();
@@ -193,11 +193,11 @@ public class PSPDFGraphics2D extends PSG
             COSDictionary s = f.getCOSObject();
             assert s instanceof COSStream;
             COSStream stream = (COSStream) s;
-            COSArray encode = (COSArray) s.getDictionaryObject(COSName.ENCODE);
             COSArray domain = (COSArray) s.getDictionaryObject(COSName.DOMAIN);
             COSArray range = (COSArray) s.getDictionaryObject(COSName.RANGE);
             int bits = 
((COSInteger)s.getDictionaryObject(COSName.BITS_PER_SAMPLE)).intValue();
             COSArray size = (COSArray) s.getDictionaryObject(COSName.SIZE);
+            COSArray encode = getEncode(s);
             byte[] x = IOUtils.toByteArray(stream.getUnfilteredStream());
             for (byte y : x) {
                 if (y != 0) {
@@ -215,6 +215,20 @@ public class PSPDFGraphics2D extends PSG
         throw new IOException("Unsupported " + f.toString());
     }
 
+    private static COSArray getEncode(COSDictionary s) {
+        COSArray encode = (COSArray) s.getDictionaryObject(COSName.ENCODE);
+        if (encode == null) {
+            encode = new COSArray();
+            COSArray size = (COSArray) s.getDictionaryObject(COSName.SIZE);
+            int sizeValuesSize = size.size();
+            for (int i = 0; i < sizeValuesSize; i++) {
+                encode.add(COSInteger.ZERO);
+                encode.add(COSInteger.get(size.getInt(i) - 1));
+            }
+        }
+        return encode;
+    }
+
     private static List<Float> toList(float[] array) {
         List<Float> list = new ArrayList<Float>(array.length);
         for (float f : array) {

Added: 
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PSPDFGraphics2DTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PSPDFGraphics2DTestCase.java?rev=1801064&view=auto
==============================================================================
--- 
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PSPDFGraphics2DTestCase.java
 (added)
+++ 
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PSPDFGraphics2DTestCase.java
 Thu Jul  6 14:39:11 2017
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.pdf;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSInteger;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.pdmodel.common.function.PDFunction;
+import org.apache.pdfbox.pdmodel.common.function.PDFunctionType0;
+
+import org.apache.fop.render.gradient.Function;
+import org.apache.fop.render.pdf.pdfbox.PSPDFGraphics2D;
+
+public class PSPDFGraphics2DTestCase {
+
+    @Test
+    public void testShading() throws IOException {
+        COSStream stream = new COSStream();
+        OutputStream streamData = stream.createOutputStream();
+        streamData.write("test".getBytes("UTF-8"));
+        streamData.close();
+        stream.setItem(COSName.BITS_PER_SAMPLE, COSInteger.get(8));
+        stream.setItem(COSName.FUNCTION_TYPE, COSInteger.ZERO);
+        COSArray range = new COSArray();
+        range.add(COSInteger.ZERO);
+        range.add(COSInteger.ONE);
+        range.add(COSInteger.ZERO);
+        range.add(COSInteger.ONE);
+        range.add(COSInteger.ZERO);
+        range.add(COSInteger.ONE);
+        stream.setItem(COSName.RANGE, range);
+        stream.setItem(COSName.DOMAIN, range);
+        COSArray size = new COSArray();
+        size.add(COSInteger.ONE);
+        stream.setItem(COSName.SIZE, size);
+
+        Function f = new MyPSPDFGraphics2D().getAFunction(new 
PDFunctionType0(stream));
+        Assert.assertEquals(f.getBitsPerSample(), 8);
+    }
+
+    static class MyPSPDFGraphics2D extends PSPDFGraphics2D {
+        MyPSPDFGraphics2D() {
+            super(false);
+        }
+
+        Function getAFunction(PDFunction function) throws IOException {
+            return getFunction(function);
+        }
+    }
+}

Propchange: 
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PSPDFGraphics2DTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org

Reply via email to