Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.interactive.form

pack-priv Class AppearanceGeneratorHelper

extends Object
Class Inheritance
Imports
java.awt.geom.AffineTransform, .GeneralPath, .Point2D, java.io.ByteArrayOutputStream, .IOException, .OutputStream, java.util.ArrayList, .List, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.util.BoundingBox, org.apache.pdfbox.contentstream.operator.Operator, org.apache.pdfbox.cos.COSDictionary, .COSName, .COSString, org.apache.pdfbox.pdfparser.PDFStreamParser, org.apache.pdfbox.pdfwriter.ContentStreamWriter, org.apache.pdfbox.pdmodel.PDResources, .PDAppearanceContentStream, org.apache.pdfbox.pdmodel.common.PDRectangle, org.apache.pdfbox.pdmodel.font.PDFont, .PDSimpleFont, .PDType3CharProc, .PDType3Font, .PDVectorFont, org.apache.pdfbox.pdmodel.graphics.color.PDColor, org.apache.pdfbox.pdmodel.interactive.action.PDAction, .PDActionJavaScript, .PDFormFieldAdditionalActions, org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget, .PDAppearanceCharacteristicsDictionary, .PDAppearanceDictionary, .PDAppearanceEntry, .PDAppearanceStream, .PDBorderStyleDictionary, org.apache.pdfbox.util.Matrix

Create the AcroForms field appearance helper.
Authors
Stephan Gerhard, Ben Litchfield

Field Summary

Modifier and TypeField and Description
private static final Operator
private static final float
DEFAULT_FONT_SIZE

The default font size used for multiline text

private static final float
DEFAULT_PADDING

The default padding applied by Acrobat to the fields bbox.

private PDDefaultAppearanceString
private static final Operator
private final PDVariableText
private static final int
FONTSCALE

The scaling factor for font units to PDF units

private static final float[]
HIGHLIGHT_COLOR

The highlight color The color setting is used by Adobe to display the highlight box for selected entries in a list box.

private static final Log
private static final float
private static final float
MINIMUM_FONT_SIZE

The minimum/maximum font sizes used for multiline text auto sizing

private String

Constructor Summary

AccessConstructor and Description
pack-priv
AppearanceGeneratorHelper(PDVariableText
the field which you wish to control the appearance of
field
)

Constructs a COSAppearance from the given field.

Method Summary

Modifier and TypeMethod and Description
private PDRectangle

Returns:

the padded box.
applyPadding
(PDRectangle
box
box
,
float padding)

Apply padding to a box.

private float

Returns:

the calculated font-size
calculateFontSize
(PDFont font, PDRectangle contentRect)

My "not so great" method for calculating the fontsize.

private AffineTransform
calculateMatrix(PDRectangle bbox, int rotation)

private String
private int
private PDDefaultAppearanceString
private void
initializeAppearanceContent(PDAnnotationWidget
the field widget
widget
,
PDAppearanceCharacteristicsDictionary
the appearance characteristics dictionary from the widget or null
appearanceCharacteristics
,
PDAppearanceStream
the appearance stream to be used
appearanceStream
)

Initialize the content of the appearance stream.

private void
insertGeneratedAppearance(PDAnnotationWidget widget, PDAppearanceStream appearanceStream, OutputStream output)

Generate and insert text content and clipping around it.

private void
insertGeneratedCombAppearance(PDAppearanceContentStream
the content stream to write to
contents
,
PDAppearanceStream
the appearance stream used
appearanceStream
,
PDFont
the font to be used
font
,
float
the font size to be used
fontSize
)

Generate the appearance for comb fields.

private void
insertGeneratedListboxAppearance(PDAppearanceContentStream contents, PDAppearanceStream appearanceStream, PDRectangle contentRect, PDFont font, float fontSize)

private void
private boolean
private static boolean
private PDAppearanceStream
private PDRectangle

Returns:

the resolved boundingBox.
resolveBoundingBox
(PDAnnotationWidget
the annotation widget.
fieldWidget
,
PDAppearanceStream
the annotations appearance stream.
appearanceStream
)

Resolve the bounding box.

private float
private float
private float
resolveGlyphHeight(PDFont font, int code)

private int
private void
setAppearanceContent(PDAnnotationWidget widget, PDAppearanceStream appearanceStream)

Constructs and sets new contents for given appearance stream.

public void
setAppearanceValue(String
the String value which the appearance should represent
apValue
)

This is the public method for setting the appearance stream.

private boolean

Returns:

the comb state
shallComb
()

Determine if the appearance shall provide a comb output.

private void
private void
writeToStream(byte[] data, PDAppearanceStream appearanceStream)

Writes the stream to the actual stream in the COSStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BMCback to summary
private static final Operator BMC
DEFAULT_FONT_SIZEback to summary
private static final float DEFAULT_FONT_SIZE

The default font size used for multiline text

DEFAULT_PADDINGback to summary
private static final float DEFAULT_PADDING

The default padding applied by Acrobat to the fields bbox.

defaultAppearanceback to summary
private PDDefaultAppearanceString defaultAppearance
EMCback to summary
private static final Operator EMC
fieldback to summary
private final PDVariableText field
FONTSCALEback to summary
private static final int FONTSCALE

The scaling factor for font units to PDF units

HIGHLIGHT_COLORback to summary
private static final float[] HIGHLIGHT_COLOR

The highlight color The color setting is used by Adobe to display the highlight box for selected entries in a list box. Regardless of other settings in an existing appearance stream Adobe will always use this value.

