pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1854575 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
Date Fri, 01 Mar 2019 11:36:51 GMT
Author: tilman
Date: Fri Mar  1 11:36:51 2019
New Revision: 1854575

URL: http://svn.apache.org/viewvc?rev=1854575&view=rev
Log:
PDFBOX-4478: add missing types in arrays and dictionaries

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java?rev=1854575&r1=1854574&r2=1854575&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
Fri Mar  1 11:36:51 2019
@@ -30,9 +30,11 @@ import javax.xml.xpath.XPathFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSBoolean;
 
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSFloat;
+import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.util.Hex;
@@ -118,6 +120,8 @@ public class FDFAnnotationStamp extends
         }
         if (base64EncodedAppearance != null && !base64EncodedAppearance.isEmpty())
         {
+            LOG.debug("Decoded XML: " + decodedAppearanceXML);
+
             Document stampAppearance = getStampAppearanceDocument(decodedAppearanceXML);
 
             Element appearanceEl = stampAppearance.getDocumentElement();
@@ -204,6 +208,7 @@ public class FDFAnnotationStamp extends
 
     private COSStream parseStreamElement(Element streamEl) throws IOException
     {
+        LOG.debug("Parse " + streamEl.getAttribute("KEY") + " Stream");
         COSStream stream = new COSStream();
 
         NodeList nodeList = streamEl.getChildNodes();
@@ -227,6 +232,11 @@ public class FDFAnnotationStamp extends
                         LOG.debug(parentAttrKey + " => Set " + childAttrKey + ": " + childAttrVal);
                     }
                 }
+                else if ("FIXED".equalsIgnoreCase(child.getTagName()))
+                {
+                    stream.setFloat(COSName.getPDFName(childAttrKey), Float.parseFloat(childAttrVal));
+                    LOG.debug(parentAttrKey + " => Set " + childAttrKey + ": " + childAttrVal);
+                }
                 else if ("NAME".equalsIgnoreCase(child.getTagName()))
                 {
                     stream.setName(COSName.getPDFName(childAttrKey), childAttrVal);
@@ -235,7 +245,7 @@ public class FDFAnnotationStamp extends
                 else if ("BOOL".equalsIgnoreCase(child.getTagName()))
                 {
                     stream.setBoolean(COSName.getPDFName(childAttrKey), Boolean.parseBoolean(childAttrVal));
-                    LOG.debug(parentAttrKey + " => Set Interpolate: " + childAttrVal);
+                    LOG.debug(parentAttrKey + " => Set " + childAttrVal);
                 }
                 else if ("ARRAY".equalsIgnoreCase(child.getTagName()))
                 {
@@ -264,6 +274,15 @@ public class FDFAnnotationStamp extends
                             LOG.debug(parentAttrKey + " => Data was streamed");
                         }
                     }
