pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1818979 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java
Date Thu, 21 Dec 2017 20:46:40 GMT
Author: tilman
Date: Thu Dec 21 20:46:40 2017
New Revision: 1818979

URL: http://svn.apache.org/viewvc?rev=1818979&view=rev
Log:
PDFBOX-4044: add /Name entry if /OCProperties/D dictionary is created because it's needed
at least for PDF/A-3

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java?rev=1818979&r1=1818978&r2=1818979&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java
Thu Dec 21 20:46:40 2017
@@ -87,7 +87,12 @@ public class PDOptionalContentProperties
     {
         this.dict = new COSDictionary();
         this.dict.setItem(COSName.OCGS, new COSArray());
-        this.dict.setItem(COSName.D, new COSDictionary());
+        COSDictionary d = new COSDictionary();
+
+        // Name optional but required for PDF/A-3
+        d.setString(COSName.NAME, "Top");
+
+        this.dict.setItem(COSName.D, d);
     }
 
     /**
@@ -119,12 +124,20 @@ public class PDOptionalContentProperties
 
     private COSDictionary getD()
     {
-        COSDictionary d = (COSDictionary)this.dict.getDictionaryObject(COSName.D);
-        if (d == null)
+        COSBase base = this.dict.getDictionaryObject(COSName.D);
+        if (base instanceof COSDictionary)
         {
-            d = new COSDictionary();
-            this.dict.setItem(COSName.D, d); //D is required
+            return (COSDictionary) base;
         }
+
+        COSDictionary d = new COSDictionary();
+
+        // Name optional but required for PDF/A-3
+        d.setString(COSName.NAME, "Top");
+
+        // D is required
+        this.dict.setItem(COSName.D, d);        
+
         return d;
     }
 
@@ -250,10 +263,10 @@ public class PDOptionalContentProperties
         //i.e. OCProperties/Configs
 
         COSDictionary d = getD();
-        COSArray on = (COSArray)d.getDictionaryObject(COSName.ON);
-        if (on != null)
+        COSBase base = d.getDictionaryObject(COSName.ON);
+        if (base instanceof COSArray)
         {
-            for (COSBase o : on)
+            for (COSBase o : (COSArray) base)
             {
                 COSDictionary group = toDictionary(o);
                 String name = group.getString(COSName.NAME);
@@ -264,10 +277,10 @@ public class PDOptionalContentProperties
             }
         }
 
-        COSArray off = (COSArray)d.getDictionaryObject(COSName.OFF);
-        if (off != null)
+        base = d.getDictionaryObject(COSName.OFF);
+        if (base instanceof COSArray)
         {
-            for (COSBase o : off)
+            for (COSBase o : (COSArray) base)
             {
                 COSDictionary group = toDictionary(o);
                 String name = group.getString(COSName.NAME);
@@ -304,19 +317,29 @@ public class PDOptionalContentProperties
      */
     public boolean setGroupEnabled(String groupName, boolean enable)
     {
+        COSArray on, off;
+
         COSDictionary d = getD();
-        COSArray on = (COSArray)d.getDictionaryObject(COSName.ON);
-        if (on == null)
+        COSBase base = d.getDictionaryObject(COSName.ON);
+        if (!(base instanceof COSArray))
         {
             on = new COSArray();
             d.setItem(COSName.ON, on);
         }
-        COSArray off = (COSArray)d.getDictionaryObject(COSName.OFF);
-        if (off == null)
+        else
+        {
+            on = (COSArray) base;
+        }
+        base = d.getDictionaryObject(COSName.OFF);
+        if (!(base instanceof COSArray))
         {
             off = new COSArray();
             d.setItem(COSName.OFF, off);
         }
+        else
+        {
+            off = (COSArray) base;
+        }
 
         boolean found = false;
         if (enable)
@@ -365,6 +388,4 @@ public class PDOptionalContentProperties
         }
         return found;
     }
-
-
 }



Mime
View raw message