Author: tilman
Date: Mon Aug 18 03:40:32 2025
New Revision: 1927848

Log:
PDFBOX-5660: simplify code, as suggested by Valery Bokov; closes #216

Modified:
   pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java   
Mon Aug 18 03:40:28 2025        (r1927847)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java   
Mon Aug 18 03:40:32 2025        (r1927848)
@@ -504,9 +504,10 @@ public class Overlay implements Closeabl
                 // Note that this segment is only the second best solution to 
the problem. The best
                 // would be to make appropriate transforms in 
calculateAffineTransform()                
                 PDPage page = inputPDFDocument.getPage(pageNumber - 1);
-                if (page.getRotation() != 0)
+                int rotation = page.getRotation();
+                if (rotation != 0)
                 {
-                    return createAdjustedLayoutPage(page);
+                    return createAdjustedLayoutPage(rotation);
                 }
             }
         }
@@ -518,16 +519,16 @@ public class Overlay implements Closeabl
         return layoutPage;
     }
 
-    private LayoutPage createAdjustedLayoutPage(PDPage page) throws IOException
+    private LayoutPage createAdjustedLayoutPage(int rotation) throws 
IOException
     {
-        LayoutPage rotatedLayoutPage = 
rotatedDefaultOverlayPagesMap.get(page.getRotation());
+        LayoutPage rotatedLayoutPage = 
rotatedDefaultOverlayPagesMap.get(rotation);
         if (rotatedLayoutPage == null)
         {
             // createLayoutPage must be called because we can't reuse the 
COSStream
             rotatedLayoutPage = 
createLayoutPage(defaultOverlayDocument.getPage(0));
-            int newRotation = (rotatedLayoutPage.overlayRotation - 
page.getRotation() + 360) % 360;
+            int newRotation = (rotatedLayoutPage.overlayRotation - rotation + 
360) % 360;
             rotatedLayoutPage.overlayRotation = newRotation;
-            rotatedDefaultOverlayPagesMap.put(page.getRotation(), 
rotatedLayoutPage);
+            rotatedDefaultOverlayPagesMap.put(rotation, rotatedLayoutPage);
         }
         return rotatedLayoutPage;
     }

Reply via email to