pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1858100 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel: documentinterchange/markedcontent/PDPropertyList.java graphics/optionalcontent/PDOptionalContentMembershipDictionary.java
Date Thu, 25 Apr 2019 09:24:37 GMT
Author: tilman
Date: Thu Apr 25 09:24:37 2019
New Revision: 1858100

URL: http://svn.apache.org/viewvc?rev=1858100&view=rev
Log:
PDFBOX-4526: introduce PDOptionalContentMembershipDictionary

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentMembershipDictionary.java
  (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/markedcontent/PDPropertyList.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/markedcontent/PDPropertyList.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/markedcontent/PDPropertyList.java?rev=1858100&r1=1858099&r2=1858100&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/markedcontent/PDPropertyList.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/markedcontent/PDPropertyList.java
Thu Apr 25 09:24:37 2019
@@ -20,6 +20,7 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup;
+import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentMembershipDictionary;
 
 /**
  * A property list is a dictionary containing private information meaningful to the conforming
@@ -39,6 +40,10 @@ public class PDPropertyList implements C
         {
             return new PDOptionalContentGroup(dict);
         }
+        else if (COSName.OCMD.equals(dict.getItem(COSName.TYPE)))
+        {
+            return new PDOptionalContentMembershipDictionary(dict);
+        }
         else
         {
             // todo: more types

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentMembershipDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentMembershipDictionary.java?rev=1858100&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentMembershipDictionary.java
(added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentMembershipDictionary.java
Thu Apr 25 09:24:37 2019
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ */
+package org.apache.pdfbox.pdmodel.graphics.optionalcontent;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList;
+
+/**
+ * An optional content membership dictionary (OCMD).
+ *
+ * @author Tilman Hausherr
+ */
+public class PDOptionalContentMembershipDictionary extends PDPropertyList
+{
+    /**
+     * Creates a new optional content membership dictionary (OCMD).
+     */
+    public PDOptionalContentMembershipDictionary()
+    {
+        this.dict.setItem(COSName.TYPE, COSName.OCMD);
+    }
+
+    /**
+     * Creates a new instance based on a given {@link COSDictionary}.
+     * @param dict the dictionary
+     */
+    public PDOptionalContentMembershipDictionary(COSDictionary dict)
+    {
+        super(dict);
+        if (!dict.getItem(COSName.TYPE).equals(COSName.OCMD))
+        {
+            throw new IllegalArgumentException(
+                    "Provided dictionary is not of type '" + COSName.OCMD + "'");
+        }
+    }
+
+    /**
+     * Get a list of optional content groups.
+     * 
+     * @return List of optional content groups, never null.
+     */
+    public List<PDPropertyList> getOCGs()
+    {
+        List<PDPropertyList> list = new ArrayList<PDPropertyList>();
+        COSBase base = dict.getDictionaryObject(COSName.OCGS);
+        if (base instanceof COSDictionary)
+        {
+            list.add(PDPropertyList.create((COSDictionary) base));
+        }
+        else if (base instanceof COSArray)
+        {
+            COSArray ar = (COSArray) base;
+            for (int i = 0; i < ar.size(); ++i)
+            {
+                COSBase elem = ar.getObject(i);
+                if (elem instanceof COSDictionary)
+                {
+                    list.add(PDPropertyList.create((COSDictionary) elem));
+                }
+            }
+        }
+        return list;
+    }
+
+    /**
+     * Set optional content groups as a list.
+     * 
+     * @param ocgs list of optional content groups to set.
+     */
+    public void setOCGs(List<PDPropertyList> ocgs)
+    {
+        COSArray ar = new COSArray();
+        for (PDPropertyList prop : ocgs)
+        {
+            ar.add(prop);
+        }
+        dict.setItem(COSName.OCGS, ar);
+    }
+
+    /**
+     * Get the visibility policy name. Valid names are AllOff, AllOn, AnyOff, AnyOn (default).
+     *
+     * @return the visibility policy, never null.
+     */
+    public COSName getVisibilityPolicy()
+    {
+        return dict.getCOSName(COSName.P, COSName.ANY_ON);
+    }
+
+    /**
+     * Sets the visibility policy name. Valid names are AllOff, AllOn, AnyOff, AnyOn (default).
+     * @param visibilityPolicy 
+     */
+    public void setVisibilityPolicy(COSName visibilityPolicy)
+    {
+        dict.setItem(COSName.P, visibilityPolicy);
+    }
+    
+    //TODO support /VE some day
+}

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentMembershipDictionary.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message