Skip to content

Commit 319839a

Browse files
committed
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #268
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1928819 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4784c9d commit 319839a

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public void generateNormalAppearance()
5858
setOpacity(contentStream, annotation.getConstantOpacity());
5959

6060
PDRectangle rect = getRectangle();
61-
PDRectangle bbox = new PDRectangle(rect.getWidth(), rect.getHeight());
61+
float rectWidth = rect.getWidth();
62+
float rectHeight = rect.getHeight();
63+
PDRectangle bbox = new PDRectangle(rectWidth, rectHeight);
6264
PDAppearanceStream pdAppearanceStream = annotation.getNormalAppearanceStream();
6365
if (!annotation.getCOSObject().containsKey(COSName.RD))
6466
{
@@ -68,26 +70,26 @@ public void generateNormalAppearance()
6870
// translation values in the matrix and also used for the line width
6971
// (not here because it has no effect, see comment near fill() ).
7072
// The curves are based on the original rectangle.
71-
float rd = Math.min(rect.getHeight() / 10, 5);
73+
float rd = Math.min(rectHeight / 10, 5);
7274
annotation.setRectDifferences(rd);
73-
bbox = new PDRectangle(-rd, -rd, rect.getWidth() + 2 * rd, rect.getHeight() + 2 * rd);
75+
bbox = new PDRectangle(-rd, -rd, rectWidth + 2 * rd, rectHeight + 2 * rd);
7476
Matrix matrix = pdAppearanceStream.getMatrix();
7577
pdAppearanceStream.setMatrix(matrix.createAffineTransform());
7678
PDRectangle rect2 = new PDRectangle(rect.getLowerLeftX() - rd, rect.getLowerLeftY() - rd,
77-
rect.getWidth() + 2 * rd, rect.getHeight() + 2 * rd);
79+
rectWidth + 2 * rd, rectHeight + 2 * rd);
7880
annotation.setRectangle(rect2);
7981
}
8082
pdAppearanceStream.setBBox(bbox);
8183

82-
float halfX = rect.getWidth() / 2;
83-
float halfY = rect.getHeight() / 2;
84+
float halfX = rectWidth / 2;
85+
float halfY = rectHeight / 2;
8486
contentStream.moveTo(0, 0);
8587
contentStream.curveTo(halfX, 0,
8688
halfX, halfY,
87-
halfX, rect.getHeight());
89+
halfX, rectHeight);
8890
contentStream.curveTo(halfX, halfY,
8991
halfX, 0,
90-
rect.getWidth(), 0);
92+
rectWidth, 0);
9193
contentStream.closePath();
9294
contentStream.fill();
9395
// Adobe has an additional stroke, but it has no effect
@@ -110,4 +112,4 @@ public void generateDownAppearance()
110112
{
111113
// TODO to be implemented
112114
}
113-
}
115+
}

0 commit comments

Comments
 (0)