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 2021/07/31 09:52:15 UTC
svn commit: r1891913 - in
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers:
PDAbstractAppearanceHandler.java PDLinkAppearanceHandler.java
Author: tilman
Date: Sat Jul 31 09:52:15 2021
New Revision: 1891913
URL: http://svn.apache.org/viewvc?rev=1891913&view=rev
Log:
PDFBOX-4892: optimize, as suggested by valerybokov
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java?rev=1891913&r1=1891912&r2=1891913&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java Sat Jul 31 09:52:15 2021
@@ -312,19 +312,18 @@ public abstract class PDAbstractAppearan
}
else if (PDAnnotationLine.LE_R_OPEN_ARROW.equals(style) || PDAnnotationLine.LE_R_CLOSED_ARROW.equals(style))
{
- drawArrow(cs, x + (0 - sign) * width, y, (0 - sign) * width * 9);
+ drawArrow(cs, x + (-sign) * width, y, (-sign) * width * 9);
}
else if (PDAnnotationLine.LE_SLASH.equals(style))
{
// the line is 18 x linewidth at an angle of 60°
- cs.moveTo(x + (float) (Math.cos(Math.toRadians(60)) * width * 9),
- y + (float) (Math.sin(Math.toRadians(60)) * width * 9));
- cs.lineTo(x + (float) (Math.cos(Math.toRadians(240)) * width * 9),
- y + (float) (Math.sin(Math.toRadians(240)) * width * 9));
+ float width9 = width * 9;
+ cs.moveTo(x + (float) (Math.cos(Math.toRadians(60)) * width9),
+ y + (float) (Math.sin(Math.toRadians(60)) * width9));
+ cs.lineTo(x + (float) (Math.cos(Math.toRadians(240)) * width9),
+ y + (float) (Math.sin(Math.toRadians(240)) * width9));
}
-
-
if (PDAnnotationLine.LE_R_CLOSED_ARROW.equals(style) ||
PDAnnotationLine.LE_CLOSED_ARROW.equals(style))
{
@@ -352,9 +351,11 @@ public abstract class PDAbstractAppearan
// cos(angle) = x position
// sin(angle) = y position
// this comes very close to what Adobe is doing
- cs.moveTo(x + (float) (Math.cos(ARROW_ANGLE) * len), y + (float) (Math.sin(ARROW_ANGLE) * len));
+ float armX = x + (float) (Math.cos(ARROW_ANGLE) * len);
+ float armYdelta = (float) (Math.sin(ARROW_ANGLE) * len);
+ cs.moveTo(armX, y + armYdelta);
cs.lineTo(x, y);
- cs.lineTo(x + (float) (Math.cos(ARROW_ANGLE) * len), y - (float) (Math.sin(ARROW_ANGLE) * len));
+ cs.lineTo(armX, y - armYdelta);
}
/**
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java?rev=1891913&r1=1891912&r2=1891913&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java Sat Jul 31 09:52:15 2021
@@ -64,7 +64,8 @@ public class PDLinkAppearanceHandler ext
public void generateNormalAppearance()
{
PDAnnotationLink annotation = (PDAnnotationLink) getAnnotation();
- if (annotation.getRectangle() == null)
+ PDRectangle rect = annotation.getRectangle();
+ if (rect == null)
{
// 660402-p1-AnnotationEmptyRect.pdf has /Rect entry with 0 elements
return;
@@ -99,7 +100,6 @@ public class PDLinkAppearanceHandler ext
{
// 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]))
@@ -128,19 +128,22 @@ public class PDLinkAppearanceHandler ext
pathsArray[7] = borderEdge.getUpperRightY();
}
- int of = 0;
- while (of + 7 < pathsArray.length)
+ boolean underline = false;
+ if (pathsArray.length >= 8)
{
- if (annotation.getBorderStyle() != null &&
- annotation.getBorderStyle().getStyle().equals(PDBorderStyleDictionary.STYLE_UNDERLINE))
+ PDBorderStyleDictionary borderStyleDic = annotation.getBorderStyle();
+ if (borderStyleDic != null)
{
- contentStream.moveTo(pathsArray[of], pathsArray[of + 1]);
- contentStream.lineTo(pathsArray[of + 2], pathsArray[of + 3]);
+ underline = PDBorderStyleDictionary.STYLE_UNDERLINE.equals(borderStyleDic.getStyle());
}
- else
+ }
+ int of = 0;
+ while (of + 7 < pathsArray.length)
+ {
+ contentStream.moveTo(pathsArray[of], pathsArray[of + 1]);
+ contentStream.lineTo(pathsArray[of + 2], pathsArray[of + 3]);
+ if (!underline)
{
- 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();