From commits-return-14823-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Sun Jun 16 16:31:38 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 4FB2E180662 for ; Sun, 16 Jun 2019 18:31:38 +0200 (CEST) Received: (qmail 7229 invoked by uid 500); 16 Jun 2019 16:31:37 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 7220 invoked by uid 99); 16 Jun 2019 16:31:37 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Jun 2019 16:31:37 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id AE7F23A05C4 for ; Sun, 16 Jun 2019 16:31:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1861468 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java Date: Sun, 16 Jun 2019 16:31:36 -0000 To: commits@pdfbox.apache.org From: msahyoun@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190616163136.AE7F23A05C4@svn01-us-west.apache.org> Author: msahyoun Date: Sun Jun 16 16:31:36 2019 New Revision: 1861468 URL: http://svn.apache.org/viewvc?rev=1861468&view=rev Log: PDFBOX-4574: add support for FreeText appearance handler Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java?rev=1861468&r1=1861467&r2=1861468&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java (original) +++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java Sun Jun 16 16:31:36 2019 @@ -26,9 +26,11 @@ import org.apache.pdfbox.cos.COSFloat; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.cos.COSString; +import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDAppearanceHandler; import org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDCaretAppearanceHandler; +import org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDFreeTextAppearanceHandler; import org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDPolygonAppearanceHandler; import org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDPolylineAppearanceHandler; @@ -69,6 +71,25 @@ public class PDAnnotationMarkup extends public static final String SUB_TYPE_SOUND = "Sound"; /* + * The various values of the free text annotation as defined in the PDF 1.7 reference Table 170 + */ + + /** + * A plain free-text annotation, also known as a text box comment. + */ + public static final String IT_FREE_TEXT = "FreeText"; + + /** + * A callout, associated with an area on the page through the callout line specified. + */ + public static final String IT_FREE_TEXT_CALLOUT = "FreeTextCallout"; + + /** + * The annotation is intended to function as a click-to-type or typewriter object. + */ + public static final String IT_FREE_TEXT_TYPE_WRITER = "FreeTextTypeWriter"; + + /* * The various values of the reply type as defined in the PDF 1.7 reference Table 170 */ @@ -365,6 +386,27 @@ public class PDAnnotationMarkup extends return null; } + /** + * This will set the line ending style. + * + * @param style The new style. + */ + public final void setLineEndingStyle(String style) + { + getCOSObject().setName(COSName.LE, style); + } + + /** + * This will retrieve the line ending style. + * + * @return The line ending style, possible values shown in the LE_ constants section, LE_NONE if + * missing, never null. + */ + public String getLineEndingStyle() + { + return getCOSObject().getNameAsString(COSName.LE, PDAnnotationLine.LE_NONE); + } + // PDF 32000 specification has "the interior color with which to fill the annotation’s line endings" // but it is the inside of the polygon. @@ -420,6 +462,106 @@ public class PDAnnotationMarkup extends } /** + * Get the default appearance. + * + * @return a string describing the default appearance. + */ + public String getDefaultAppearance() + { + return getCOSObject().getString(COSName.DA); + } + + /** + * Set the default appearance. + * + * @param daValue a string describing the default appearance. + */ + public void setDefaultAppearance(String daValue) + { + getCOSObject().setString(COSName.DA, daValue); + } + + /** + * Get the default style string. + * + * The default style string defines the default style for rich text fields. + * + * @return the DS element of the dictionary object + */ + public String getDefaultStyleString() + { + return getCOSObject().getString(COSName.DS); + } + + /** + * Set the default style string. + * + * Providing null as the value will remove the default style string. + * + * @param defaultStyleString a string describing the default style. + */ + public void setDefaultStyleString(String defaultStyleString) + { + getCOSObject().setString(COSName.DS, defaultStyleString); + } + + /** + * This will get the 'quadding' or justification of the text to be displayed. + *
+ * 0 - Left (default)
+ * 1 - Centered
+ * 2 - Right
+ * Please see the QUADDING_CONSTANTS in {@link PDVariableText }. + * + * @return The justification of the text strings. + */ + public int getQ() + { + return getCOSObject().getInt(COSName.Q, 0); + } + + /** + * This will set the quadding/justification of the text. Please see the QUADDING_CONSTANTS + * in {@link PDVariableText }. + * + * @param q The new text justification. + */ + public void setQ(int q) + { + getCOSObject().setInt(COSName.Q, q); + } + + /** + * This will set the rectangle difference rectangle. Giving the difference between the + * annotations rectangle and where the drawing occurs. (To take account of any effects applied + * through the BE entry for example) + * + * @param rd the rectangle difference + * + */ + public void setRectDifference(PDRectangle rd) + { + getCOSObject().setItem(COSName.RD, rd); + } + + /** + * This will get the rectangle difference rectangle. Giving the difference between the + * annotations rectangle and where the drawing occurs. (To take account of any effects applied + * through the BE entry for example) + * + * @return the rectangle difference + */ + public PDRectangle getRectDifference() + { + COSBase base = getCOSObject().getDictionaryObject(COSName.RD); + if (base instanceof COSArray) + { + return new PDRectangle((COSArray) base); + } + return null; + } + + /** * This will set the difference between the annotations "outer" rectangle defined by * /Rect and boundaries of the underlying. * @@ -468,6 +610,41 @@ public class PDAnnotationMarkup extends } /** + * This will set the coordinates of the callout line. (PDF 1.6 and higher) Only relevant if the + * intent is FreeTextCallout. + * + * @param callout An array of four or six numbers specifying a callout line attached to the free + * text annotation. Six numbers [ x1 y1 x2 y2 x3 y3 ] represent the starting, knee point, and + * ending coordinates of the line in default user space, four numbers [ x1 y1 x2 y2 ] represent + * the starting and ending coordinates of the line. + */ + public final void setCallout(float[] callout) + { + COSArray newCallout = new COSArray(); + newCallout.setFloatArray(callout); + getCOSObject().setItem(COSName.CL, newCallout); + } + + /** + * This will get the coordinates of the callout line. (PDF 1.6 and higher) Only relevant if the + * intent is FreeTextCallout. + * + * @return An array of four or six numbers specifying a callout line attached to the free text + * annotation. Six numbers [ x1 y1 x2 y2 x3 y3 ] represent the starting, knee point, and ending + * coordinates of the line in default user space, four numbers [ x1 y1 x2 y2 ] represent the + * starting and ending coordinates of the line. + */ + public float[] getCallout() + { + COSBase base = getCOSObject().getDictionaryObject(COSName.CL); + if (base instanceof COSArray) + { + return ((COSArray) base).toFloatArray(); + } + return null; + } + + /** * This will set the line ending style for the start point, see the LE_ constants for the possible values. * * @param style The new style. @@ -628,7 +805,11 @@ public class PDAnnotationMarkup extends { appearanceHandler = new PDCaretAppearanceHandler(this); } - if (SUB_TYPE_POLYGON.equals(getSubtype())) + else if (SUB_TYPE_FREETEXT.equals(getSubtype())) + { + appearanceHandler = new PDFreeTextAppearanceHandler(this); + } + else if (SUB_TYPE_POLYGON.equals(getSubtype())) { appearanceHandler = new PDPolygonAppearanceHandler(this); }