+                    else if ("ASCII".equals(child.getAttribute("ENCODING")))
+                    {
+                        try (OutputStream os = stream.createOutputStream())
+                        {
+                            // not sure about charset
+                            os.write(child.getTextContent().getBytes());
+                            LOG.debug(parentAttrKey + " => Data was streamed");
+                        }
+                    }
                     else
                     {
                         LOG.warn(parentAttrKey + " => Not handling element DATA encoding:
" +
@@ -284,10 +303,11 @@ public class FDFAnnotationStamp extends
     {
         LOG.debug("Parse " + arrayEl.getAttribute("KEY") + " Array");
         COSArray array = new COSArray();
-        NodeList nodeList = arrayEl.getElementsByTagName("FIXED");
-        String elAttrKey = arrayEl.getAttribute("KEY");
 
-        if ("BBox".equals(elAttrKey))
+        NodeList nodeList = arrayEl.getChildNodes();
+        String parentAttrKey = arrayEl.getAttribute("KEY");
+
+        if ("BBox".equals(parentAttrKey))
         {
             if (nodeList.getLength() < 4)
             {
@@ -295,7 +315,7 @@ public class FDFAnnotationStamp extends
                         nodeList.getLength());
             }
         }
-        else if ("Matrix".equals(elAttrKey))
+        else if ("Matrix".equals(parentAttrKey))
         {
             if (nodeList.getLength() < 6)
             {
@@ -304,16 +324,55 @@ public class FDFAnnotationStamp extends
             }
         }
 
-        LOG.debug("There are " + nodeList.getLength() + " FIXED elements");
-
         for (int i = 0; i < nodeList.getLength(); i++)
         {
             Node node = nodeList.item(i);
             if (node instanceof Element)
             {
-                Element el = (Element) node;
-                LOG.debug(elAttrKey + " value(" + i + "): " + el.getAttribute("VAL"));
-                array.add(new COSFloat(el.getAttribute("VAL")));
+                Element child = (Element) node;
+                String childAttrKey = child.getAttribute("KEY");
+                String childAttrVal = child.getAttribute("VAL");
+                LOG.debug(parentAttrKey + " => reading child: " + child.getTagName() +
+                           " with key: " + childAttrKey);
+                if ("INT".equalsIgnoreCase(child.getTagName()))
+                {
+                    LOG.debug(parentAttrKey + " value(" + i + "): " + child.getAttribute("VAL"));
+                    array.add(COSFloat.get(childAttrVal));
+                }
+                else if ("FIXED".equalsIgnoreCase(child.getTagName()))
+                {
+                    LOG.debug(parentAttrKey + " value(" + i + "): " + child.getAttribute("VAL"));
+                    array.add(COSInteger.get(childAttrVal));
+                }
+                else if ("NAME".equalsIgnoreCase(child.getTagName()))
+                {
+                    LOG.debug(parentAttrKey + " value(" + i + "): " + child.getAttribute("VAL"));
+                    array.add(COSName.getPDFName(childAttrVal));
+                }
+                else if ("BOOL".equalsIgnoreCase(child.getTagName()))
+                {
+                    LOG.debug(parentAttrKey + " value(" + i + "): " + child.getAttribute("VAL"));
+                    array.add(COSBoolean.getBoolean(Boolean.parseBoolean(childAttrVal)));
+                }
+                else if ("DICT".equalsIgnoreCase(child.getTagName()))
+                {
+                    LOG.debug(parentAttrKey + " value(" + i + "): " + child.getAttribute("VAL"));
+                    array.add(parseDictElement(child));
+                }
+                else if ("STREAM".equalsIgnoreCase(child.getTagName()))
+                {
+                    LOG.debug(parentAttrKey + " value(" + i + "): " + child.getAttribute("VAL"));
+                    array.add(parseStreamElement(child));
+                }
+                else if ("ARRAY".equalsIgnoreCase(child.getTagName()))
+                {
+                    LOG.debug(parentAttrKey + " value(" + i + "): " + child.getAttribute("VAL"));
+                    array.add(parseArrayElement(child));
+                }
+                else
+                {
+                    LOG.warn(parentAttrKey + " => Not handling child element: " + child.getTagName());
+                }
             }
         }
 
@@ -354,6 +413,26 @@ public class FDFAnnotationStamp extends
                     dict.setName(COSName.getPDFName(childAttrKey), childAttrVal);
                     LOG.debug(parentAttrKey + " => Set " + childAttrKey + ": " + childAttrVal);
                 }
+                else if ("INT".equalsIgnoreCase(child.getTagName()))
+                {
+                    dict.setInt(COSName.getPDFName(childAttrKey), Integer.parseInt(childAttrVal));
+                    LOG.debug(parentAttrKey + " => Set " + childAttrKey + ": " + childAttrVal);
+                }
+                else if ("FIXED".equalsIgnoreCase(child.getTagName()))
+                {
+                    dict.setFloat(COSName.getPDFName(childAttrKey), Float.parseFloat(childAttrVal));
+                    LOG.debug(parentAttrKey + " => Set " + childAttrKey + ": " + childAttrVal);
+                }
+                else if ("BOOL".equalsIgnoreCase(child.getTagName()))
+                {
+                    dict.setBoolean(COSName.getPDFName(childAttrKey), Boolean.parseBoolean(childAttrVal));
+                    LOG.debug(parentAttrKey + " => Set " + childAttrVal);
+                }
+                else if ("ARRAY".equalsIgnoreCase(child.getTagName()))
+                {
+                    dict.setItem(COSName.getPDFName(childAttrKey), parseArrayElement(child));
+                    LOG.debug(parentAttrKey + " => Set " + childAttrKey);
+                }
                 else
                 {
                     LOG.warn(parentAttrKey + " => NOT handling child element: " + child.getTagName());



Mime
View raw message