You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/12/06 12:41:51 UTC

svn commit: r1848300 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java

Author: tilman
Date: Thu Dec  6 12:41:51 2018
New Revision: 1848300

URL: http://svn.apache.org/viewvc?rev=1848300&view=rev
Log:
PDFBOX-4303, PDFBOX-4393: add test

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java?rev=1848300&r1=1848299&r2=1848300&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java Thu Dec  6 12:41:51 2018
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotEquals;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -35,6 +36,8 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDType1Font;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
 import org.apache.pdfbox.rendering.TestPDFToImage;
@@ -291,6 +294,57 @@ public class PDAcroFormTest
         }
     }
 
+    /**
+     * PDFBOX-3732, PDFBOX-4303, PDFBOX-4393: Test whether /Helv and /ZaDb get added, but only if
+     * they don't exist.
+     */
+    @Test
+    public void testAcroFormDefaultFonts() throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try (PDDocument doc = new PDDocument())
+        {
+            PDPage page = new PDPage(PDRectangle.A4);
+            doc.addPage(page);
+            PDAcroForm acroForm2 = new PDAcroForm(doc);
+            doc.getDocumentCatalog().setAcroForm(acroForm2);
+            PDResources defaultResources = acroForm2.getDefaultResources();
+            assertNull(defaultResources);
+            defaultResources = new PDResources();
+            acroForm2.setDefaultResources(defaultResources);
+            assertNull(defaultResources.getFont(COSName.HELV));
+            assertNull(defaultResources.getFont(COSName.ZA_DB));
+
+            // getting AcroForm sets the two fonts
+            acroForm2 = doc.getDocumentCatalog().getAcroForm();
+            defaultResources = acroForm2.getDefaultResources();
+            assertNotNull(defaultResources.getFont(COSName.HELV));
+            assertNotNull(defaultResources.getFont(COSName.ZA_DB));
+
+            // repeat with a new AcroForm (to delete AcroForm cache) and thus missing /DR
+            doc.getDocumentCatalog().setAcroForm(new PDAcroForm(doc));
+            acroForm2 = doc.getDocumentCatalog().getAcroForm();
+            defaultResources = acroForm2.getDefaultResources();
+            PDFont helv = defaultResources.getFont(COSName.HELV);
+            PDFont zadb = defaultResources.getFont(COSName.ZA_DB);
+            assertNotNull(helv);
+            assertNotNull(zadb);
+            doc.save(baos);
+        }
+        try (PDDocument doc = PDDocument.load(baos.toByteArray()))
+        {
+            PDAcroForm acroForm2 = doc.getDocumentCatalog().getAcroForm();
+            PDResources defaultResources = acroForm2.getDefaultResources();
+            PDFont helv = defaultResources.getFont(COSName.HELV);
+            PDFont zadb = defaultResources.getFont(COSName.ZA_DB);
+            assertNotNull(helv);
+            assertNotNull(zadb);
+            // make sure that font wasn't overwritten
+            assertNotEquals(PDType1Font.HELVETICA, helv);
+            assertNotEquals(PDType1Font.ZAPF_DINGBATS, zadb);          
+        }
+    }
+
     @After
     public void tearDown() throws IOException
     {
@@ -352,4 +406,3 @@ public class PDAcroFormTest
         return count;
     } 
 }
-