Author: tilman
Date: Fri Oct 10 11:58:58 2025
New Revision: 1929049

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

Modified:
   
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java

Modified: 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java
==============================================================================
--- 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java
 Fri Oct 10 11:58:54 2025        (r1929048)
+++ 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java
 Fri Oct 10 11:58:58 2025        (r1929049)
@@ -124,6 +124,8 @@ public class PDFreeTextAppearanceHandler
             }
             cs.setLineWidth(ab.width);
 
+            String lineEndingStyle = annotation.getLineEndingStyle();
+
             // draw callout line(s)
             // must be done before retangle paint to avoid a line cutting 
through cloud
             // see CTAN-example-Annotations.pdf
@@ -133,7 +135,7 @@ public class PDFreeTextAppearanceHandler
                 float y = pathsArray[i * 2 + 1];
                 if (i == 0)
                 {
-                    if (SHORT_STYLES.contains(annotation.getLineEndingStyle()))
+                    if (SHORT_STYLES.contains(lineEndingStyle))
                     {
                         // modify coordinate to shorten the segment
                         // 
https://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance
@@ -161,7 +163,7 @@ public class PDFreeTextAppearanceHandler
             // paint the styles here and after line(s) draw, to avoid line 
crossing a filled shape       
             if 
(PDAnnotationMarkup.IT_FREE_TEXT_CALLOUT.equals(annotation.getIntent())
                     // check only needed to avoid q cm Q if LE_NONE
-                    && !LE_NONE.equals(annotation.getLineEndingStyle())
+                    && !LE_NONE.equals(lineEndingStyle)
                     && pathsArray.length >= 4)
             {
                 float x2 = pathsArray[2];
@@ -169,7 +171,7 @@ public class PDFreeTextAppearanceHandler
                 float x1 = pathsArray[0];
                 float y1 = pathsArray[1];
                 cs.saveGraphicsState();
-                if (ANGLED_STYLES.contains(annotation.getLineEndingStyle()))
+                if (ANGLED_STYLES.contains(lineEndingStyle))
                 {
                     // do a transform so that first "arm" is imagined flat,
                     // like in line handler.
@@ -183,7 +185,7 @@ public class PDFreeTextAppearanceHandler
                 {
                     cs.transform(Matrix.getTranslateInstance(x1, y1));
                 }
-                drawStyle(annotation.getLineEndingStyle(), cs, 0, 0, ab.width, 
hasStroke, hasBackground, false);
+                drawStyle(lineEndingStyle, cs, 0, 0, ab.width, hasStroke, 
hasBackground, false);
                 cs.restoreGraphicsState();
             }
 
@@ -291,7 +293,8 @@ public class PDFreeTextAppearanceHandler
             cs.addRect(xOffset, clipY, clipWidth, clipHeight);
             cs.clip();
 
-            if (annotation.getContents() != null)
+            String annotationContents = annotation.getContents();
+            if (annotationContents != null)
             {
                 cs.beginText();
                 cs.setFont(font, fontSize);
@@ -301,7 +304,7 @@ public class PDFreeTextAppearanceHandler
                 appearanceStyle.setFontSize(fontSize);
                 PlainTextFormatter formatter = new 
PlainTextFormatter.Builder(cs)
                         .style(appearanceStyle)
-                        .text(new PlainText(annotation.getContents()))
+                        .text(new PlainText(annotationContents))
                         .width(width - ab.width * 4)
                         .wrapLines(true)
                         .initialOffset(xOffset, yOffset)

Reply via email to