pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1635673 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel: PDResources.java graphics/color/PDColorSpace.java
Date Fri, 31 Oct 2014 05:39:49 GMT
Author: jahewson
Date: Fri Oct 31 05:39:48 2014
New Revision: 1635673

URL: http://svn.apache.org/r1635673
Log:
PDFBOX-2407: Avoid null in getColorSpace

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java?rev=1635673&r1=1635672&r2=1635673&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java Fri Oct 31
05:39:48 2014
@@ -96,7 +96,7 @@ public final class PDResources implement
      */
     public PDColorSpace getColorSpace(COSName name) throws IOException
     {
-        // check for default color spaces
+        // check for default color spaces - todo: move this into PDColorSpace.create?
         if (name.equals(COSName.DEVICECMYK) &&
             get(COSName.COLORSPACE, COSName.DEFAULT_CMYK) != null)
         {
@@ -120,23 +120,28 @@ public final class PDResources implement
             return PDColorSpace.create(name, this);
         }
 
+        // get the instance
         COSBase object = get(COSName.COLORSPACE, name);
-        if (object == null &&
-            name.equals(COSName.DEVICECMYK) ||
-            name.equals(COSName.DEVICERGB) ||
-            name.equals(COSName.DEVICEGRAY))
+        if (object != null)
         {
-            // the named color space does not exist, but it's built-in
-            return PDColorSpace.create(name, this);
+            return PDColorSpace.create(object, this);
         }
         else
         {
-            // finally handle named color spaces
-            return PDColorSpace.create(object, this);
+            return PDColorSpace.create(name, this);
         }
     }
 
     /**
+     * Returns true if the given color space name exists in these resources.
+     * @param name color space name
+     */
+    public boolean hasColorSpace(COSName name)
+    {
+        return get(COSName.COLORSPACE, name) != null;
+    }
+
+    /**
      * Returns the external graphics state resource with the given name, or null if none
exists.
      */
     public PDExternalGraphicsState getExtGState(COSName name) throws IOException

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java?rev=1635673&r1=1635672&r2=1635673&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
Fri Oct 31 05:39:48 2014
@@ -89,12 +89,11 @@ public abstract class PDColorSpace imple
             }
             else if (resources != null)
             {
-                PDColorSpace cs = resources.getColorSpace(name);
-                if (cs == null)
+                if (!resources.hasColorSpace(name))
                 {
                     throw new MissingException("Missing color space: " + name.getName());
                 }
-                return cs;
+                return resources.getColorSpace(name);
             }
             else
             {



Mime
View raw message