You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2018/02/01 17:36:03 UTC

svn commit: r1822891 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java

Author: msahyoun
Date: Thu Feb  1 17:36:02 2018
New Revision: 1822891

URL: http://svn.apache.org/viewvc?rev=1822891&view=rev
Log:
PDFBOX-4092: support setting, getting the /RD value (margin) for Square and Circle annotation

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java?rev=1822891&r1=1822890&r2=1822891&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java Thu Feb  1 17:36:02 2018
@@ -19,6 +19,7 @@ package org.apache.pdfbox.pdmodel.intera
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSFloat;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.io.ScratchFile;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
@@ -185,5 +186,47 @@ public abstract class PDAnnotationSquare
         }
         return null;
     }
+    
+    /**
+     * This will set the margin between the annotations "outer" rectangle defined by
+     * /Rect and the border.
+     * 
+     * @param margin
+     */
+    public void setMargins(float margin) {
+        setMargins(margin, margin, margin, margin);
+    }
+    
+    /**
+     * This will set the margin between the annotations "outer" rectangle defined by
+     * /Rect and the border.
+     * 
+     * @param margin
+     */
+    public void setMargins(float marginLeft, float marginTop, float marginRight, float marginBottom)
+    {
+        COSArray margins = new COSArray();
+        margins.add(new COSFloat(marginLeft));
+        margins.add(new COSFloat(marginTop));
+        margins.add(new COSFloat(marginRight));
+        margins.add(new COSFloat(marginBottom));
+        getCOSObject().setItem(COSName.RD, margins);    
+    }
+    
+    /**
+     * This will get the margin between the annotations "outer" rectangle defined by
+     * /Rect and the border.
+     * 
+     * @return the margins. If the entry hasn't been set defaults to 0 on all sides.
+     */
+    public float[] getMargins()
+    {
+        COSBase margin = getCOSObject().getItem(COSName.RD);
+        if (margin instanceof COSArray)
+        {
+            return ((COSArray) margin).toFloatArray();
+        }
+        return new float[]{0f, 0f, 0f, 0f};
+    }
 
 }