Class CloudyBorder
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.interactive.annotation.handlers.CloudyBorder
-
class CloudyBorder extends java.lang.ObjectGenerates 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
Fields Modifier and Type Field Description private static doubleANGLE_12_DEGprivate static doubleANGLE_180_DEGprivate static doubleANGLE_30_DEGprivate static doubleANGLE_34_DEGprivate static doubleANGLE_90_DEGprivate PDRectangleannotRectprivate doublebboxMaxXprivate doublebboxMaxYprivate doublebboxMinXprivate doublebboxMinYprivate doubleintensityprivate doublelineWidthprivate PDAppearanceContentStreamoutputprivate booleanoutputStartedprivate PDRectanglerectWithDiff
-
Constructor Summary
Constructors Constructor Description CloudyBorder(PDAppearanceContentStream stream, double intensity, double lineWidth, PDRectangle rect)Creates a newCloudyBorderthat writes to the specified content stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddCornerCurl(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 voidaddFirstIntermediateCurl(double angleCur, double r, double alpha, double cx, double cy)Generates the first intermediate curl for a cloudy polygon.private PDRectangleapplyRectDiff(PDRectangle rd, float min)private voidbeginOutput(double x, double y)private voidcloudyEllipseImpl(double leftOrig, double bottomOrig, double rightOrig, double topOrig)Cloudy ellipse implementation.private voidcloudyPolygonImpl(java.awt.geom.Point2D.Double[] vertices, boolean isEllipse)Cloudy polygon implementation.private voidcloudyRectangleImpl(double left, double bottom, double right, double top, boolean isEllipse)Cloudy rectangle implementation is based on converting the rectangle to a polygon.private doublecomputeParamsEllipse(java.awt.geom.Point2D.Double pt, java.awt.geom.Point2D.Double ptNext, double r, double curlAdv)Computes the alpha parameter for an ellipse curl.private intcomputeParamsPolygon(double advInterm, double advCorner, double k, double r, double length, double[] array)Computes parameters for a cloudy polygon: n, alpha, and dx.private static doublecosine(double dx, double hypot)(package private) voidcreateCloudyEllipse(PDRectangle rd)Creates a cloudy border for a Circle annotation.(package private) voidcreateCloudyPolygon(float[][] path)Creates a cloudy border for a Polygon annotation.(package private) voidcreateCloudyRectangle(PDRectangle rd)Creates a cloudy border for a rectangular annotation.private voidcurveTo(double ax, double ay, double bx, double by, double cx, double cy)private voiddrawBasicEllipse(double left, double bottom, double right, double top)Draws an ellipse without a cloudy border effect.private voidfinish()private static java.awt.geom.Point2D.Double[]flattenEllipse(double left, double bottom, double right, double top)Flattens an ellipse into a polygon.private voidgetArc(double startAng, double endAng, double rx, double ry, double cx, double cy, java.util.ArrayList<java.awt.geom.Point2D.Double> out, boolean addMoveTo)Creates one or more Bézier curves that represent an elliptical arc.private voidgetArcSegment(double startAng, double endAng, double cx, double cy, double rx, double ry, java.util.ArrayList<java.awt.geom.Point2D.Double> out, boolean addMoveTo)Creates a single Bézier curve that represents a section of an elliptical arc.(package private) PDRectanglegetBBox()Returns theBBoxentry (bounding box) for the appearance stream form XObject.private doublegetEllipseCloudRadius()private java.awt.geom.Point2D.Double[]getIntermediateCurlTemplate(double angleCur, double r)Returns a template for intermediate curls in a cloudy polygon.(package private) java.awt.geom.AffineTransformgetMatrix()Returns theMatrixentry for the appearance stream form XObject.private doublegetPolygonCloudRadius()private doublegetPolygonDirection(java.awt.geom.Point2D.Double[] points)Returns the direction of the specified polygon.private voidgetPositivePolygon(java.awt.geom.Point2D.Double[] points)Makes a polygon whose direction is the same as the positive angle direction in the coordinate system.(package private) PDRectanglegetRectangle()Returns the updatedRectentry for the annotation.(package private) PDRectanglegetRectDifference()Returns the updatedRDentry for Square and Circle annotations.private voidlineTo(double x, double y)private voidlineTo(java.awt.geom.Point2D.Double p)private voidmoveTo(double x, double y)private voidmoveTo(java.awt.geom.Point2D.Double p)private voidoutputCurlTemplate(java.awt.geom.Point2D.Double[] template, double x, double y)Writes the curl template points to the output and applies translation (x, y).private java.awt.geom.Point2D.Double[]removeZeroLengthSegments(java.awt.geom.Point2D.Double[] polygon)private voidreversePolygon(java.awt.geom.Point2D.Double[] points)private static doublesine(double dy, double hypot)private voidupdateBBox(double x, double y)
-
-
-
Field Detail
-
ANGLE_180_DEG
private static final double ANGLE_180_DEG
- See Also:
- Constant Field Values
-
ANGLE_90_DEG
private static final double ANGLE_90_DEG
- See Also:
- Constant Field Values
-
ANGLE_34_DEG
private static final double ANGLE_34_DEG
-
ANGLE_30_DEG
private static final double ANGLE_30_DEG
-
ANGLE_12_DEG
private static final double ANGLE_12_DEG
-
output
private final PDAppearanceContentStream output
-
annotRect
private final PDRectangle annotRect
-
intensity
private final double intensity
-
lineWidth
private final double lineWidth
-
rectWithDiff
private PDRectangle rectWithDiff
-
outputStarted
private boolean outputStarted
-
bboxMinX
private double bboxMinX
-
bboxMinY
private double bboxMinY
-
bboxMaxX
private double bboxMaxX
-
bboxMaxY
private double bboxMaxY
-
-
Constructor Detail
-
CloudyBorder
CloudyBorder(PDAppearanceContentStream stream, double intensity, double lineWidth, PDRectangle rect)
Creates a newCloudyBorderthat writes to the specified content stream.- Parameters:
stream- content streamintensity- intensity of cloudy effect (entryI); typically 1.0 or 2.0lineWidth- line width for annotation border (entryW)rect- annotation rectangle (entryRect)
-
-
Method Detail
-
createCloudyRectangle
void createCloudyRectangle(PDRectangle rd) throws java.io.IOException
Creates a cloudy border for a rectangular annotation. The rectangle is specified by theRDentry and theRectentry 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- entryRD, or null if the entry does not exist- Throws:
java.io.IOException- If there is an error writing to the stream.
-
createCloudyPolygon
void createCloudyPolygon(float[][] path) throws java.io.IOExceptionCreates a cloudy border for a Polygon annotation.- Parameters:
path- polygon path- Throws:
java.io.IOException- If there is an error writing to the stream.
-
createCloudyEllipse
void createCloudyEllipse(PDRectangle rd) throws java.io.IOException
Creates a cloudy border for a Circle annotation. The ellipse is specified by theRDentry and theRectentry that was passed in to the constructor.- Parameters:
rd- entryRD, or null if the entry does not exist- Throws:
java.io.IOException- If there is an error writing to the stream.
-
getBBox
PDRectangle getBBox()
Returns theBBoxentry (bounding box) for the appearance stream form XObject.- Returns:
- Bounding box for appearance stream form XObject.
-
getRectangle
PDRectangle getRectangle()
Returns the updatedRectentry for the annotation. The rectangle completely contains the cloudy border.- Returns:
- Annotation
Rect.
-
getMatrix
java.awt.geom.AffineTransform getMatrix()
Returns theMatrixentry for the appearance stream form XObject.- Returns:
- Matrix for appearance stream form XObject.
-
getRectDifference
PDRectangle getRectDifference()
Returns the updatedRDentry for Square and Circle annotations.- Returns:
- Annotation
RDvalue.
-
cosine
private static double cosine(double dx, double hypot)
-
sine
private static double sine(double dy, double hypot)
-
cloudyRectangleImpl
private void cloudyRectangleImpl(double left, double bottom, double right, double top, boolean isEllipse) throws java.io.IOExceptionCloudy rectangle implementation is based on converting the rectangle to a polygon.- Throws:
java.io.IOException
-
cloudyPolygonImpl
private void cloudyPolygonImpl(java.awt.geom.Point2D.Double[] vertices, boolean isEllipse) throws java.io.IOExceptionCloudy polygon implementation.- Parameters:
vertices- polygon vertices; first and last point must be equalisEllipse- specifies if the polygon represents an ellipse- Throws:
java.io.IOException
-
computeParamsPolygon
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.
-
addCornerCurl
private void addCornerCurl(double anglePrev, double angleCur, double radius, double cx, double cy, double alpha, double alphaPrev, boolean addMoveTo) throws java.io.IOExceptionCreates a corner curl for polygons and ellipses.- Throws:
java.io.IOException
-
addFirstIntermediateCurl
private void addFirstIntermediateCurl(double angleCur, double r, double alpha, double cx, double cy) throws java.io.IOExceptionGenerates the first intermediate curl for a cloudy polygon.- Throws:
java.io.IOException
-
getIntermediateCurlTemplate
private java.awt.geom.Point2D.Double[] getIntermediateCurlTemplate(double angleCur, double r) throws java.io.IOExceptionReturns a template for intermediate curls in a cloudy polygon.- Throws:
java.io.IOException
-
outputCurlTemplate
private void outputCurlTemplate(java.awt.geom.Point2D.Double[] template, double x, double y) throws java.io.IOExceptionWrites the curl template points to the output and applies translation (x, y).- Throws:
java.io.IOException
-
applyRectDiff
private PDRectangle applyRectDiff(PDRectangle rd, float min)
-
reversePolygon
private void reversePolygon(java.awt.geom.Point2D.Double[] points)
-
getPositivePolygon
private void getPositivePolygon(java.awt.geom.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.
-
getPolygonDirection
private double getPolygonDirection(java.awt.geom.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".
-
getArc
private void getArc(double startAng, double endAng, double rx, double ry, double cx, double cy, java.util.ArrayList<java.awt.geom.Point2D.Double> out, boolean addMoveTo) throws java.io.IOExceptionCreates 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`.- Throws:
java.io.IOException
-
getArcSegment
private void getArcSegment(double startAng, double endAng, double cx, double cy, double rx, double ry, java.util.ArrayList<java.awt.geom.Point2D.Double> out, boolean addMoveTo) throws java.io.IOExceptionCreates 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`.- Throws:
java.io.IOException
-
flattenEllipse
private static java.awt.geom.Point2D.Double[] flattenEllipse(double left, double bottom, double right, double top)Flattens an ellipse into a polygon.
-
cloudyEllipseImpl
private void cloudyEllipseImpl(double leftOrig, double bottomOrig, double rightOrig, double topOrig) throws java.io.IOExceptionCloudy ellipse implementation.- Throws:
java.io.IOException
-
computeParamsEllipse
private double computeParamsEllipse(java.awt.geom.Point2D.Double pt, java.awt.geom.Point2D.Double ptNext, double r, double curlAdv)Computes the alpha parameter for an ellipse curl.
-
removeZeroLengthSegments
private java.awt.geom.Point2D.Double[] removeZeroLengthSegments(java.awt.geom.Point2D.Double[] polygon)
-
drawBasicEllipse
private void drawBasicEllipse(double left, double bottom, double right, double top) throws java.io.IOExceptionDraws an ellipse without a cloudy border effect.- Throws:
java.io.IOException
-
beginOutput
private void beginOutput(double x, double y) throws java.io.IOException- Throws:
java.io.IOException
-
updateBBox
private void updateBBox(double x, double y)
-
moveTo
private void moveTo(java.awt.geom.Point2D.Double p) throws java.io.IOException- Throws:
java.io.IOException
-
moveTo
private void moveTo(double x, double y) throws java.io.IOException- Throws:
java.io.IOException
-
lineTo
private void lineTo(java.awt.geom.Point2D.Double p) throws java.io.IOException- Throws:
java.io.IOException
-
lineTo
private void lineTo(double x, double y) throws java.io.IOException- Throws:
java.io.IOException
-
curveTo
private void curveTo(double ax, double ay, double bx, double by, double cx, double cy) throws java.io.IOException- Throws:
java.io.IOException
-
finish
private void finish() throws java.io.IOException- Throws:
java.io.IOException
-
getEllipseCloudRadius
private double getEllipseCloudRadius()
-
getPolygonCloudRadius
private double getPolygonCloudRadius()
-
-