Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.interactive.annotation.handlers

pack-priv Class CloudyBorder

extends Object
Class Inheritance
Imports
java.awt.geom.AffineTransform, .Ellipse2D, .PathIterator, .Point2D, java.io.IOException, java.util.ArrayList, org.apache.pdfbox.pdmodel.common.PDRectangle, org.apache.pdfbox.pdmodel.PDAppearanceContentStream

Generates annotation appearances with a cloudy border.

Dashed stroke styles are not recommended with cloudy borders. The result would not look good because some parts of the arcs are traced twice by the stroked path. Actually Acrobat Reader's line style dialog does not allow to choose a dashed and a cloudy style at the same time.

Field Summary

Modifier and TypeField and Description
private static final double
private static final double
private static final double
private static final double
private static final double
private final PDRectangle
private double
private double
private double
private double
private final double
private final double
private final PDAppearanceContentStream
private boolean
private PDRectangle

Constructor Summary

AccessConstructor and Description
pack-priv
CloudyBorder(PDAppearanceContentStream
content stream
stream
,
double
intensity of cloudy effect (entry I); typically 1.0 or 2.0
intensity
,
double
line width for annotation border (entry W)
lineWidth
,
PDRectangle
annotation rectangle (entry Rect)
rect
)

Creates a new CloudyBorder that writes to the specified content stream.

Method Summary

Modifier and TypeMethod and Description
private void
addCornerCurl(double anglePrev, double angleCur, double radius, double cx, double cy, double alpha, double alphaPrev, boolean addMoveTo)

Creates a corner curl for polygons and ellipses.

private void
addFirstIntermediateCurl(double angleCur, double r, double alpha, double cx, double cy)

Generates the first intermediate curl for a cloudy polygon.

private PDRectangle
applyRectDiff(PDRectangle rd, float min)

private void
beginOutput(double x, double y)

private void
cloudyEllipseImpl(final double leftOrig, final double bottomOrig, final double rightOrig, final double topOrig)

Cloudy ellipse implementation.

private void
cloudyPolygonImpl(Point2D.Double[]
polygon vertices; first and last point must be equal
vertices
,
boolean
specifies if the polygon represents an ellipse
isEllipse
)

Cloudy polygon implementation.

private void
cloudyRectangleImpl(double left, double bottom, double right, double top, boolean isEllipse)

Cloudy rectangle implementation is based on converting the rectangle to a polygon.

private double
computeParamsEllipse(Point2D.Double pt, Point2D.Double ptNext, double r, double curlAdv)

Computes the alpha parameter for an ellipse curl.

private int
computeParamsPolygon(double advInterm, double advCorner, double k, double r, double length, double[] array)

Computes parameters for a cloudy polygon: n, alpha, and dx.

private static double
cosine(double dx, double hypot)

pack-priv void
createCloudyEllipse(PDRectangle
entry RD, or null if the entry does not exist
rd
)

Creates a cloudy border for a Circle annotation.

pack-priv void
createCloudyPolygon(float[][]
polygon path
path
)

Creates a cloudy border for a Polygon annotation.

pack-priv void
createCloudyRectangle(PDRectangle
entry RD, or null if the entry does not exist
rd
)

Creates a cloudy border for a rectangular annotation.

private void
curveTo(double ax, double ay, double bx, double by, double cx, double cy)

private void
drawBasicEllipse(double left, double bottom, double right, double top)

Draws an ellipse without a cloudy border effect.

private void
private static Point2D.Double[]
flattenEllipse(double left, double bottom, double right, double top)

Flattens an ellipse into a polygon.

private void
getArc(double startAng, double endAng, double rx, double ry, double cx, double cy, ArrayList<Point2D.Double> out, boolean addMoveTo)

Creates one or more Bézier curves that represent an elliptical arc.

private void
getArcSegment(double startAng, double endAng, double cx, double cy, double rx, double ry, ArrayList<Point2D.Double> out, boolean addMoveTo)

Creates a single Bézier curve that represents a section of an elliptical arc.

pack-priv PDRectangle

Returns:

Bounding box for appearance stream form XObject.
getBBox
()

Returns the BBox entry (bounding box) for the appearance stream form XObject.

private double
private Point2D.Double[]
getIntermediateCurlTemplate(double angleCur, double r)

Returns a template for intermediate curls in a cloudy polygon.

pack-priv AffineTransform

Returns:

Matrix for appearance stream form XObject.
getMatrix
()

Returns the Matrix entry for the appearance stream form XObject.

