You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/05/25 17:33:33 UTC
svn commit: r1832257 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/
Author: tilman
Date: Fri May 25 17:33:32 2018
New Revision: 1832257
URL: http://svn.apache.org/viewvc?rev=1832257&view=rev
Log:
PDFBOX-3353: remove unneeded "try" level
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -55,34 +55,31 @@ public class PDCaretAppearanceHandler ex
// Currently, the rendering difference between our content stream and the one from Adobe
// is minimal, about one pixel line at the bottom.
- try
+ PDAnnotationCaret annotation = (PDAnnotationCaret) getAnnotation();
+ try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
{
- PDAnnotationCaret annotation = (PDAnnotationCaret) getAnnotation();
- try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
- {
- contentStream.setStrokingColor(getColor());
- contentStream.setNonStrokingColor(getColor());
-
- setOpacity(contentStream, annotation.getConstantOpacity());
+ contentStream.setStrokingColor(getColor());
+ contentStream.setNonStrokingColor(getColor());
- PDRectangle rect = getRectangle();
- PDRectangle bbox = new PDRectangle(rect.getWidth(), rect.getHeight());
- annotation.getNormalAppearanceStream().setBBox(bbox);
+ setOpacity(contentStream, annotation.getConstantOpacity());
- float halfX = rect.getWidth() / 2;
- float halfY = rect.getHeight() / 2;
- contentStream.moveTo(0, 0);
- contentStream.curveTo(halfX, 0,
- halfX, halfY,
- halfX, rect.getHeight());
- contentStream.curveTo(halfX, halfY,
- halfX, 0,
- rect.getWidth(), 0);
- contentStream.closePath();
- contentStream.fill();
- // Adobe has an additional stroke, but it has no effect
- // because fill "consumes" the path.
- }
+ PDRectangle rect = getRectangle();
+ PDRectangle bbox = new PDRectangle(rect.getWidth(), rect.getHeight());
+ annotation.getNormalAppearanceStream().setBBox(bbox);
+
+ float halfX = rect.getWidth() / 2;
+ float halfY = rect.getHeight() / 2;
+ contentStream.moveTo(0, 0);
+ contentStream.curveTo(halfX, 0,
+ halfX, halfY,
+ halfX, rect.getHeight());
+ contentStream.curveTo(halfX, halfY,
+ halfX, 0,
+ rect.getWidth(), 0);
+ contentStream.closePath();
+ contentStream.fill();
+ // Adobe has an additional stroke, but it has no effect
+ // because fill "consumes" the path.
}
catch (IOException e)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -56,70 +56,67 @@ public class PDCircleAppearanceHandler e
public void generateNormalAppearance()
{
float lineWidth = getLineWidth();
- try
+ PDAnnotationCircle annotation = (PDAnnotationCircle) getAnnotation();
+ try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
{
- PDAnnotationCircle annotation = (PDAnnotationCircle) getAnnotation();
- try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
+ boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());
+ boolean hasBackground = contentStream
+ .setNonStrokingColorOnDemand(annotation.getInteriorColor());
+
+ setOpacity(contentStream, annotation.getConstantOpacity());
+
+ contentStream.setBorderLine(lineWidth, annotation.getBorderStyle());
+ PDBorderEffectDictionary borderEffect = annotation.getBorderEffect();
+
+ // Acrobat applies a padding to each side of the bbox so the line is completely within
+ // the bbox.
+ // TODO: Needs validation for Circles as Adobe Reader seems to extend the bbox bei the rect differenve
+ // for circle annotations.
+ PDRectangle bbox = getRectangle();
+ PDRectangle borderEdge = getPaddedRectangle(bbox,lineWidth/2);
+
+ if (borderEffect != null && borderEffect.getStyle().equals(PDBorderEffectDictionary.STYLE_CLOUDY))
{
- boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());
- boolean hasBackground = contentStream
- .setNonStrokingColorOnDemand(annotation.getInteriorColor());
-
- setOpacity(contentStream, annotation.getConstantOpacity());
-
- contentStream.setBorderLine(lineWidth, annotation.getBorderStyle());
- PDBorderEffectDictionary borderEffect = annotation.getBorderEffect();
-
- // Acrobat applies a padding to each side of the bbox so the line is completely within
- // the bbox.
- // TODO: Needs validation for Circles as Adobe Reader seems to extend the bbox bei the rect differenve
- // for circle annotations.
- PDRectangle bbox = getRectangle();
- PDRectangle borderEdge = getPaddedRectangle(bbox,lineWidth/2);
-
- if (borderEffect != null && borderEffect.getStyle().equals(PDBorderEffectDictionary.STYLE_CLOUDY))
- {
- CloudyBorder cloudyBorder = new CloudyBorder(contentStream,
- borderEffect.getIntensity(), lineWidth, getRectangle());
- cloudyBorder.createCloudyEllipse(annotation.getRectDifference());
- annotation.setRectangle(cloudyBorder.getRectangle());
- annotation.setRectDifference(cloudyBorder.getRectDifference());
- PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
- appearanceStream.setBBox(cloudyBorder.getBBox());
- appearanceStream.setMatrix(cloudyBorder.getMatrix());
- }
- else
- {
- // the differences rectangle
- setRectDifference(lineWidth);
-
- // lower left corner
- float x0 = borderEdge.getLowerLeftX();
- float y0 = borderEdge.getLowerLeftY();
- // upper right corner
- float x1 = borderEdge.getUpperRightX();
- float y1 = borderEdge.getUpperRightY();
- // mid points
- float xm = x0 + borderEdge.getWidth() / 2;
- float ym = y0 + borderEdge.getHeight() / 2;
- // see http://spencermortensen.com/articles/bezier-circle/
- // the below number was calculated from sampling content streams
- // generated using Adobe Reader
- float magic = 0.55555417f;
- // control point offsets
- float vOffset = borderEdge.getHeight() / 2 * magic;
- float hOffset = borderEdge.getWidth() / 2 * magic;
-
- contentStream.moveTo(xm, y1);
- contentStream.curveTo((xm + hOffset), y1, x1, (ym + vOffset), x1, ym);
- contentStream.curveTo(x1, (ym - vOffset), (xm + hOffset), y0, xm, y0);
- contentStream.curveTo((xm - hOffset), y0, x0, (ym - vOffset), x0, ym);
- contentStream.curveTo(x0, (ym + vOffset), (xm - hOffset), y1, xm, y1);
- contentStream.closePath();
- }
-
- contentStream.drawShape(lineWidth, hasStroke, hasBackground);
+ CloudyBorder cloudyBorder = new CloudyBorder(contentStream,
+ borderEffect.getIntensity(), lineWidth, getRectangle());
+ cloudyBorder.createCloudyEllipse(annotation.getRectDifference());
+ annotation.setRectangle(cloudyBorder.getRectangle());
+ annotation.setRectDifference(cloudyBorder.getRectDifference());
+ PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
+ appearanceStream.setBBox(cloudyBorder.getBBox());
+ appearanceStream.setMatrix(cloudyBorder.getMatrix());
}
+ else
+ {
+ // the differences rectangle
+ setRectDifference(lineWidth);
+
+ // lower left corner
+ float x0 = borderEdge.getLowerLeftX();
+ float y0 = borderEdge.getLowerLeftY();
+ // upper right corner
+ float x1 = borderEdge.getUpperRightX();
+ float y1 = borderEdge.getUpperRightY();
+ // mid points
+ float xm = x0 + borderEdge.getWidth() / 2;
+ float ym = y0 + borderEdge.getHeight() / 2;
+ // see http://spencermortensen.com/articles/bezier-circle/
+ // the below number was calculated from sampling content streams
+ // generated using Adobe Reader
+ float magic = 0.55555417f;
+ // control point offsets
+ float vOffset = borderEdge.getHeight() / 2 * magic;
+ float hOffset = borderEdge.getWidth() / 2 * magic;
+
+ contentStream.moveTo(xm, y1);
+ contentStream.curveTo((xm + hOffset), y1, x1, (ym + vOffset), x1, ym);
+ contentStream.curveTo(x1, (ym - vOffset), (xm + hOffset), y0, xm, y0);
+ contentStream.curveTo((xm - hOffset), y0, x0, (ym - vOffset), x0, ym);
+ contentStream.curveTo(x0, (ym + vOffset), (xm - hOffset), y1, xm, y1);
+ contentStream.closePath();
+ }
+
+ contentStream.drawShape(lineWidth, hasStroke, hasBackground);
}
catch (IOException e)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -107,108 +107,105 @@ public class PDHighlightAppearanceHandle
rect.setUpperRightY(Math.max(maxY + ab.width + maxDelta, rect.getUpperRightY()));
annotation.setRectangle(rect);
- try
+ try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
{
- try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
+ PDExtendedGraphicsState r0 = new PDExtendedGraphicsState();
+ PDExtendedGraphicsState r1 = new PDExtendedGraphicsState();
+ r0.setAlphaSourceFlag(false);
+ r0.setStrokingAlphaConstant(annotation.getConstantOpacity());
+ r0.setNonStrokingAlphaConstant(annotation.getConstantOpacity());
+ r1.setAlphaSourceFlag(false);
+ r1.setBlendMode(BlendMode.MULTIPLY);
+ cs.setGraphicsStateParameters(r0);
+ cs.setGraphicsStateParameters(r1);
+ //TODO replace with document.getDocument().createCOSStream()
+ // or call new PDFormXObject(document)
+ PDFormXObject frm1 = new PDFormXObject(new COSStream());
+ PDFormXObject frm2 = new PDFormXObject(new COSStream());
+ frm1.setResources(new PDResources());
+ try (PDFormContentStream mwfofrmCS = new PDFormContentStream(frm1))
{
- PDExtendedGraphicsState r0 = new PDExtendedGraphicsState();
- PDExtendedGraphicsState r1 = new PDExtendedGraphicsState();
- r0.setAlphaSourceFlag(false);
- r0.setStrokingAlphaConstant(annotation.getConstantOpacity());
- r0.setNonStrokingAlphaConstant(annotation.getConstantOpacity());
- r1.setAlphaSourceFlag(false);
- r1.setBlendMode(BlendMode.MULTIPLY);
- cs.setGraphicsStateParameters(r0);
- cs.setGraphicsStateParameters(r1);
- //TODO replace with document.getDocument().createCOSStream()
- // or call new PDFormXObject(document)
- PDFormXObject frm1 = new PDFormXObject(new COSStream());
- PDFormXObject frm2 = new PDFormXObject(new COSStream());
- frm1.setResources(new PDResources());
- try (PDFormContentStream mwfofrmCS = new PDFormContentStream(frm1))
- {
- mwfofrmCS.drawForm(frm2);
- }
- frm1.setBBox(annotation.getRectangle());
- COSDictionary groupDict = new COSDictionary();
- groupDict.setItem(COSName.S, COSName.TRANSPARENCY);
- //TODO PDFormXObject.setGroup() is missing
- frm1.getCOSObject().setItem(COSName.GROUP, groupDict);
- cs.drawForm(frm1);
- frm2.setBBox(annotation.getRectangle());
- try (PDFormContentStream frm2CS = new PDFormContentStream(frm2))
+ mwfofrmCS.drawForm(frm2);
+ }
+ frm1.setBBox(annotation.getRectangle());
+ COSDictionary groupDict = new COSDictionary();
+ groupDict.setItem(COSName.S, COSName.TRANSPARENCY);
+ //TODO PDFormXObject.setGroup() is missing
+ frm1.getCOSObject().setItem(COSName.GROUP, groupDict);
+ cs.drawForm(frm1);
+ frm2.setBBox(annotation.getRectangle());
+ try (PDFormContentStream frm2CS = new PDFormContentStream(frm2))
+ {
+ frm2CS.setNonStrokingColor(color);
+ int of = 0;
+ while (of + 7 < pathsArray.length)
{
- frm2CS.setNonStrokingColor(color);
- int of = 0;
- while (of + 7 < pathsArray.length)
- {
- // quadpoints spec sequence is incorrect, correct one is (4,5 0,1 2,3 6,7)
- // https://stackoverflow.com/questions/9855814/pdf-spec-vs-acrobat-creation-quadpoints
-
- // for "curvy" highlighting, two Bézier control points are used that seem to have a
- // distance of about 1/4 of the height.
- // note that curves won't appear if outside of the rectangle
- float delta = 0;
- if (Float.compare(pathsArray[of + 0], pathsArray[of + 4]) == 0 &&
- Float.compare(pathsArray[of + 1], pathsArray[of + 3]) == 0 &&
- Float.compare(pathsArray[of + 2], pathsArray[of + 6]) == 0 &&
- Float.compare(pathsArray[of + 5], pathsArray[of + 7]) == 0)
- {
- // horizontal highlight
- delta = (pathsArray[of + 1] - pathsArray[of + 5]) / 4;
- }
- else if (Float.compare(pathsArray[of + 1], pathsArray[of + 5]) == 0 &&
- Float.compare(pathsArray[of + 0], pathsArray[of + 2]) == 0 &&
- Float.compare(pathsArray[of + 3], pathsArray[of + 7]) == 0 &&
- Float.compare(pathsArray[of + 4], pathsArray[of + 6]) == 0)
- {
- // vertical highlight
- delta = (pathsArray[of + 0] - pathsArray[of + 4]) / 4;
- }
+ // quadpoints spec sequence is incorrect, correct one is (4,5 0,1 2,3 6,7)
+ // https://stackoverflow.com/questions/9855814/pdf-spec-vs-acrobat-creation-quadpoints
- frm2CS.moveTo(pathsArray[of + 4], pathsArray[of + 5]);
+ // for "curvy" highlighting, two Bézier control points are used that seem to have a
+ // distance of about 1/4 of the height.
+ // note that curves won't appear if outside of the rectangle
+ float delta = 0;
+ if (Float.compare(pathsArray[of + 0], pathsArray[of + 4]) == 0 &&
+ Float.compare(pathsArray[of + 1], pathsArray[of + 3]) == 0 &&
+ Float.compare(pathsArray[of + 2], pathsArray[of + 6]) == 0 &&
+ Float.compare(pathsArray[of + 5], pathsArray[of + 7]) == 0)
+ {
+ // horizontal highlight
+ delta = (pathsArray[of + 1] - pathsArray[of + 5]) / 4;
+ }
+ else if (Float.compare(pathsArray[of + 1], pathsArray[of + 5]) == 0 &&
+ Float.compare(pathsArray[of + 0], pathsArray[of + 2]) == 0 &&
+ Float.compare(pathsArray[of + 3], pathsArray[of + 7]) == 0 &&
+ Float.compare(pathsArray[of + 4], pathsArray[of + 6]) == 0)
+ {
+ // vertical highlight
+ delta = (pathsArray[of + 0] - pathsArray[of + 4]) / 4;
+ }
- if (Float.compare(pathsArray[of + 0], pathsArray[of + 4]) == 0)
- {
- // horizontal highlight
- frm2CS.curveTo(pathsArray[of + 4] - delta, pathsArray[of + 5] + delta,
- pathsArray[of + 0] - delta, pathsArray[of + 1] - delta,
- pathsArray[of + 0], pathsArray[of + 1]);
- }
- else if (Float.compare(pathsArray[of + 5], pathsArray[of + 1]) == 0)
- {
- // vertical highlight
- frm2CS.curveTo(pathsArray[of + 4] + delta, pathsArray[of + 5] + delta,
- pathsArray[of + 0] - delta, pathsArray[of + 1] + delta,
- pathsArray[of + 0], pathsArray[of + 1]);
- }
- else
- {
- frm2CS.lineTo(pathsArray[of + 0], pathsArray[of + 1]);
- }
- frm2CS.lineTo(pathsArray[of + 2], pathsArray[of + 3]);
- if (Float.compare(pathsArray[of + 2], pathsArray[of + 6]) == 0)
- {
- // horizontal highlight
- frm2CS.curveTo(pathsArray[of + 2] + delta, pathsArray[of + 3] - delta,
- pathsArray[of + 6] + delta, pathsArray[of + 7] + delta,
- pathsArray[of + 6], pathsArray[of + 7]);
- }
- else if (Float.compare(pathsArray[of + 3], pathsArray[of + 7]) == 0)
- {
- // vertical highlight
- frm2CS.curveTo(pathsArray[of + 2] - delta, pathsArray[of + 3] - delta,
- pathsArray[of + 6] + delta, pathsArray[of + 7] - delta,
- pathsArray[of + 6], pathsArray[of + 7]);
- }
- else
- {
- frm2CS.lineTo(pathsArray[of + 6], pathsArray[of + 7]);
- }
+ frm2CS.moveTo(pathsArray[of + 4], pathsArray[of + 5]);
- frm2CS.fill();
- of += 8;
+ if (Float.compare(pathsArray[of + 0], pathsArray[of + 4]) == 0)
+ {
+ // horizontal highlight
+ frm2CS.curveTo(pathsArray[of + 4] - delta, pathsArray[of + 5] + delta,
+ pathsArray[of + 0] - delta, pathsArray[of + 1] - delta,
+ pathsArray[of + 0], pathsArray[of + 1]);
}
+ else if (Float.compare(pathsArray[of + 5], pathsArray[of + 1]) == 0)
+ {
+ // vertical highlight
+ frm2CS.curveTo(pathsArray[of + 4] + delta, pathsArray[of + 5] + delta,
+ pathsArray[of + 0] - delta, pathsArray[of + 1] + delta,
+ pathsArray[of + 0], pathsArray[of + 1]);
+ }
+ else
+ {
+ frm2CS.lineTo(pathsArray[of + 0], pathsArray[of + 1]);
+ }
+ frm2CS.lineTo(pathsArray[of + 2], pathsArray[of + 3]);
+ if (Float.compare(pathsArray[of + 2], pathsArray[of + 6]) == 0)
+ {
+ // horizontal highlight
+ frm2CS.curveTo(pathsArray[of + 2] + delta, pathsArray[of + 3] - delta,
+ pathsArray[of + 6] + delta, pathsArray[of + 7] + delta,
+ pathsArray[of + 6], pathsArray[of + 7]);
+ }
+ else if (Float.compare(pathsArray[of + 3], pathsArray[of + 7]) == 0)
+ {
+ // vertical highlight
+ frm2CS.curveTo(pathsArray[of + 2] - delta, pathsArray[of + 3] - delta,
+ pathsArray[of + 6] + delta, pathsArray[of + 7] - delta,
+ pathsArray[of + 6], pathsArray[of + 7]);
+ }
+ else
+ {
+ frm2CS.lineTo(pathsArray[of + 6], pathsArray[of + 7]);
+ }
+
+ frm2CS.fill();
+ of += 8;
}
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -57,41 +57,38 @@ public class PDInkAppearanceHandler exte
return;
}
- try
+ try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
{
- try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
+ setOpacity(cs, ink.getConstantOpacity());
+
+ cs.setStrokingColor(color);
+ if (ab.dashArray != null)
{
- setOpacity(cs, ink.getConstantOpacity());
+ cs.setLineDashPattern(ab.dashArray, 0);
+ }
+ cs.setLineWidth(ab.width);
- cs.setStrokingColor(color);
- if (ab.dashArray != null)
- {
- cs.setLineDashPattern(ab.dashArray, 0);
- }
- cs.setLineWidth(ab.width);
+ for (float[] pathArray : ink.getInkList())
+ {
+ int nPoints = pathArray.length / 2;
- for (float[] pathArray : ink.getInkList())
+ // "When drawn, the points shall be connected by straight lines or curves
+ // in an implementation-dependent way" - we do lines.
+ for (int i = 0; i < nPoints; ++i)
{
- int nPoints = pathArray.length / 2;
+ float x = pathArray[i * 2];
+ float y = pathArray[i * 2 + 1];
- // "When drawn, the points shall be connected by straight lines or curves
- // in an implementation-dependent way" - we do lines.
- for (int i = 0; i < nPoints; ++i)
+ if (i == 0)
{
- float x = pathArray[i * 2];
- float y = pathArray[i * 2 + 1];
-
- if (i == 0)
- {
- cs.moveTo(x, y);
- }
- else
- {
- cs.lineTo(x, y);
- }
+ cs.moveTo(x, y);
+ }
+ else
+ {
+ cs.lineTo(x, y);
}
- cs.stroke();
}
+ cs.stroke();
}
}
catch (IOException ex)
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -103,159 +103,156 @@ public class PDLineAppearanceHandler ext
annotation.setRectangle(rect);
- try
+ try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
{
- try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
+ setOpacity(cs, annotation.getConstantOpacity());
+
+ // Tested with Adobe Reader:
+ // text is written first (TODO)
+ // width 0 is used by Adobe as such (but results in a visible line in rendering)
+ // empty color array results in an invisible line ("n" operator) but the rest is visible
+ // empty content is like no caption
+
+ boolean hasStroke = cs.setStrokingColorOnDemand(color);
+
+ if (ab.dashArray != null)
{
- setOpacity(cs, annotation.getConstantOpacity());
+ cs.setLineDashPattern(ab.dashArray, 0);
+ }
+ cs.setLineWidth(ab.width);
- // Tested with Adobe Reader:
- // text is written first (TODO)
- // width 0 is used by Adobe as such (but results in a visible line in rendering)
- // empty color array results in an invisible line ("n" operator) but the rest is visible
- // empty content is like no caption
-
- boolean hasStroke = cs.setStrokingColorOnDemand(color);
-
- if (ab.dashArray != null)
- {
- cs.setLineDashPattern(ab.dashArray, 0);
- }
- cs.setLineWidth(ab.width);
-
- float x1 = pathsArray[0];
- float y1 = pathsArray[1];
- float x2 = pathsArray[2];
- float y2 = pathsArray[3];
-
- // if there are leader lines, then the /L coordinates represent
- // the endpoints of the leader lines rather than the endpoints of the line itself.
- // so for us, llo + ll is the vertical offset for the line.
- float y = llo + ll;
-
- String contents = annotation.getContents();
- if (contents == null)
- {
- contents = "";
- }
-
- double angle = Math.atan2(y2 - y1, x2 - x1);
- cs.transform(Matrix.getRotateInstance(angle, x1, y1));
- float lineLength = (float) Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
- if (annotation.hasCaption() && !contents.isEmpty())
- {
- PDType1Font font = PDType1Font.HELVETICA;
- // TODO: support newlines!!!!!
- // see https://www.pdfill.com/example/pdf_commenting_new.pdf
- float contentLength = 0;
- try
- {
- contentLength = font.getStringWidth(annotation.getContents()) / 1000 * FONT_SIZE;
-
- //TODO How to decide the size of the font?
- // 9 seems to be standard, but if the text doesn't fit, a scaling is done
- // see AnnotationSample.Standard.pdf, diagonal line
- }
- catch (IllegalArgumentException ex)
- {
- // Adobe Reader displays placeholders instead
- LOG.error("line text '" + annotation.getContents() + "' can't be shown", ex);
- }
- float xOffset = (lineLength - contentLength) / 2;
- float yOffset;
-
- // Leader lines
- cs.moveTo(0, llo);
- cs.lineTo(0, llo + ll + lle);
- cs.moveTo(lineLength, llo);
- cs.lineTo(lineLength, llo + ll + lle);
-
- String captionPositioning = annotation.getCaptionPositioning();
-
- // draw the line horizontally, using the rotation CTM to get to correct final position
- // that's the easiest way to calculate the positions for the line before and after inline caption
- if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
- {
- cs.moveTo(ab.width, y);
- }
- else
- {
- cs.moveTo(0, y);
- }
- if ("Top".equals(captionPositioning))
- {
- // this arbitrary number is from Adobe
- yOffset = 1.908f;
- }
- else
- {
- // Inline
- // this arbitrary number is from Adobe
- yOffset = -2.6f;
-
- cs.lineTo(xOffset - ab.width, y);
- cs.moveTo(lineLength - xOffset + ab.width, y);
- }
- if (SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
- {
- cs.lineTo(lineLength - ab.width, y);
- }
- else
- {
- cs.lineTo(lineLength, y);
- }
- cs.drawShape(ab.width, hasStroke, false);
+ float x1 = pathsArray[0];
+ float y1 = pathsArray[1];
+ float x2 = pathsArray[2];
+ float y2 = pathsArray[3];
+
+ // if there are leader lines, then the /L coordinates represent
+ // the endpoints of the leader lines rather than the endpoints of the line itself.
+ // so for us, llo + ll is the vertical offset for the line.
+ float y = llo + ll;
+
+ String contents = annotation.getContents();
+ if (contents == null)
+ {
+ contents = "";
+ }
+
+ double angle = Math.atan2(y2 - y1, x2 - x1);
+ cs.transform(Matrix.getRotateInstance(angle, x1, y1));
+ float lineLength = (float) Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
+ if (annotation.hasCaption() && !contents.isEmpty())
+ {
+ PDType1Font font = PDType1Font.HELVETICA;
+ // TODO: support newlines!!!!!
+ // see https://www.pdfill.com/example/pdf_commenting_new.pdf
+ float contentLength = 0;
+ try
+ {
+ contentLength = font.getStringWidth(annotation.getContents()) / 1000 * FONT_SIZE;
+
+ //TODO How to decide the size of the font?
+ // 9 seems to be standard, but if the text doesn't fit, a scaling is done
+ // see AnnotationSample.Standard.pdf, diagonal line
+ }
+ catch (IllegalArgumentException ex)
+ {
+ // Adobe Reader displays placeholders instead
+ LOG.error("line text '" + annotation.getContents() + "' can't be shown", ex);
+ }
+ float xOffset = (lineLength - contentLength) / 2;
+ float yOffset;
- // /CO entry (caption offset)
- float captionHorizontalOffset = annotation.getCaptionHorizontalOffset();
- float captionVerticalOffset = annotation.getCaptionVerticalOffset();
-
- // check contentLength so we don't show if there was trouble before
- if (contentLength > 0)
- {
- cs.beginText();
- cs.setFont(font, FONT_SIZE);
- cs.newLineAtOffset(xOffset + captionHorizontalOffset,
- y + yOffset + captionVerticalOffset);
- cs.showText(annotation.getContents());
- cs.endText();
- }
-
- if (Float.compare(captionVerticalOffset, 0) != 0)
- {
- // Adobe paints vertical bar to the caption
- cs.moveTo(0 + lineLength / 2, y);
- cs.lineTo(0 + lineLength / 2, y + captionVerticalOffset);
- cs.drawShape(ab.width, hasStroke, false);
- }
+ // Leader lines
+ cs.moveTo(0, llo);
+ cs.lineTo(0, llo + ll + lle);
+ cs.moveTo(lineLength, llo);
+ cs.lineTo(lineLength, llo + ll + lle);
+
+ String captionPositioning = annotation.getCaptionPositioning();
+
+ // draw the line horizontally, using the rotation CTM to get to correct final position
+ // that's the easiest way to calculate the positions for the line before and after inline caption
+ if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
+ {
+ cs.moveTo(ab.width, y);
}
else
{
- if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
- {
- cs.moveTo(ab.width, y);
- }
- else
- {
- cs.moveTo(0, y);
- }
- if (SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
- {
- cs.lineTo(lineLength - ab.width, y);
- }
- else
- {
- cs.lineTo(lineLength, y);
- }
- cs.drawShape(ab.width, hasStroke, false);
+ cs.moveTo(0, y);
+ }
+ if ("Top".equals(captionPositioning))
+ {
+ // this arbitrary number is from Adobe
+ yOffset = 1.908f;
+ }
+ else
+ {
+ // Inline
+ // this arbitrary number is from Adobe
+ yOffset = -2.6f;
+
+ cs.lineTo(xOffset - ab.width, y);
+ cs.moveTo(lineLength - xOffset + ab.width, y);
+ }
+ if (SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
+ {
+ cs.lineTo(lineLength - ab.width, y);
+ }
+ else
+ {
+ cs.lineTo(lineLength, y);
+ }
+ cs.drawShape(ab.width, hasStroke, false);
+
+ // /CO entry (caption offset)
+ float captionHorizontalOffset = annotation.getCaptionHorizontalOffset();
+ float captionVerticalOffset = annotation.getCaptionVerticalOffset();
+
+ // check contentLength so we don't show if there was trouble before
+ if (contentLength > 0)
+ {
+ cs.beginText();
+ cs.setFont(font, FONT_SIZE);
+ cs.newLineAtOffset(xOffset + captionHorizontalOffset,
+ y + yOffset + captionVerticalOffset);
+ cs.showText(annotation.getContents());
+ cs.endText();
}
- // paint the styles here and not before showing the text, or the text would appear
- // with the interior color
- boolean hasBackground = cs.setNonStrokingColorOnDemand(annotation.getInteriorColor());
- drawStyle(annotation.getStartPointEndingStyle(), cs, 0, y, ab.width, hasStroke, hasBackground);
- drawStyle(annotation.getEndPointEndingStyle(), cs, lineLength, y, ab.width, hasStroke, hasBackground);
+ if (Float.compare(captionVerticalOffset, 0) != 0)
+ {
+ // Adobe paints vertical bar to the caption
+ cs.moveTo(0 + lineLength / 2, y);
+ cs.lineTo(0 + lineLength / 2, y + captionVerticalOffset);
+ cs.drawShape(ab.width, hasStroke, false);
+ }
+ }
+ else
+ {
+ if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
+ {
+ cs.moveTo(ab.width, y);
+ }
+ else
+ {
+ cs.moveTo(0, y);
+ }
+ if (SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
+ {
+ cs.lineTo(lineLength - ab.width, y);
+ }
+ else
+ {
+ cs.lineTo(lineLength, y);
+ }
+ cs.drawShape(ab.width, hasStroke, false);
}
+
+ // paint the styles here and not before showing the text, or the text would appear
+ // with the interior color
+ boolean hasBackground = cs.setNonStrokingColorOnDemand(annotation.getInteriorColor());
+ drawStyle(annotation.getStartPointEndingStyle(), cs, 0, y, ab.width, hasStroke, hasBackground);
+ drawStyle(annotation.getEndPointEndingStyle(), cs, lineLength, y, ab.width, hasStroke, hasBackground);
}
catch (IOException ex)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -65,95 +65,92 @@ public class PDLinkAppearanceHandler ext
// Adobe doesn't generate an appearance for a link annotation
float lineWidth = getLineWidth();
- try
+ try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
{
- try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
+ PDColor color = annotation.getColor();
+ if (color == null)
{
- PDColor color = annotation.getColor();
- if (color == null)
- {
- // spec is unclear, but black is what Adobe does
- color = new PDColor(new float[] { 0 }, PDDeviceGray.INSTANCE);
- }
- boolean hasStroke = contentStream.setStrokingColorOnDemand(color);
+ // spec is unclear, but black is what Adobe does
+ color = new PDColor(new float[] { 0 }, PDDeviceGray.INSTANCE);
+ }
+ boolean hasStroke = contentStream.setStrokingColorOnDemand(color);
- contentStream.setBorderLine(lineWidth, annotation.getBorderStyle());
- //TODO find better way to do this. Either pass border array to
- // setBorderLine(), or use AnnotationBorder class
- if (annotation.getBorderStyle() == null)
+ contentStream.setBorderLine(lineWidth, annotation.getBorderStyle());
+ //TODO find better way to do this. Either pass border array to
+ // setBorderLine(), or use AnnotationBorder class
+ if (annotation.getBorderStyle() == null)
+ {
+ COSArray border = annotation.getBorder();
+ if (border.size() > 3 && border.getObject(3) instanceof COSArray)
{
- COSArray border = annotation.getBorder();
- if (border.size() > 3 && border.getObject(3) instanceof COSArray)
- {
- contentStream.setLineDashPattern(((COSArray) border.getObject(3)).toFloatArray(), 0);
- }
+ contentStream.setLineDashPattern(((COSArray) border.getObject(3)).toFloatArray(), 0);
}
+ }
+
+ // the differences rectangle
+ // TODO: this only works for border effect solid. Cloudy needs a different approach.
+ setRectDifference(lineWidth);
- // the differences rectangle
- // TODO: this only works for border effect solid. Cloudy needs a different approach.
- setRectDifference(lineWidth);
-
- // Acrobat applies a padding to each side of the bbox so the line is completely within
- // the bbox.
- PDRectangle borderEdge = getPaddedRectangle(getRectangle(),lineWidth/2);
+ // Acrobat applies a padding to each side of the bbox so the line is completely within
+ // the bbox.
+ PDRectangle borderEdge = getPaddedRectangle(getRectangle(),lineWidth/2);
- float[] pathsArray = annotation.getQuadPoints();
+ float[] pathsArray = annotation.getQuadPoints();
- if (pathsArray != null)
+ if (pathsArray != null)
+ {
+ // QuadPoints shall be ignored if any coordinate in the array lies outside
+ // the region specified by Rect.
+ PDRectangle rect = annotation.getRectangle();
+ for (int i = 0; i < pathsArray.length / 2; ++i)
{
- // QuadPoints shall be ignored if any coordinate in the array lies outside
- // the region specified by Rect.
- PDRectangle rect = annotation.getRectangle();
- for (int i = 0; i < pathsArray.length / 2; ++i)
+ if (!rect.contains(pathsArray[i * 2], pathsArray[i * 2 + 1]))
{
- if (!rect.contains(pathsArray[i * 2], pathsArray[i * 2 + 1]))
- {
- LOG.warn("At least one /QuadPoints entry (" +
- pathsArray[i * 2] + ";" + pathsArray[i * 2 + 1] +
- ") is outside of rectangle, " + rect +
- ", /QuadPoints are ignored and /Rect is used instead");
- pathsArray = null;
- break;
- }
+ LOG.warn("At least one /QuadPoints entry (" +
+ pathsArray[i * 2] + ";" + pathsArray[i * 2 + 1] +
+ ") is outside of rectangle, " + rect +
+ ", /QuadPoints are ignored and /Rect is used instead");
+ pathsArray = null;
+ break;
}
}
+ }
- if (pathsArray == null)
+ if (pathsArray == null)
+ {
+ // Convert rectangle coordinates as if it was a /QuadPoints entry
+ pathsArray = new float[8];
+ pathsArray[0] = borderEdge.getLowerLeftX();
+ pathsArray[1] = borderEdge.getLowerLeftY();
+ pathsArray[2] = borderEdge.getUpperRightX();
+ pathsArray[3] = borderEdge.getLowerLeftY();
+ pathsArray[4] = borderEdge.getUpperRightX();
+ pathsArray[5] = borderEdge.getUpperRightY();
+ pathsArray[6] = borderEdge.getLowerLeftX();
+ pathsArray[7] = borderEdge.getUpperRightY();
+ }
+
+ int of = 0;
+ while (of + 7 < pathsArray.length)
+ {
+ if (annotation.getBorderStyle() != null &&
+ annotation.getBorderStyle().getStyle().equals(PDBorderStyleDictionary.STYLE_UNDERLINE))
{
- // Convert rectangle coordinates as if it was a /QuadPoints entry
- pathsArray = new float[8];
- pathsArray[0] = borderEdge.getLowerLeftX();
- pathsArray[1] = borderEdge.getLowerLeftY();
- pathsArray[2] = borderEdge.getUpperRightX();
- pathsArray[3] = borderEdge.getLowerLeftY();
- pathsArray[4] = borderEdge.getUpperRightX();
- pathsArray[5] = borderEdge.getUpperRightY();
- pathsArray[6] = borderEdge.getLowerLeftX();
- pathsArray[7] = borderEdge.getUpperRightY();
+ contentStream.moveTo(pathsArray[of], pathsArray[of + 1]);
+ contentStream.lineTo(pathsArray[of + 2], pathsArray[of + 3]);
}
-
- int of = 0;
- while (of + 7 < pathsArray.length)
+ else
{
- if (annotation.getBorderStyle() != null &&
- annotation.getBorderStyle().getStyle().equals(PDBorderStyleDictionary.STYLE_UNDERLINE))
- {
- contentStream.moveTo(pathsArray[of], pathsArray[of + 1]);
- contentStream.lineTo(pathsArray[of + 2], pathsArray[of + 3]);
- }
- else
- {
- contentStream.moveTo(pathsArray[of], pathsArray[of + 1]);
- contentStream.lineTo(pathsArray[of + 2], pathsArray[of + 3]);
- contentStream.lineTo(pathsArray[of + 4], pathsArray[of + 5]);
- contentStream.lineTo(pathsArray[of + 6], pathsArray[of + 7]);
- contentStream.closePath();
- }
- of += 8;
+ contentStream.moveTo(pathsArray[of], pathsArray[of + 1]);
+ contentStream.lineTo(pathsArray[of + 2], pathsArray[of + 3]);
+ contentStream.lineTo(pathsArray[of + 4], pathsArray[of + 5]);
+ contentStream.lineTo(pathsArray[of + 6], pathsArray[of + 7]);
+ contentStream.closePath();
}
-
- contentStream.drawShape(lineWidth, hasStroke, false);
+ of += 8;
}
+
+ contentStream.drawShape(lineWidth, hasStroke, false);
}
catch (IOException e)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -91,74 +91,71 @@ public class PDPolygonAppearanceHandler
rect.setUpperRightY(Math.max(maxY + lineWidth, rect.getUpperRightY()));
annotation.setRectangle(rect);
- try
+ try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
{
- try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
+ boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());
+
+ boolean hasBackground = contentStream
+ .setNonStrokingColorOnDemand(annotation.getInteriorColor());
+
+ setOpacity(contentStream, annotation.getConstantOpacity());
+
+ contentStream.setBorderLine(lineWidth, annotation.getBorderStyle());
+ //TODO find better way to do this. Either pass border array to
+ // setBorderLine(), or use AnnotationBorder class
+ if (annotation.getBorderStyle() == null)
{
- boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());
+ COSArray border = annotation.getBorder();
+ if (border.size() > 3 && border.getObject(3) instanceof COSArray)
+ {
+ contentStream.setLineDashPattern(((COSArray) border.getObject(3)).toFloatArray(), 0);
+ }
+ }
- boolean hasBackground = contentStream
- .setNonStrokingColorOnDemand(annotation.getInteriorColor());
+ PDBorderEffectDictionary borderEffect = annotation.getBorderEffect();
+ if (borderEffect != null && borderEffect.getStyle().equals(PDBorderEffectDictionary.STYLE_CLOUDY))
+ {
+ CloudyBorder cloudyBorder = new CloudyBorder(contentStream,
+ borderEffect.getIntensity(), lineWidth, getRectangle());
+ cloudyBorder.createCloudyPolygon(pathArray);
+ annotation.setRectangle(cloudyBorder.getRectangle());
+ PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
+ appearanceStream.setBBox(cloudyBorder.getBBox());
+ appearanceStream.setMatrix(cloudyBorder.getMatrix());
+ }
+ else
+ {
+ // the differences rectangle
+ setRectDifference(lineWidth);
- setOpacity(contentStream, annotation.getConstantOpacity());
+ // Acrobat applies a padding to each side of the bbox so the line is
+ // completely within the bbox.
- contentStream.setBorderLine(lineWidth, annotation.getBorderStyle());
- //TODO find better way to do this. Either pass border array to
- // setBorderLine(), or use AnnotationBorder class
- if (annotation.getBorderStyle() == null)
+ for (int i = 0; i < pathArray.length; i++)
{
- COSArray border = annotation.getBorder();
- if (border.size() > 3 && border.getObject(3) instanceof COSArray)
+ float[] pointsArray = pathArray[i];
+ // first array shall be of size 2 and specify the moveto operator
+ if (i == 0 && pointsArray.length == 2)
{
- contentStream.setLineDashPattern(((COSArray) border.getObject(3)).toFloatArray(), 0);
+ contentStream.moveTo(pointsArray[0], pointsArray[1]);
}
- }
-
- PDBorderEffectDictionary borderEffect = annotation.getBorderEffect();
- if (borderEffect != null && borderEffect.getStyle().equals(PDBorderEffectDictionary.STYLE_CLOUDY))
- {
- CloudyBorder cloudyBorder = new CloudyBorder(contentStream,
- borderEffect.getIntensity(), lineWidth, getRectangle());
- cloudyBorder.createCloudyPolygon(pathArray);
- annotation.setRectangle(cloudyBorder.getRectangle());
- PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
- appearanceStream.setBBox(cloudyBorder.getBBox());
- appearanceStream.setMatrix(cloudyBorder.getMatrix());
- }
- else
- {
- // the differences rectangle
- setRectDifference(lineWidth);
-
- // Acrobat applies a padding to each side of the bbox so the line is
- // completely within the bbox.
-
- for (int i = 0; i < pathArray.length; i++)
+ else
{
- float[] pointsArray = pathArray[i];
- // first array shall be of size 2 and specify the moveto operator
- if (i == 0 && pointsArray.length == 2)
+ // entries of length 2 shall be treated as lineto operator
+ if (pointsArray.length == 2)
{
- contentStream.moveTo(pointsArray[0], pointsArray[1]);
+ contentStream.lineTo(pointsArray[0], pointsArray[1]);
}
- else
+ else if (pointsArray.length == 6)
{
- // entries of length 2 shall be treated as lineto operator
- if (pointsArray.length == 2)
- {
- contentStream.lineTo(pointsArray[0], pointsArray[1]);
- }
- else if (pointsArray.length == 6)
- {
- contentStream.curveTo(pointsArray[0], pointsArray[1],
- pointsArray[2], pointsArray[3],
- pointsArray[4], pointsArray[5]);
- }
+ contentStream.curveTo(pointsArray[0], pointsArray[1],
+ pointsArray[2], pointsArray[3],
+ pointsArray[4], pointsArray[5]);
}
}
}
- contentStream.drawShape(lineWidth, hasStroke, hasBackground);
}
+ contentStream.drawShape(lineWidth, hasStroke, hasBackground);
}
catch (IOException e)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -93,94 +93,91 @@ public class PDPolylineAppearanceHandler
rect.setUpperRightY(Math.max(maxY + ab.width * 10, rect.getUpperRightY()));
annotation.setRectangle(rect);
- try
+ try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
{
- try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
- {
- boolean hasBackground = cs.setNonStrokingColorOnDemand(annotation.getInteriorColor());
- setOpacity(cs, annotation.getConstantOpacity());
- boolean hasStroke = cs.setStrokingColorOnDemand(color);
+ boolean hasBackground = cs.setNonStrokingColorOnDemand(annotation.getInteriorColor());
+ setOpacity(cs, annotation.getConstantOpacity());
+ boolean hasStroke = cs.setStrokingColorOnDemand(color);
- if (ab.dashArray != null)
- {
- cs.setLineDashPattern(ab.dashArray, 0);
- }
- cs.setLineWidth(ab.width);
+ if (ab.dashArray != null)
+ {
+ cs.setLineDashPattern(ab.dashArray, 0);
+ }
+ cs.setLineWidth(ab.width);
- for (int i = 0; i < pathsArray.length / 2; ++i)
+ for (int i = 0; i < pathsArray.length / 2; ++i)
+ {
+ float x = pathsArray[i * 2];
+ float y = pathsArray[i * 2 + 1];
+ if (i == 0)
{
- float x = pathsArray[i * 2];
- float y = pathsArray[i * 2 + 1];
- if (i == 0)
+ if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
{
- if (SHORT_STYLES.contains(annotation.getStartPointEndingStyle()))
+ // modify coordinate to shorten the segment
+ // https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
+ float x1 = pathsArray[2];
+ float y1 = pathsArray[3];
+ float len = (float) (Math.sqrt(Math.pow(x - x1, 2) + Math.pow(y - y1, 2)));
+ if (Float.compare(len, 0) != 0)
{
- // modify coordinate to shorten the segment
- // https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
- float x1 = pathsArray[2];
- float y1 = pathsArray[3];
- float len = (float) (Math.sqrt(Math.pow(x - x1, 2) + Math.pow(y - y1, 2)));
- if (Float.compare(len, 0) != 0)
- {
- x += (x1 - x) / len * ab.width;
- y += (y1 - y) / len * ab.width;
- }
+ x += (x1 - x) / len * ab.width;
+ y += (y1 - y) / len * ab.width;
}
- cs.moveTo(x, y);
}
- else
+ cs.moveTo(x, y);
+ }
+ else
+ {
+ if (i == pathsArray.length / 2 - 1 &&
+ SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
{
- if (i == pathsArray.length / 2 - 1 &&
- SHORT_STYLES.contains(annotation.getEndPointEndingStyle()))
+ // modify coordinate to shorten the segment
+ // https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
+ float x0 = pathsArray[pathsArray.length - 4];
+ float y0 = pathsArray[pathsArray.length - 3];
+ float len = (float) (Math.sqrt(Math.pow(x0 - x, 2) + Math.pow(y0 - y, 2)));
+ if (Float.compare(len, 0) != 0)
{
- // modify coordinate to shorten the segment
- // https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
- float x0 = pathsArray[pathsArray.length - 4];
- float y0 = pathsArray[pathsArray.length - 3];
- float len = (float) (Math.sqrt(Math.pow(x0 - x, 2) + Math.pow(y0 - y, 2)));
- if (Float.compare(len, 0) != 0)
- {
- x -= (x - x0) / len * ab.width;
- y -= (y - y0) / len * ab.width;
- }
+ x -= (x - x0) / len * ab.width;
+ y -= (y - y0) / len * ab.width;
}
- cs.lineTo(x, y);
}
+ cs.lineTo(x, y);
}
- cs.stroke();
+ }
+ cs.stroke();
- // do a transform so that first and last "arms" are imagined flat, like in line handler
- // the alternative would be to apply the transform to the LE shapes directly,
- // which would be more work and produce code difficult to understand
+ // do a transform so that first and last "arms" are imagined flat, like in line handler
+ // the alternative would be to apply the transform to the LE shapes directly,
+ // which would be more work and produce code difficult to understand
- // paint the styles here and after polyline draw, to avoid line crossing a filled shape
- if (!LE_NONE.equals(annotation.getStartPointEndingStyle()))
- {
- // check only needed to avoid q cm Q if LE_NONE
- float x2 = pathsArray[2];
- float y2 = pathsArray[3];
- float x1 = pathsArray[0];
- float y1 = pathsArray[1];
- cs.saveGraphicsState();
- double angle = Math.atan2(y2 - y1, x2 - x1);
- cs.transform(Matrix.getRotateInstance(angle, x1, y1));
- drawStyle(annotation.getStartPointEndingStyle(), cs, 0, 0, ab.width, hasStroke, hasBackground);
- cs.restoreGraphicsState();
- }
+ // paint the styles here and after polyline draw, to avoid line crossing a filled shape
+ if (!LE_NONE.equals(annotation.getStartPointEndingStyle()))
+ {
+ // check only needed to avoid q cm Q if LE_NONE
+ float x2 = pathsArray[2];
+ float y2 = pathsArray[3];
+ float x1 = pathsArray[0];
+ float y1 = pathsArray[1];
+ cs.saveGraphicsState();
+ double angle = Math.atan2(y2 - y1, x2 - x1);
+ cs.transform(Matrix.getRotateInstance(angle, x1, y1));
+ drawStyle(annotation.getStartPointEndingStyle(), cs, 0, 0, ab.width, hasStroke, hasBackground);
+ cs.restoreGraphicsState();
+ }
- if (!LE_NONE.equals(annotation.getEndPointEndingStyle()))
- {
- // check only needed to avoid q cm Q if LE_NONE
- float x1 = pathsArray[pathsArray.length - 4];
- float y1 = pathsArray[pathsArray.length - 3];
- float x2 = pathsArray[pathsArray.length - 2];
- float y2 = pathsArray[pathsArray.length - 1];
- // save / restore not needed because it's the last one
- double angle = Math.atan2(y2 - y1, x2 - x1);
- cs.transform(Matrix.getRotateInstance(angle, x1, y1));
- float lineLength = (float) Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
- drawStyle(annotation.getEndPointEndingStyle(), cs, lineLength, 0, ab.width, hasStroke, hasBackground);
- }
+ if (!LE_NONE.equals(annotation.getEndPointEndingStyle()))
+ {
+ // check only needed to avoid q cm Q if LE_NONE
+ float x1 = pathsArray[pathsArray.length - 4];
+ float y1 = pathsArray[pathsArray.length - 3];
+ float x2 = pathsArray[pathsArray.length - 2];
+ float y2 = pathsArray[pathsArray.length - 1];
+ // save / restore not needed because it's the last one
+ double angle = Math.atan2(y2 - y1, x2 - x1);
+ cs.transform(Matrix.getRotateInstance(angle, x1, y1));
+ float lineLength = (float) Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
+ drawStyle(annotation.getEndPointEndingStyle(), cs, lineLength, 0, ab.width, hasStroke, hasBackground);
}
}
catch (IOException ex)
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -58,71 +58,68 @@ public class PDSquareAppearanceHandler e
public void generateNormalAppearance()
{
float lineWidth = getLineWidth();
- try
+ PDAnnotationSquare annotation = (PDAnnotationSquare) getAnnotation();
+ try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
{
- PDAnnotationSquare annotation = (PDAnnotationSquare) getAnnotation();
- try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
+ boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());
+ boolean hasBackground = contentStream
+ .setNonStrokingColorOnDemand(annotation.getInteriorColor());
+
+ setOpacity(contentStream, annotation.getConstantOpacity());
+
+ contentStream.setBorderLine(lineWidth, annotation.getBorderStyle());
+ PDBorderEffectDictionary borderEffect = annotation.getBorderEffect();
+
+ if (borderEffect != null && borderEffect.getStyle().equals(PDBorderEffectDictionary.STYLE_CLOUDY))
+ {
+ CloudyBorder cloudyBorder = new CloudyBorder(contentStream,
+ borderEffect.getIntensity(), lineWidth, getRectangle());
+ cloudyBorder.createCloudyRectangle(annotation.getRectDifference());
+ annotation.setRectangle(cloudyBorder.getRectangle());
+ annotation.setRectDifference(cloudyBorder.getRectDifference());
+ PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
+ appearanceStream.setBBox(cloudyBorder.getBBox());
+ appearanceStream.setMatrix(cloudyBorder.getMatrix());
+ }
+ else
{
- boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());
- boolean hasBackground = contentStream
- .setNonStrokingColorOnDemand(annotation.getInteriorColor());
-
- setOpacity(contentStream, annotation.getConstantOpacity());
-
- contentStream.setBorderLine(lineWidth, annotation.getBorderStyle());
- PDBorderEffectDictionary borderEffect = annotation.getBorderEffect();
-
- if (borderEffect != null && borderEffect.getStyle().equals(PDBorderEffectDictionary.STYLE_CLOUDY))
+ // handle the border box
+ //
+ // There are two options. The handling is not part of the PDF specification but
+ // implementation specific to Adobe Reader
+ // - if /RD is set the border box is the /Rect entry inset by the respective
+ // border difference.
+ // - if /RD is not set the border box is defined by the /Rect entry. The /RD entry will
+ // be set to be the line width and the /Rect is enlarged by the /RD amount
+
+ PDRectangle borderBox = null;
+ float[] rectDifferences = annotation.getRectDifferences();
+
+ if (rectDifferences.length == 0)
{
- CloudyBorder cloudyBorder = new CloudyBorder(contentStream,
- borderEffect.getIntensity(), lineWidth, getRectangle());
- cloudyBorder.createCloudyRectangle(annotation.getRectDifference());
- annotation.setRectangle(cloudyBorder.getRectangle());
- annotation.setRectDifference(cloudyBorder.getRectDifference());
- PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
- appearanceStream.setBBox(cloudyBorder.getBBox());
- appearanceStream.setMatrix(cloudyBorder.getMatrix());
+ borderBox = getPaddedRectangle(getRectangle(), lineWidth/2);
+ // the differences rectangle
+ annotation.setRectDifferences(lineWidth/2);
+ annotation.setRectangle(addRectDifferences(getRectangle(), annotation.getRectDifferences()));
+
+ // when the normal appearance stream was generated BBox and Matrix have been set to the
+ // values of the original /Rect. As the /Rect was changed that needs to be adjusted too.
+ annotation.getNormalAppearanceStream().setBBox(getRectangle());
+ AffineTransform transform = AffineTransform.getTranslateInstance(-getRectangle().getLowerLeftX(),
+ -getRectangle().getLowerLeftY());
+ annotation.getNormalAppearanceStream().setMatrix(transform);
}
else
{
- // handle the border box
- //
- // There are two options. The handling is not part of the PDF specification but
- // implementation specific to Adobe Reader
- // - if /RD is set the border box is the /Rect entry inset by the respective
- // border difference.
- // - if /RD is not set the border box is defined by the /Rect entry. The /RD entry will
- // be set to be the line width and the /Rect is enlarged by the /RD amount
-
- PDRectangle borderBox = null;
- float[] rectDifferences = annotation.getRectDifferences();
-
- if (rectDifferences.length == 0)
- {
- borderBox = getPaddedRectangle(getRectangle(), lineWidth/2);
- // the differences rectangle
- annotation.setRectDifferences(lineWidth/2);
- annotation.setRectangle(addRectDifferences(getRectangle(), annotation.getRectDifferences()));
-
- // when the normal appearance stream was generated BBox and Matrix have been set to the
- // values of the original /Rect. As the /Rect was changed that needs to be adjusted too.
- annotation.getNormalAppearanceStream().setBBox(getRectangle());
- AffineTransform transform = AffineTransform.getTranslateInstance(-getRectangle().getLowerLeftX(),
- -getRectangle().getLowerLeftY());
- annotation.getNormalAppearanceStream().setMatrix(transform);
- }
- else
- {
- borderBox = applyRectDifferences(getRectangle(), rectDifferences);
- borderBox = getPaddedRectangle(borderBox, lineWidth/2);
- }
-
- contentStream.addRect(borderBox.getLowerLeftX(), borderBox.getLowerLeftY(),
- borderBox.getWidth(), borderBox.getHeight());
+ borderBox = applyRectDifferences(getRectangle(), rectDifferences);
+ borderBox = getPaddedRectangle(borderBox, lineWidth/2);
}
- contentStream.drawShape(lineWidth, hasStroke, hasBackground);
+ contentStream.addRect(borderBox.getLowerLeftX(), borderBox.getLowerLeftY(),
+ borderBox.getWidth(), borderBox.getHeight());
}
+
+ contentStream.drawShape(lineWidth, hasStroke, hasBackground);
}
catch (IOException e)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -89,53 +89,50 @@ public class PDStrikeoutAppearanceHandle
rect.setUpperRightY(Math.max(maxY + ab.width, rect.getUpperRightY()));
annotation.setRectangle(rect);
- try
+ try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
{
- try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
+ setOpacity(cs, annotation.getConstantOpacity());
+
+ cs.setStrokingColor(color);
+ if (ab.dashArray != null)
{
- setOpacity(cs, annotation.getConstantOpacity());
+ cs.setLineDashPattern(ab.dashArray, 0);
+ }
+ cs.setLineWidth(ab.width);
- cs.setStrokingColor(color);
- if (ab.dashArray != null)
+ // spec is incorrect
+ // https://stackoverflow.com/questions/9855814/pdf-spec-vs-acrobat-creation-quadpoints
+ for (int i = 0; i < pathsArray.length / 8; ++i)
+ {
+ // get mid point between bounds, substract the line width to approximate what Adobe is doing
+ // See e.g. CTAN-example-Annotations.pdf and PLPDF.com-MarkupAnnotations.pdf
+ // and https://bugs.ghostscript.com/show_bug.cgi?id=693664
+ // do the math for diagonal annotations with this weird old trick:
+ // https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
+ float len0 = (float) (Math.sqrt(Math.pow(pathsArray[i * 8] - pathsArray[i * 8 + 4], 2) +
+ Math.pow(pathsArray[i * 8 + 1] - pathsArray[i * 8 + 5], 2)));
+ float x0 = pathsArray[i * 8 + 4];
+ float y0 = pathsArray[i * 8 + 5];
+ if (Float.compare(len0, 0) != 0)
{
- cs.setLineDashPattern(ab.dashArray, 0);
+ // only if both coordinates are not identical to avoid divide by zero
+ x0 += (pathsArray[i * 8] - pathsArray[i * 8 + 4]) / len0 * (len0 / 2 - ab.width);
+ y0 += (pathsArray[i * 8 + 1] - pathsArray[i * 8 + 5]) / len0 * (len0 / 2 - ab.width);
}
- cs.setLineWidth(ab.width);
-
- // spec is incorrect
- // https://stackoverflow.com/questions/9855814/pdf-spec-vs-acrobat-creation-quadpoints
- for (int i = 0; i < pathsArray.length / 8; ++i)
+ float len1 = (float) (Math.sqrt(Math.pow(pathsArray[i * 8 + 2] - pathsArray[i * 8 + 6], 2) +
+ Math.pow(pathsArray[i * 8 + 3] - pathsArray[i * 8 + 7], 2)));
+ float x1 = pathsArray[i * 8 + 6];
+ float y1 = pathsArray[i * 8 + 7];
+ if (Float.compare(len1, 0) != 0)
{
- // get mid point between bounds, substract the line width to approximate what Adobe is doing
- // See e.g. CTAN-example-Annotations.pdf and PLPDF.com-MarkupAnnotations.pdf
- // and https://bugs.ghostscript.com/show_bug.cgi?id=693664
- // do the math for diagonal annotations with this weird old trick:
- // https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
- float len0 = (float) (Math.sqrt(Math.pow(pathsArray[i * 8] - pathsArray[i * 8 + 4], 2) +
- Math.pow(pathsArray[i * 8 + 1] - pathsArray[i * 8 + 5], 2)));
- float x0 = pathsArray[i * 8 + 4];
- float y0 = pathsArray[i * 8 + 5];
- if (Float.compare(len0, 0) != 0)
- {
- // only if both coordinates are not identical to avoid divide by zero
- x0 += (pathsArray[i * 8] - pathsArray[i * 8 + 4]) / len0 * (len0 / 2 - ab.width);
- y0 += (pathsArray[i * 8 + 1] - pathsArray[i * 8 + 5]) / len0 * (len0 / 2 - ab.width);
- }
- float len1 = (float) (Math.sqrt(Math.pow(pathsArray[i * 8 + 2] - pathsArray[i * 8 + 6], 2) +
- Math.pow(pathsArray[i * 8 + 3] - pathsArray[i * 8 + 7], 2)));
- float x1 = pathsArray[i * 8 + 6];
- float y1 = pathsArray[i * 8 + 7];
- if (Float.compare(len1, 0) != 0)
- {
- // only if both coordinates are not identical to avoid divide by zero
- x1 += (pathsArray[i * 8 + 2] - pathsArray[i * 8 + 6]) / len1 * (len1 / 2 - ab.width);
- y1 += (pathsArray[i * 8 + 3] - pathsArray[i * 8 + 7]) / len1 * (len1 / 2 - ab.width);
- }
- cs.moveTo(x0, y0);
- cs.lineTo(x1, y1);
+ // only if both coordinates are not identical to avoid divide by zero
+ x1 += (pathsArray[i * 8 + 2] - pathsArray[i * 8 + 6]) / len1 * (len1 / 2 - ab.width);
+ y1 += (pathsArray[i * 8 + 3] - pathsArray[i * 8 + 7]) / len1 * (len1 / 2 - ab.width);
}
- cs.stroke();
+ cs.moveTo(x0, y0);
+ cs.lineTo(x1, y1);
}
+ cs.stroke();
}
catch (IOException ex)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java?rev=1832257&r1=1832256&r2=1832257&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java Fri May 25 17:33:32 2018
@@ -90,29 +90,26 @@ public class PDUnderlineAppearanceHandle
rect.setUpperRightY(Math.max(maxY + ab.width, rect.getUpperRightY()));
annotation.setRectangle(rect);
- try
+ try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
{
- try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
- {
- setOpacity(cs, annotation.getConstantOpacity());
+ setOpacity(cs, annotation.getConstantOpacity());
- cs.setStrokingColor(color);
- if (ab.dashArray != null)
- {
- cs.setLineDashPattern(ab.dashArray, 0);
- }
- cs.setLineWidth(ab.width);
+ cs.setStrokingColor(color);
+ if (ab.dashArray != null)
+ {
+ cs.setLineDashPattern(ab.dashArray, 0);
+ }
+ cs.setLineWidth(ab.width);
- // spec is incorrect
- // https://stackoverflow.com/questions/9855814/pdf-spec-vs-acrobat-creation-quadpoints
- for (int i = 0; i < pathsArray.length / 8; ++i)
- {
- // only lower coords are used
- cs.moveTo(pathsArray[i * 8 + 4], pathsArray[i * 8 + 5]);
- cs.lineTo(pathsArray[i * 8 + 6], pathsArray[i * 8 + 7]);
- }
- cs.stroke();
+ // spec is incorrect
+ // https://stackoverflow.com/questions/9855814/pdf-spec-vs-acrobat-creation-quadpoints
+ for (int i = 0; i < pathsArray.length / 8; ++i)
+ {
+ // only lower coords are used
+ cs.moveTo(pathsArray[i * 8 + 4], pathsArray[i * 8 + 5]);
+ cs.lineTo(pathsArray[i * 8 + 6], pathsArray[i * 8 + 7]);
}
+ cs.stroke();
}
catch (IOException ex)
{