pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1589827 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
Date Thu, 24 Apr 2014 18:26:10 GMT
Author: tilman
Date: Thu Apr 24 18:26:10 2014
New Revision: 1589827

URL: http://svn.apache.org/r1589827
Log:
PDFBOX-2042: a read operation must not alter the pdf

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java?rev=1589827&r1=1589826&r2=1589827&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
Thu Apr 24 18:26:10 2014
@@ -270,44 +270,16 @@ public final class PDICCBased extends PD
     }
 
     /**
-     * Get the range array, create and fill it with default values (0, 1) if
-     * needed so that it has enough value pairs for the position.
-     *
-     * @param pos The zero-based position that should exist after this call is
-     * completed.
-     * @return A valid range array.
-     */
-    private COSArray getRangeArray(int pos)
-    {
-        //TODO per "clean code", a method should either 
-        // return something or modify something, but not both.
-        COSArray rangeArray = (COSArray)stream.getStream().getDictionaryObject(COSName.RANGE);
-        if(rangeArray == null)
-        {
-            rangeArray = new COSArray();
-            stream.getStream().setItem(COSName.RANGE, rangeArray);
-        }
-        // extend range array with default values if needed
-        while (rangeArray.size() < (pos + 1) * 2)
-        {
-            rangeArray.add(new COSFloat(0));
-            rangeArray.add(new COSFloat(1));
-        }
-        return rangeArray;
-    }
-
-    /**
      * Returns the range for a certain component number.
-     * This is will never return null.
+     * This will never return null.
      * If it is not present then the range 0..1 will be returned.
      * @param n the component number to get the range for
      * @return the range for this component
      */
     public PDRange getRangeForComponent(int n)
     {
-        COSArray rangeArray = getRangeArray(n);
-
-        if (rangeArray.size() == 0)
+        COSArray rangeArray = (COSArray) stream.getStream().getDictionaryObject(COSName.RANGE);
+        if (rangeArray == null || rangeArray.size() < getNumberOfComponents() * 2)
         {
             return new PDRange(); // 0..1
         }
@@ -367,7 +339,18 @@ public final class PDICCBased extends PD
      */
     public void setRangeForComponent(PDRange range, int n)
     {
-        COSArray rangeArray = getRangeArray(n);
+        COSArray rangeArray = (COSArray) stream.getStream().getDictionaryObject(COSName.RANGE);
+        if (rangeArray == null)
+        {
+            rangeArray = new COSArray();
+            stream.getStream().setItem(COSName.RANGE, rangeArray);
+        }
+        // extend range array with default values if needed
+        while (rangeArray.size() < (n + 1) * 2)
+        {
+            rangeArray.add(new COSFloat(0));
+            rangeArray.add(new COSFloat(1));
+        }
         rangeArray.set(n*2, new COSFloat(range.getMin()));
         rangeArray.set(n*2+1, new COSFloat(range.getMax()));
     }



Mime
View raw message