private double
private double
getPolygonDirection(Point2D.Double[] points)

Returns the direction of the specified polygon.

private void
getPositivePolygon(Point2D.Double[] points)

Makes a polygon whose direction is the same as the positive angle direction in the coordinate system.

pack-priv PDRectangle

Returns:

Annotation Rect.
getRectangle
()

Returns the updated Rect entry for the annotation.

pack-priv PDRectangle

Returns:

Annotation RD value.
getRectDifference
()

Returns the updated RD entry for Square and Circle annotations.

private void
private void
lineTo(double x, double y)

private void
private void
moveTo(double x, double y)

private void
outputCurlTemplate(Point2D.Double[] template, double x, double y)

Writes the curl template points to the output and applies translation (x, y).

private Point2D.Double[]
private void
private static double
sine(double dy, double hypot)

private void
updateBBox(double x, double y)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANGLE_12_DEGback to summary
private static final double ANGLE_12_DEG
ANGLE_180_DEGback to summary
private static final double ANGLE_180_DEG
ANGLE_30_DEGback to summary
private static final double ANGLE_30_DEG
ANGLE_34_DEGback to summary
private static final double ANGLE_34_DEG
ANGLE_90_DEGback to summary
private static final double ANGLE_90_DEG
annotRectback to summary
private final PDRectangle annotRect
bboxMaxXback to summary
private double bboxMaxX
bboxMaxYback to summary
private double bboxMaxY
bboxMinXback to summary
private double bboxMinX
bboxMinYback to summary
private double bboxMinY
intensityback to summary
private final double intensity
lineWidthback to summary
private final double lineWidth
outputback to summary
private final PDAppearanceContentStream output
outputStartedback to summary
private boolean outputStarted
rectWithDiffback to summary
private PDRectangle rectWithDiff

Constructor Detail

CloudyBorderback to summary
pack-priv CloudyBorder(PDAppearanceContentStream stream, double intensity, double lineWidth, PDRectangle rect)

Creates a new CloudyBorder that writes to the specified content stream.

Parameters
stream:PDAppearanceContentStream

content stream

intensity:double

intensity of cloudy effect (entry I); typically 1.0 or 2.0

lineWidth:double

line width for annotation border (entry W)

rect:PDRectangle

annotation rectangle (entry Rect)

Method Detail

addCornerCurlback to summary
private void addCornerCurl(double anglePrev, double angleCur, double radius, double cx, double cy, double alpha, double alphaPrev, boolean addMoveTo) throws IOException

Creates a corner curl for polygons and ellipses.

addFirstIntermediateCurlback to summary
private void addFirstIntermediateCurl(double angleCur, double r, double alpha, double cx, double cy) throws IOException

Generates the first intermediate curl for a cloudy polygon.

applyRectDiffback to summary
private PDRectangle applyRectDiff(PDRectangle rd, float min)
beginOutputback to summary
private void beginOutput(double x, double y) throws IOException
cloudyEllipseImplback to summary
private void cloudyEllipseImpl(final double leftOrig, final double bottomOrig, final double rightOrig, final double topOrig) throws IOException

Cloudy ellipse implementation.

cloudyPolygonImplback to summary
private void cloudyPolygonImpl(Point2D.Double[] vertices, boolean isEllipse) throws IOException

Cloudy polygon implementation.

Parameters
vertices:Point2D.Double[]

polygon vertices; first and last point must be equal

isEllipse:boolean

specifies if the polygon represents an ellipse

cloudyRectangleImplback to summary
private void cloudyRectangleImpl(double left, double bottom, double right, double top, boolean isEllipse) throws IOException

Cloudy rectangle implementation is based on converting the rectangle to a polygon.

computeParamsEllipseback to summary
private double computeParamsEllipse(Point2D.Double pt, Point2D.Double ptNext, double r, double curlAdv)

Computes the alpha parameter for an ellipse curl.

computeParamsPolygonback to summary
private int computeParamsPolygon(double advInterm, double advCorner, double k, double r, double length, double[] array)

Computes parameters for a cloudy polygon: n, alpha, and dx.

cosineback to summary
private static double cosine(double dx, double hypot)
createCloudyEllipseback to summary
pack-priv void createCloudyEllipse(PDRectangle rd) throws IOException

Creates a cloudy border for a Circle annotation. The ellipse is specified by the RD entry and the Rect entry that was passed in to the constructor.

Parameters
rd:PDRectangle

entry RD, or null if the entry does not exist

