pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1652684 - in /pdfbox/branches/1.8/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/form/ test/java/org/apache/pdfbox/pdmodel/interactive/form/
Date Sat, 17 Jan 2015 22:02:48 GMT
Author: msahyoun
Date: Sat Jan 17 22:02:48 2015
New Revision: 1652684

URL: http://svn.apache.org/r1652684
Log:
PDFBOX-1750 set field type on constructor

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextbox.java
    pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java?rev=1652684&r1=1652683&r2=1652684&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
Sat Jan 17 22:02:48 2015
@@ -647,4 +647,25 @@ public abstract class PDField implements
     {
         dictionary.setItem(COSName.AA, actions);
     }
+    
+    /**
+     * Set the field type.
+     * 
+     * @param fieldType the field type string must be one of "Btn", "Ch", "Tx", "Sig"
+     */
+    protected void setFieldType(String fieldType)
+    {
+        if (fieldType.compareTo("Btn") != 0 &&
+            fieldType.compareTo("Ch") != 0 &&
+            fieldType.compareTo("Tx") != 0 &&
+            fieldType.compareTo("Sig") != 0
+                )
+        {
+            throw new IllegalArgumentException("Unknown field type given " + fieldType);
+        }
+        else
+        {
+            getDictionary().setName(COSName.FT, fieldType);
+        }
+    }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextbox.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextbox.java?rev=1652684&r1=1652683&r2=1652684&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextbox.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextbox.java
Sat Jan 17 22:02:48 2015
@@ -36,6 +36,7 @@ public class PDTextbox extends PDVariabl
     public PDTextbox( PDAcroForm theAcroForm )
     {
         super( theAcroForm );
+        setFieldType("Tx");
     }
 
     /**

Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java?rev=1652684&r1=1652683&r2=1652684&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
Sat Jan 17 22:02:48 2015
@@ -22,6 +22,7 @@ import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDDocument;
 
 /**
@@ -78,6 +79,10 @@ public class TestFields extends TestCase
             doc = new PDDocument();
             PDAcroForm form = new PDAcroForm( doc );
             PDTextbox textBox = new PDTextbox(form);
+            
+            //assert the correct field type
+            assertEquals(textBox.getFieldType(),"Tx");
+            assertEquals(textBox.getDictionary().getNameAsString(COSName.FT),"Tx");
 
             //assert that default is false.
             assertFalse( textBox.shouldComb() );



Mime
View raw message