LOGback to summary
private static final Log LOG
MAXIMUM_FONT_SIZEback to summary
private static final float MAXIMUM_FONT_SIZE
MINIMUM_FONT_SIZEback to summary
private static final float MINIMUM_FONT_SIZE

The minimum/maximum font sizes used for multiline text auto sizing

valueback to summary
private String value

Constructor Detail

AppearanceGeneratorHelperback to summary
pack-priv AppearanceGeneratorHelper(PDVariableText field) throws IOException

Constructs a COSAppearance from the given field.

Parameters
field:PDVariableText

the field which you wish to control the appearance of

Method Detail

applyPaddingback to summary
private PDRectangle applyPadding(PDRectangle box, float padding)

Apply padding to a box.

Parameters
box:PDRectangle

box

Returns:PDRectangle

the padded box.

calculateFontSizeback to summary
private float calculateFontSize(PDFont font, PDRectangle contentRect) throws IOException

My "not so great" method for calculating the fontsize. It does not work superb, but it handles ok.

Returns:float

the calculated font-size

Exceptions
IOException:
If there is an error getting the font information.
calculateMatrixback to summary
private AffineTransform calculateMatrix(PDRectangle bbox, int rotation)
getFormattedValueback to summary
private String getFormattedValue(String apValue)
getTextAlignback to summary
private int getTextAlign(PDAnnotationWidget widget)
getWidgetDefaultAppearanceStringback to summary
private PDDefaultAppearanceString getWidgetDefaultAppearanceString(PDAnnotationWidget widget) throws IOException
initializeAppearanceContentback to summary
private void initializeAppearanceContent(PDAnnotationWidget widget, PDAppearanceCharacteristicsDictionary appearanceCharacteristics, PDAppearanceStream appearanceStream) throws IOException

Initialize the content of the appearance stream. Get settings like border style, border width and colors to be used to draw a rectangle and background color around the widget

Parameters
widget:PDAnnotationWidget

the field widget

appearanceCharacteristics:PDAppearanceCharacteristicsDictionary

the appearance characteristics dictionary from the widget or null

appearanceStream:PDAppearanceStream

the appearance stream to be used

Exceptions
IOException:
in case we can't write to the appearance stream
insertGeneratedAppearanceback to summary
private void insertGeneratedAppearance(PDAnnotationWidget widget, PDAppearanceStream appearanceStream, OutputStream output) throws IOException

Generate and insert text content and clipping around it.

insertGeneratedCombAppearanceback to summary
private void insertGeneratedCombAppearance(PDAppearanceContentStream contents, PDAppearanceStream appearanceStream, PDFont font, float fontSize) throws IOException

Generate the appearance for comb fields.

Parameters
contents:PDAppearanceContentStream

the content stream to write to

appearanceStream:PDAppearanceStream

the appearance stream used

font:PDFont

the font to be used

fontSize:float

the font size to be used

insertGeneratedListboxAppearanceback to summary
private void insertGeneratedListboxAppearance(PDAppearanceContentStream contents, PDAppearanceStream appearanceStream, PDRectangle contentRect, PDFont font, float fontSize) throws IOException
insertGeneratedListboxSelectionHighlightback to summary
private void insertGeneratedListboxSelectionHighlight(PDAppearanceContentStream contents, PDAppearanceStream appearanceStream, PDFont font, float fontSize) throws IOException
isMultiLineback to summary
private boolean isMultiLine()
isValidAppearanceStreamback to summary
private static boolean isValidAppearanceStream(PDAppearanceEntry appearance)
prepareNormalAppearanceStreamback to summary
private PDAppearanceStream prepareNormalAppearanceStream(PDAnnotationWidget widget)
resolveBoundingBoxback to summary
private PDRectangle resolveBoundingBox(PDAnnotationWidget fieldWidget, PDAppearanceStream appearanceStream)

Resolve the bounding box.

Parameters
fieldWidget:PDAnnotationWidget

the annotation widget.

appearanceStream:PDAppearanceStream

the annotations appearance stream.

Returns:PDRectangle

the resolved boundingBox.

resolveCapHeightback to summary
private float resolveCapHeight(PDFont font) throws IOException
resolveDescentback to summary
private float resolveDescent(PDFont font) throws IOException
resolveGlyphHeightback to summary
private float resolveGlyphHeight(PDFont font, int code) throws IOException
resolveRotationback to summary
private int resolveRotation(PDAnnotationWidget widget)
setAppearanceContentback to summary
private void setAppearanceContent(PDAnnotationWidget widget, PDAppearanceStream appearanceStream) throws IOException

Constructs and sets new contents for given appearance stream.

setAppearanceValueback to summary
public void setAppearanceValue(String apValue) throws IOException

This is the public method for setting the appearance stream.

Parameters
apValue:String

the String value which the appearance should represent

Exceptions
IOException:
If there is an error creating the stream.
shallCombback to summary
private boolean shallComb()

Determine if the appearance shall provide a comb output.

May be set only if the MaxLen entry is present in the text field dictionary and if the Multiline, Password, and FileSelect flags are clear. If set, the field shall be automatically divided into as many equally spaced positions, or combs, as the value of MaxLen, and the text is laid out into those combs.

Returns:boolean

the comb state

validateAndEnsureAcroFormResourcesback to summary
private void validateAndEnsureAcroFormResources()
writeToStreamback to summary
private void writeToStream(byte[] data, PDAppearanceStream appearanceStream) throws IOException

Writes the stream to the actual stream in the COSStream.

Exceptions
IOException:
If there is an error writing to the stream