Class PDDefaultAppearanceString
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.interactive.form.PDDefaultAppearanceString
-
class PDDefaultAppearanceString extends java.lang.ObjectRepresents a default appearance string, as found in the /DA entry of free text annotations.The default appearance string (DA) contains any graphics state or text state operators needed to establish the graphics state parameters, such as text size and colour, for displaying the field’s variable text. Only operators that are allowed within text objects shall occur in this string. Note: This class is not yet public, as its API is still unstable.
-
-
Field Summary
Fields Modifier and Type Field Description private static floatDEFAULT_FONT_SIZEThe default font size used by Acrobat.private PDResourcesdefaultResourcesprivate PDFontfontprivate PDColorfontColorprivate COSNamefontNameprivate floatfontSize
-
Constructor Summary
Constructors Constructor Description PDDefaultAppearanceString(COSString defaultAppearance, PDResources defaultResources)Constructor for reading an existing DA string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidcopyNeededResourcesTo(PDAppearanceStream appearanceStream)Copies any needed resources from the document’s DR dictionary into the stream’s Resources dictionary.(package private) PDFontgetFont()Returns the font.(package private) PDColorgetFontColor()Returns the font color(package private) COSNamegetFontName()Get the font namefloatgetFontSize()Returns the font size.private voidprocessAppearanceStringOperators(byte[] content)Processes the operators of the given content stream.private voidprocessOperator(Operator operator, java.util.List<COSBase> operands)This is used to handle an operation.private voidprocessSetFont(java.util.List<COSBase> operands)Process the set font and font size operator.private voidprocessSetFontColor(java.util.List<COSBase> operands)Process the font color operator.(package private) voidsetFont(PDFont font)Set the font.(package private) voidsetFontColor(PDColor fontColor)Set the font color.(package private) voidsetFontName(COSName fontName)Set the font name.(package private) voidsetFontSize(float fontSize)Set the font size.(package private) voidwriteTo(PDAppearanceContentStream contents, float zeroFontSize)Write font name, font size and color from the /DA string to the given content stream.
-
-
-
Field Detail
-
DEFAULT_FONT_SIZE
private static final float DEFAULT_FONT_SIZE
The default font size used by Acrobat.- See Also:
- Constant Field Values
-
defaultResources
private final PDResources defaultResources
-
fontName
private COSName fontName
-
font
private PDFont font
-
fontSize
private float fontSize
-
fontColor
private PDColor fontColor
-
-
Constructor Detail
-
PDDefaultAppearanceString
PDDefaultAppearanceString(COSString defaultAppearance, PDResources defaultResources) throws java.io.IOException
Constructor for reading an existing DA string.- Parameters:
defaultResources- DR entrydefaultAppearance- DA entry- Throws:
java.io.IOException- If the DA could not be parsed
-
-
Method Detail
-
processAppearanceStringOperators
private void processAppearanceStringOperators(byte[] content) throws java.io.IOExceptionProcesses the operators of the given content stream.- Parameters:
content- the content to parse.- Throws:
java.io.IOException- if there is an error reading or parsing the content stream.
-
processOperator
private void processOperator(Operator operator, java.util.List<COSBase> operands) throws java.io.IOException
This is used to handle an operation.- Parameters:
operator- The operation to perform.operands- The list of arguments.- Throws:
java.io.IOException- If there is an error processing the operation.
-
processSetFont
private void processSetFont(java.util.List<COSBase> operands) throws java.io.IOException
Process the set font and font size operator.- Parameters:
operands- the font name and size- Throws:
java.io.IOException- in case there are missing operators or the font is not within the resources
-
processSetFontColor
private void processSetFontColor(java.util.List<COSBase> operands) throws java.io.IOException
Process the font color operator. This is assumed to be an RGB color.- Parameters:
operands- the color components- Throws:
java.io.IOException- in case of the color components not matching
-
getFontName
COSName getFontName()
Get the font name- Returns:
- the font name to use for resource lookup
-
setFontName
void setFontName(COSName fontName)
Set the font name.- Parameters:
fontName- the font name to use for resource lookup
-
getFont
PDFont getFont()
Returns the font.
-
setFont
void setFont(PDFont font)
Set the font.- Parameters:
font- the font to use.
-
getFontSize
public float getFontSize()
Returns the font size.
-
setFontSize
void setFontSize(float fontSize)
Set the font size.- Parameters:
fontSize- the font size.
-
getFontColor
PDColor getFontColor()
Returns the font color
-
setFontColor
void setFontColor(PDColor fontColor)
Set the font color.- Parameters:
fontColor- the fontColor to use.
-
writeTo
void writeTo(PDAppearanceContentStream contents, float zeroFontSize) throws java.io.IOException
Write font name, font size and color from the /DA string to the given content stream.- Parameters:
contents- The content stream.zeroFontSize- The calculated font size to use if the /DA string has a size 0 (autosize). Otherwise the size from the /DA string is used.- Throws:
java.io.IOException
-
copyNeededResourcesTo
void copyNeededResourcesTo(PDAppearanceStream appearanceStream) throws java.io.IOException
Copies any needed resources from the document’s DR dictionary into the stream’s Resources dictionary. Resources with the same name shall be left intact.- Throws:
java.io.IOException
-
-