pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1674233 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf: FDFAnnotation.java FDFDictionary.java
Date Fri, 17 Apr 2015 08:25:58 GMT
Author: msahyoun
Date: Fri Apr 17 08:25:58 2015
New Revision: 1674233

URL: http://svn.apache.org/r1674233
Log:
PDFBOX-2758 initialize additional FDFAnnotations when importing from FDF/XFDF

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotation.java?rev=1674233&r1=1674232&r2=1674233&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotation.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotation.java Fri
Apr 17 08:25:58 2015
@@ -135,7 +135,6 @@ public abstract class FDFAnnotation impl
                     setToggleNoView( true );
                 }
             }
-
         }
 
         setName( element.getAttribute( "name" ) );
@@ -176,15 +175,75 @@ public abstract class FDFAnnotation impl
     public static FDFAnnotation create( COSDictionary fdfDic ) throws IOException
     {
         FDFAnnotation retval = null;
-        if( fdfDic != null )
+        if (fdfDic != null)
         {
-        if( FDFAnnotationText.SUBTYPE.equals( fdfDic.getNameAsString( COSName.SUBTYPE ) )
)
+            if (FDFAnnotationText.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
             {
                 retval = new FDFAnnotationText( fdfDic );
             }
+            else if (FDFAnnotationCaret.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationCaret(fdfDic);
+            }
+            else if (FDFAnnotationFreeText.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationFreeText(fdfDic);
+            }
+            else if (FDFAnnotationFileAttachment.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationFileAttachment(fdfDic);
+            }
+            else if (FDFAnnotationHighlight.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationHighlight(fdfDic);
+            }
+            else if (FDFAnnotationInk.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationInk(fdfDic);
+            }
+            else if (FDFAnnotationLine.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationLine(fdfDic);
+            }
+            else if (FDFAnnotationCircle.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationCircle(fdfDic);
+            }
+            else if (FDFAnnotationSquare.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationSquare(fdfDic);
+            }
+            else if (FDFAnnotationPolygon.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationPolygon(fdfDic);
+            }
+            else if (FDFAnnotationPolyline.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationPolyline(fdfDic);
+            }
+            else if (FDFAnnotationSound.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationSound(fdfDic);
+            }                            
+            else if (FDFAnnotationSquiggly.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationSquiggly(fdfDic);
+            }                            
+            else if (FDFAnnotationStamp.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationStamp(fdfDic);
+            }                            
+            else if (FDFAnnotationStrikeOut.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationStrikeOut(fdfDic);
+            }
+            else if (FDFAnnotationUnderline.SUBTYPE.equals(fdfDic.getNameAsString(COSName.SUBTYPE)))
+            {
+                retval = new FDFAnnotationUnderline(fdfDic);
+            }
             else
             {
-                LOG.warn("Unknown annotation type '" + fdfDic.getNameAsString( COSName.SUBTYPE
) + "'" );
+                LOG.warn("Unknown or unsupported annotation type '" + fdfDic.getNameAsString(
COSName.SUBTYPE ) + "'" );
             }
         }
         return retval;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java?rev=1674233&r1=1674232&r2=1674233&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java Fri
Apr 17 08:25:58 2015
@@ -21,13 +21,14 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 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.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
-
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
@@ -43,6 +44,9 @@ import org.w3c.dom.NodeList;
  */
 public class FDFDictionary implements COSObjectable
 {
+    
+    private static final Log LOG = LogFactory.getLog(FDFDictionary.class);
+    
     private COSDictionary fdf;
 
     /**
@@ -114,17 +118,85 @@ public class FDFDictionary implements CO
                     List<FDFAnnotation> annotList = new ArrayList<FDFAnnotation>();
                     for( int j=0; j<annots.getLength(); j++ )
                     {
-                        Node annotNode = annots.item( i );
+                        Node annotNode = annots.item( j );
                         if( annotNode instanceof Element )
                         {
+                            
+                            // the node name defines the annotation type
                             Element annot = (Element)annotNode;
-                            if( annot.getNodeName().equals( "text" ) )
+                            String annotationName = annot.getNodeName();
+
+                            if (annotationName.equals("text"))
+                            {
+                                annotList.add(new FDFAnnotationText(annot));
+                            }
+                            else if (annotationName.equals("caret"))
+                            {
+                                annotList.add(new FDFAnnotationCaret(annot));
+                            }
+                            else if (annotationName.equals("freetext"))
+                            {
+                                annotList.add(new FDFAnnotationFreeText(annot));
+                            }
+                            else if (annotationName.equals("fileattachment"))
+                            {
+                                annotList.add(new FDFAnnotationFileAttachment(annot));
+                            }
+                            else if (annotationName.equals("highlight"))
+                            {
+                                annotList.add(new FDFAnnotationHighlight(annot));
+                            }
+                            else if (annotationName.equals("ink"))
+                            {
+                                annotList.add(new FDFAnnotationInk(annot));
+                            }
+                            else if (annotationName.equals("line"))
+                            {
+                                annotList.add(new FDFAnnotationLine(annot));
+                            }
+                            else if (annotationName.equals("link"))
+                            {
+                                // TODO: support link annotation
+                            }
+                            else if (annotationName.equals("circle"))
+                            {
+                                annotList.add(new FDFAnnotationCircle(annot));
+                            }
+                            else if (annotationName.equals("square"))
+                            {
+                                annotList.add(new FDFAnnotationSquare(annot));
+                            }
+                            else if (annotationName.equals("polygon"))
+                            {
+                                annotList.add(new FDFAnnotationPolygon(annot));
+                            }
+                            else if (annotationName.equals("polyline"))
+                            {
+                                annotList.add(new FDFAnnotationPolyline(annot));
+                            }
+                            else if (annotationName.equals("sound"))
+                            {
+                                annotList.add(new FDFAnnotationSound(annot));
+                            }                            
+                            else if (annotationName.equals("squiggly"))
+                            {
+                                annotList.add(new FDFAnnotationSquiggly(annot));
+                            }                            
+                            else if (annotationName.equals("stamp"))
+                            {
+                                annotList.add(new FDFAnnotationStamp(annot));
+                            }                            
+                            else if (annotationName.equals("strikeout"))
+                            {
+                                annotList.add(new FDFAnnotationStrikeOut(annot));
+                            }
+                            else if (annotationName.equals("underline"))
                             {
-                                annotList.add( new FDFAnnotationText( annot ) );
+                                annotList.add(new FDFAnnotationUnderline(annot));
                             }
                             else
                             {
-                                throw new IOException( "Error: Unknown annotation type '"
+ annot.getNodeName() );
+                                LOG.warn("Unknown or unsupported annotation type '" + annotationName
+ "'" );
                             }
                         }
                     }



Mime
View raw message