Author: msahyoun Date: Thu Feb 1 17:38:02 2018 New Revision: 1822892 URL: http://svn.apache.org/viewvc?rev=1822892&view=rev Log: PDFBOX-4092: support setting, getting the /RD value (margin) for FreeText annotation
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationFreeText.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationFreeText.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationFreeText.java?rev=1822892&r1=1822891&r2=1822892&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationFreeText.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationFreeText.java Thu Feb 1 17:38:02 2018 @@ -15,7 +15,10 @@ */ package org.apache.pdfbox.pdmodel.interactive.annotation; +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.interactive.annotation.handlers.PDAppearanceHandler; @@ -121,6 +124,48 @@ public class PDAnnotationFreeText extend } /** + * 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}; + } + + /** * Set a custom appearance handler for generating the annotations appearance streams. * * @param freeTextAppearanceHandler