Author: tilman
Date: Sun Sep 28 15:54:39 2025
New Revision: 1928817

Log:
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #268

Modified:
   
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java

Modified: 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java
    Sun Sep 28 14:08:29 2025        (r1928816)
+++ 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java
    Sun Sep 28 15:54:39 2025        (r1928817)
@@ -58,7 +58,9 @@ public class PDCaretAppearanceHandler ex
             setOpacity(contentStream, annotation.getConstantOpacity());
 
             PDRectangle rect = getRectangle();
-            PDRectangle bbox = new PDRectangle(rect.getWidth(), 
rect.getHeight());
+            float rectWidth = rect.getWidth();
+            float rectHeight = rect.getHeight();
+            PDRectangle bbox = new PDRectangle(rectWidth, rectHeight);
             PDAppearanceStream pdAppearanceStream = 
annotation.getNormalAppearanceStream();
             if (!annotation.getCOSObject().containsKey(COSName.RD))
             {
@@ -68,26 +70,26 @@ public class PDCaretAppearanceHandler ex
                 // translation values in the matrix and also used for the line 
width
                 // (not here because it has no effect, see comment near fill() 
).
                 // The curves are based on the original rectangle.
-                float rd = Math.min(rect.getHeight() / 10, 5);
+                float rd = Math.min(rectHeight / 10, 5);
                 annotation.setRectDifferences(rd);
-                bbox = new PDRectangle(-rd, -rd, rect.getWidth() + 2 * rd, 
rect.getHeight() + 2 * rd);
+                bbox = new PDRectangle(-rd, -rd, rectWidth + 2 * rd, 
rectHeight + 2 * rd);
                 Matrix matrix = pdAppearanceStream.getMatrix();
                 pdAppearanceStream.setMatrix(matrix.createAffineTransform());
                 PDRectangle rect2 = new PDRectangle(rect.getLowerLeftX() - rd, 
rect.getLowerLeftY() - rd,
-                                                    rect.getWidth() + 2 * rd, 
rect.getHeight() + 2 * rd);
+                                                rectWidth + 2 * rd, rectHeight 
+ 2 * rd);
                 annotation.setRectangle(rect2);
             }
             pdAppearanceStream.setBBox(bbox);
 
-            float halfX = rect.getWidth() / 2;
-            float halfY = rect.getHeight() / 2;
+            float halfX = rectWidth / 2;
+            float halfY = rectHeight / 2;
             contentStream.moveTo(0, 0);
             contentStream.curveTo(halfX, 0,
                                   halfX, halfY, 
-                                  halfX, rect.getHeight());
+                                  halfX, rectHeight);
             contentStream.curveTo(halfX, halfY, 
                                   halfX, 0,
-                                  rect.getWidth(), 0);
+                                  rectWidth, 0);
             contentStream.closePath();
             contentStream.fill();
             // Adobe has an additional stroke, but it has no effect
@@ -110,4 +112,4 @@ public class PDCaretAppearanceHandler ex
     {
         // TODO to be implemented
     }
-}
\ No newline at end of file
+}

Reply via email to