pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1805105 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java
Date Tue, 15 Aug 2017 17:10:00 GMT
Author: msahyoun
Date: Tue Aug 15 17:10:00 2017
New Revision: 1805105

URL: http://svn.apache.org/viewvc?rev=1805105&view=rev
Log:
PDFBOX-3898: modify detecttion of PDNonTerminalField by checking for kids with a field name

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java?rev=1805105&r1=1805104&r2=1805105&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java
Tue Aug 15 17:10:00 2017
@@ -17,6 +17,7 @@
 
 package org.apache.pdfbox.pdmodel.interactive.form;
 
+import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
@@ -47,6 +48,27 @@ final class PDFieldFactory
     static PDField createField(PDAcroForm form, COSDictionary field, PDNonTerminalField parent)
     {
         String fieldType = findFieldType(field);
+        
+        // Test if we have a non terminal field first as it might have
+        // properties which do apply to other fields
+        // A non terminal fields has Kids entries which do have
+        // a field name (other than annotations)
+        if (field.containsKey(COSName.KIDS))
+        {
+            COSArray kids = (COSArray) field.getDictionaryObject(COSName.KIDS);
+            if (kids != null && kids.size() > 0)
+            {
+                for (int i = 0; i < kids.size(); i++)
+                {
+                    COSBase kid = kids.getObject(i);
+                    if (kid instanceof COSDictionary && ((COSDictionary) kid).getString(COSName.T)
!= null)
+                    {
+                        return new PDNonTerminalField(form, field, parent);
+                    }
+                }
+            }
+        } 
+        
         if (FIELD_TYPE_CHOICE.equals(fieldType))
         {
             return createChoiceSubType(form, field, parent);
@@ -63,10 +85,6 @@ final class PDFieldFactory
         {
             return createButtonSubType(form, field, parent);
         }
-        else if (field.containsKey(COSName.KIDS))
-        {
-            return new PDNonTerminalField(form, field, parent);
-        }
         else
         {
             // an erroneous non-field object, see PDFBOX-2885



Mime
View raw message