Exceptions
IOException:
If there is an error writing to the stream.
createCloudyPolygonback to summary
pack-priv void createCloudyPolygon(float[][] path) throws IOException

Creates a cloudy border for a Polygon annotation.

Parameters
path:float[][]

polygon path

Exceptions
IOException:
If there is an error writing to the stream.
createCloudyRectangleback to summary
pack-priv void createCloudyRectangle(PDRectangle rd) throws IOException

Creates a cloudy border for a rectangular annotation. The rectangle is specified by the RD entry and the Rect entry that was passed in to the constructor.

This can be used for Square and FreeText annotations. However, this does not produce the text and the callout line for FreeTexts.

Parameters
rd:PDRectangle

entry RD, or null if the entry does not exist

Exceptions
IOException:
If there is an error writing to the stream.
curveToback to summary
private void curveTo(double ax, double ay, double bx, double by, double cx, double cy) throws IOException
drawBasicEllipseback to summary
private void drawBasicEllipse(double left, double bottom, double right, double top) throws IOException

Draws an ellipse without a cloudy border effect.

finishback to summary
private void finish() throws IOException
flattenEllipseback to summary
private static Point2D.Double[] flattenEllipse(double left, double bottom, double right, double top)

Flattens an ellipse into a polygon.

getArcback to summary
private void getArc(double startAng, double endAng, double rx, double ry, double cx, double cy, ArrayList<Point2D.Double> out, boolean addMoveTo) throws IOException

Creates one or more Bézier curves that represent an elliptical arc. Angles are in radians. The arc will always proceed in the positive angle direction. If the argument `out` is null, this writes the results to the instance variable `output`.

getArcSegmentback to summary
private void getArcSegment(double startAng, double endAng, double cx, double cy, double rx, double ry, ArrayList<Point2D.Double> out, boolean addMoveTo) throws IOException

Creates a single Bézier curve that represents a section of an elliptical arc. The sweep angle of the section must not be larger than 90 degrees. If argument `out` is null, this writes the results to the instance variable `output`.

getBBoxback to summary
pack-priv PDRectangle getBBox()

Returns the BBox entry (bounding box) for the appearance stream form XObject.

Returns:PDRectangle

Bounding box for appearance stream form XObject.

getEllipseCloudRadiusback to summary
private double getEllipseCloudRadius()
getIntermediateCurlTemplateback to summary
private Point2D.Double[] getIntermediateCurlTemplate(double angleCur, double r) throws IOException

Returns a template for intermediate curls in a cloudy polygon.

getMatrixback to summary
pack-priv AffineTransform getMatrix()

Returns the Matrix entry for the appearance stream form XObject.

Returns:AffineTransform

Matrix for appearance stream form XObject.

getPolygonCloudRadiusback to summary
private double getPolygonCloudRadius()
getPolygonDirectionback to summary
private double getPolygonDirection(Point2D.Double[] points)

Returns the direction of the specified polygon. A positive value indicates that the polygon's direction is the same as the direction of positive angles in the coordinate system. A negative value indicates the opposite direction. The polygon must not intersect itself. A 2-point polygon is not acceptable. This is based on the "shoelace formula".

getPositivePolygonback to summary
private void getPositivePolygon(Point2D.Double[] points)

Makes a polygon whose direction is the same as the positive angle direction in the coordinate system. The polygon must not intersect itself.

getRectangleback to summary
pack-priv PDRectangle getRectangle()

Returns the updated Rect entry for the annotation. The rectangle completely contains the cloudy border.

Returns:PDRectangle

Annotation Rect.

getRectDifferenceback to summary
pack-priv PDRectangle getRectDifference()

Returns the updated RD entry for Square and Circle annotations.

Returns:PDRectangle

Annotation RD value.

lineToback to summary
private void lineTo(Point2D.Double p) throws IOException
lineToback to summary
private void lineTo(double x, double y) throws IOException
moveToback to summary
private void moveTo(Point2D.Double p) throws IOException
moveToback to summary
private void moveTo(double x, double y) throws IOException
outputCurlTemplateback to summary
private void outputCurlTemplate(Point2D.Double[] template, double x, double y) throws IOException

Writes the curl template points to the output and applies translation (x, y).

removeZeroLengthSegmentsback to summary
private Point2D.Double[] removeZeroLengthSegments(Point2D.Double[] polygon)
reversePolygonback to summary
private void reversePolygon(Point2D.Double[] points)
sineback to summary
private static double sine(double dy, double hypot)
updateBBoxback to summary
private void updateBBox(double x, double y)