Class PDAbstractAppearanceHandler
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDAbstractAppearanceHandler
-
- All Implemented Interfaces:
PDAppearanceHandler
- Direct Known Subclasses:
PDCaretAppearanceHandler
,PDCircleAppearanceHandler
,PDFreeTextAppearanceHandler
,PDHighlightAppearanceHandler
,PDInkAppearanceHandler
,PDLineAppearanceHandler
,PDLinkAppearanceHandler
,PDPolygonAppearanceHandler
,PDPolylineAppearanceHandler
,PDSoundAppearanceHandler
,PDSquareAppearanceHandler
,PDSquigglyAppearanceHandler
,PDStrikeoutAppearanceHandler
,PDTextAppearanceHandler
,PDUnderlineAppearanceHandler
public abstract class PDAbstractAppearanceHandler extends java.lang.Object implements PDAppearanceHandler
Generic handler to generate the fields appearance. Individual handler will provide specific implementations for different field types.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.Set<java.lang.String>
ANGLED_STYLES
Line ending styles where the shape changes its angle, e.g.private PDAnnotation
annotation
(package private) static double
ARROW_ANGLE
protected PDDocument
document
protected static java.util.Set<java.lang.String>
INTERIOR_COLOR_STYLES
Line ending styles where there is an interior color.protected static java.util.Set<java.lang.String>
SHORT_STYLES
Line ending styles where the line has to be drawn shorter (minus line width).
-
Constructor Summary
Constructors Constructor Description PDAbstractAppearanceHandler(PDAnnotation annotation)
PDAbstractAppearanceHandler(PDAnnotation annotation, PDDocument document)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) PDRectangle
addRectDifferences(PDRectangle rectangle, float[] differences)
Get a rectangle enlarged by the differences.(package private) PDRectangle
applyRectDifferences(PDRectangle rectangle, float[] differences)
Get a rectangle with the differences applied to each side.private static java.util.Set<java.lang.String>
createAngledStyles()
protected COSStream
createCOSStream()
private static java.util.Set<java.lang.String>
createInteriorColorStyles()
private static java.util.Set<java.lang.String>
createShortStyles()
(package private) void
drawArrow(PDAppearanceContentStream cs, float x, float y, float len)
Add the two arms of a horizontal arrow.(package private) void
drawCircle(PDAppearanceContentStream cs, float x, float y, float r)
Add a circle shape to the path in clockwise direction.(package private) void
drawCircle2(PDAppearanceContentStream cs, float x, float y, float r)
Add a circle shape to the path in counterclockwise direction.(package private) void
drawDiamond(PDAppearanceContentStream cs, float x, float y, float r)
Add a square diamond shape (corner on top) to the path.(package private) void
drawStyle(java.lang.String style, PDAppearanceContentStream cs, float x, float y, float width, boolean hasStroke, boolean hasBackground, boolean ending)
Draw a line ending style.(package private) PDAnnotation
getAnnotation()
(package private) PDAppearanceDictionary
getAppearance()
Get the annotations appearance dictionary.private PDAppearanceContentStream
getAppearanceEntryAsContentStream(PDAppearanceEntry appearanceEntry, boolean compress)
(package private) PDColor
getColor()
(package private) PDAppearanceEntry
getDownAppearance()
Get the annotations down appearance.private PDAppearanceEntry
getNormalAppearance()
Get the annotations normal appearance.(package private) PDAppearanceContentStream
getNormalAppearanceAsContentStream()
Get the annotations normal appearance content stream.(package private) PDAppearanceContentStream
getNormalAppearanceAsContentStream(boolean compress)
Get the annotations normal appearance content stream.(package private) PDRectangle
getPaddedRectangle(PDRectangle rectangle, float padding)
Get a padded rectangle.(package private) PDRectangle
getRectangle()
(package private) PDAppearanceEntry
getRolloverAppearance()
Get the annotations rollover appearance.(package private) PDRectangle
handleBorderBox(PDAnnotationSquareCircle annotation, float lineWidth)
(package private) void
setOpacity(PDAppearanceContentStream contentStream, float opacity)
private void
setTransformationMatrix(PDAppearanceStream appearanceStream)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDAppearanceHandler
generateAppearanceStreams, generateDownAppearance, generateNormalAppearance, generateRolloverAppearance
-
-
-
-
Field Detail
-
annotation
private final PDAnnotation annotation
-
document
protected PDDocument document
-
SHORT_STYLES
protected static final java.util.Set<java.lang.String> SHORT_STYLES
Line ending styles where the line has to be drawn shorter (minus line width).
-
ARROW_ANGLE
static final double ARROW_ANGLE
-
INTERIOR_COLOR_STYLES
protected static final java.util.Set<java.lang.String> INTERIOR_COLOR_STYLES
Line ending styles where there is an interior color.
-
ANGLED_STYLES
protected static final java.util.Set<java.lang.String> ANGLED_STYLES
Line ending styles where the shape changes its angle, e.g. arrows.
-
-
Constructor Detail
-
PDAbstractAppearanceHandler
public PDAbstractAppearanceHandler(PDAnnotation annotation)
-
PDAbstractAppearanceHandler
public PDAbstractAppearanceHandler(PDAnnotation annotation, PDDocument document)
-
-
Method Detail
-
getAnnotation
PDAnnotation getAnnotation()
-
getColor
PDColor getColor()
-
getRectangle
PDRectangle getRectangle()
-
createCOSStream
protected COSStream createCOSStream()
-
getAppearance
PDAppearanceDictionary getAppearance()
Get the annotations appearance dictionary.This will get the annotations appearance dictionary. If this is not existent an empty appearance dictionary will be created.
- Returns:
- the annotations appearance dictionary
-
getNormalAppearanceAsContentStream
PDAppearanceContentStream getNormalAppearanceAsContentStream() throws java.io.IOException
Get the annotations normal appearance content stream.This will get the annotations normal appearance content stream, to 'draw' to. It will be uncompressed.
- Returns:
- the appearance entry representing the normal appearance.
- Throws:
java.io.IOException
-
getNormalAppearanceAsContentStream
PDAppearanceContentStream getNormalAppearanceAsContentStream(boolean compress) throws java.io.IOException
Get the annotations normal appearance content stream.This will get the annotations normal appearance content stream, to 'draw' to.
- Parameters:
compress
- whether the content stream is to be compressed. Set this to true when creating long content streams.- Returns:
- the appearance entry representing the normal appearance.
- Throws:
java.io.IOException
-
getDownAppearance
PDAppearanceEntry getDownAppearance()
Get the annotations down appearance.This will get the annotations down appearance. If this is not existent an empty appearance entry will be created.
- Returns:
- the appearance entry representing the down appearance.
-
getRolloverAppearance
PDAppearanceEntry getRolloverAppearance()
Get the annotations rollover appearance.This will get the annotations rollover appearance. If this is not existent an empty appearance entry will be created.
- Returns:
- the appearance entry representing the rollover appearance.
-
getPaddedRectangle
PDRectangle getPaddedRectangle(PDRectangle rectangle, float padding)
Get a padded rectangle.Creates a new rectangle with padding applied to each side. .
- Parameters:
rectangle
- the rectangle.padding
- the padding to apply.- Returns:
- the padded rectangle.
-
addRectDifferences
PDRectangle addRectDifferences(PDRectangle rectangle, float[] differences)
Get a rectangle enlarged by the differences.Creates a new rectangle with differences added to each side. If there are no valid differences, then the original rectangle is returned.
- Parameters:
rectangle
- the rectangle.differences
- the differences to apply.- Returns:
- the padded rectangle.
-
applyRectDifferences
PDRectangle applyRectDifferences(PDRectangle rectangle, float[] differences)
Get a rectangle with the differences applied to each side.Creates a new rectangle with differences added to each side. If there are no valid differences, then the original rectangle is returned.
- Parameters:
rectangle
- the rectangle.differences
- the differences to apply.- Returns:
- the padded rectangle.
-
setOpacity
void setOpacity(PDAppearanceContentStream contentStream, float opacity) throws java.io.IOException
- Throws:
java.io.IOException
-
drawStyle
void drawStyle(java.lang.String style, PDAppearanceContentStream cs, float x, float y, float width, boolean hasStroke, boolean hasBackground, boolean ending) throws java.io.IOException
Draw a line ending style.- Parameters:
style
-cs
-x
-y
-width
-hasStroke
-hasBackground
-ending
- false if left, true if right of an imagined horizontal line (important for arrows).- Throws:
java.io.IOException
-
drawArrow
void drawArrow(PDAppearanceContentStream cs, float x, float y, float len) throws java.io.IOException
Add the two arms of a horizontal arrow.- Parameters:
cs
- Content streamx
-y
-len
- The arm length. Positive goes to the right, negative goes to the left.- Throws:
java.io.IOException
- If the content stream could not be written
-
drawDiamond
void drawDiamond(PDAppearanceContentStream cs, float x, float y, float r) throws java.io.IOException
Add a square diamond shape (corner on top) to the path.- Parameters:
cs
- Content streamx
-y
-r
- Radius (to a corner)- Throws:
java.io.IOException
- If the content stream could not be written
-
drawCircle
void drawCircle(PDAppearanceContentStream cs, float x, float y, float r) throws java.io.IOException
Add a circle shape to the path in clockwise direction.- Parameters:
cs
- Content streamx
-y
-r
- Radius- Throws:
java.io.IOException
- If the content stream could not be written.
-
drawCircle2
void drawCircle2(PDAppearanceContentStream cs, float x, float y, float r) throws java.io.IOException
Add a circle shape to the path in counterclockwise direction. You'll need this e.g. when drawing a doughnut shape. See "Nonzero Winding Number Rule" for more information.- Parameters:
cs
- Content streamx
-y
-r
- Radius- Throws:
java.io.IOException
- If the content stream could not be written.
-
createShortStyles
private static java.util.Set<java.lang.String> createShortStyles()
-
createInteriorColorStyles
private static java.util.Set<java.lang.String> createInteriorColorStyles()
-
createAngledStyles
private static java.util.Set<java.lang.String> createAngledStyles()
-
getNormalAppearance
private PDAppearanceEntry getNormalAppearance()
Get the annotations normal appearance.This will get the annotations normal appearance. If this is not existent an empty appearance entry will be created.
- Returns:
- the appearance entry representing the normal appearance.
-
getAppearanceEntryAsContentStream
private PDAppearanceContentStream getAppearanceEntryAsContentStream(PDAppearanceEntry appearanceEntry, boolean compress) throws java.io.IOException
- Throws:
java.io.IOException
-
setTransformationMatrix
private void setTransformationMatrix(PDAppearanceStream appearanceStream)
-
handleBorderBox
PDRectangle handleBorderBox(PDAnnotationSquareCircle annotation, float lineWidth)
-
-